Changeset 1251 for trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/Trie.java
- Timestamp:
- 07/12/13 16:45:53 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/Trie.java
r1189 r1251 17 17 import java.io.Serializable; 18 18 import java.util.Collection; 19 import java.util.HashSet;20 19 import java.util.LinkedHashSet; 21 20 import java.util.LinkedList; … … 55 54 * </p> 56 55 */ 57 private Collection<T> knownSymbols;56 private SymbolMap<T, T> knownSymbols; 58 57 59 58 /** … … 88 87 this.comparator = comparator; 89 88 rootNode = new TrieNode<T>(comparator); 90 knownSymbols = new LinkedHashSet<T>();89 knownSymbols = new SymbolMap<T, T>(this.comparator); 91 90 } 92 91 … … 104 103 } 105 104 rootNode = new TrieNode<T>(other.rootNode); 106 knownSymbols = new LinkedHashSet<T>(other.knownSymbols);105 knownSymbols = new SymbolMap<T, T>(other.knownSymbols); 107 106 comparator = other.comparator; 108 107 } … … 116 115 */ 117 116 public Collection<T> getKnownSymbols() { 118 return new LinkedHashSet<T>(knownSymbols );117 return new LinkedHashSet<T>(knownSymbols.getSymbols()); 119 118 } 120 119 … … 153 152 /** 154 153 * <p> 155 * Adds a given subsequence to the trie and increases the counters accordingly. 154 * Adds a given subsequence to the trie and increases the counters accordingly. NOTE: This 155 * method does not add the symbols to the list of known symbols. This is only ensured using 156 * the method {@link #train(List, int)}. 156 157 * </p> 157 158 * … … 162 163 protected void add(List<T> subsequence) { 163 164 if (subsequence != null && !subsequence.isEmpty()) { 164 addToKnownSymbols(subsequence);165 165 subsequence = new LinkedList<T>(subsequence); // defensive copy! 166 166 T firstSymbol = subsequence.get(0); … … 495 495 */ 496 496 private void addToKnownSymbols(T symbol) { 497 for (T knownSymbol : knownSymbols) { 498 if (comparator.equals(knownSymbol, symbol)) { 499 return; 500 } 501 } 502 503 knownSymbols.add(symbol); 504 } 505 506 /** 507 * <p> 508 * adds a list of new symbols to the collection of known symbols. Uses the 509 * {@link #addToKnownSymbols(Object)} method for each element of the provided list. 510 * </p> 511 * 512 * @param symbols the list of symbols to be added to the known symbols 513 */ 514 private void addToKnownSymbols(List<T> symbols) { 515 for (T symbol : symbols) { 516 addToKnownSymbols(symbol); 497 if (!knownSymbols.containsSymbol(symbol)) { 498 knownSymbols.addSymbol(symbol, symbol); 517 499 } 518 500 } … … 653 635 */ 654 636 public void updateKnownSymbols() { 655 knownSymbols = new HashSet<T>();637 knownSymbols = new SymbolMap<T, T>(this.comparator); 656 638 for (TrieNode<T> node : rootNode.getChildren()) { 657 639 addToKnownSymbols(node.getSymbol());
Note: See TracChangeset
for help on using the changeset viewer.