Ignore:
Timestamp:
07/12/13 16:45:53 (11 years ago)
Author:
pharms
Message:
  • improved performance of the trie for large alphabets by using the symbol map. This is an improved list of symbols that allows a more efficient lookup for symbols using buckets of symbol as an initial search order
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/TrieNode.java

    r1189 r1251  
    6767     * </p> 
    6868     */ 
    69     private Collection<TrieNode<T>> children; 
    70  
     69    private SymbolMap<T, TrieNode<T>> children; 
     70     
    7171    /** 
    7272     * <p> 
     
    115115        this.symbol = null; 
    116116        count = 0; 
    117         children = new LinkedList<TrieNode<T>>(); 
     117        children = new SymbolMap<T, TrieNode<T>>(this.comparator); 
    118118    } 
    119119 
     
    140140 
    141141        count = 0; 
    142         children = new LinkedList<TrieNode<T>>(); 
     142        children = new SymbolMap<T, TrieNode<T>>(this.comparator); 
    143143    } 
    144144 
     
    157157        count = other.count; 
    158158        comparator = other.comparator; 
    159         children = new LinkedList<TrieNode<T>>(); 
    160         for (TrieNode<T> child : other.children) { 
    161             children.add(new TrieNode<T>(child)); 
     159        children = new SymbolMap<T, TrieNode<T>>(this.comparator); 
     160         
     161        for (TrieNode<T> child : other.children.getValues()) { 
     162            children.addSymbol(child.getSymbol(), new TrieNode<T>(child)); 
    162163        } 
    163164    } 
     
    224225        if (node == null) { 
    225226            node = new TrieNode<T>(symbol, comparator); 
    226             children.add(node); 
     227            children.addSymbol(symbol, node); 
    227228        } 
    228229        return node; 
     
    240241     */ 
    241242    protected TrieNode<T> getChild(T symbol) { 
    242         for (TrieNode<T> child : children) { 
    243             if (comparator.equals(child.getSymbol(), symbol)) { 
    244                 return child; 
    245             } 
    246         } 
    247         return null; 
     243        return children.getValue(symbol); 
    248244    } 
    249245 
     
    256252     */ 
    257253    protected Collection<TrieNode<T>> getChildren() { 
    258         return children; 
     254        return children.getValues(); 
    259255    } 
    260256 
     
    296292    public Collection<T> getFollowingSymbols() { 
    297293        Collection<T> followingSymbols = new LinkedList<T>(); 
    298         for (TrieNode<T> child : children) { 
     294        for (TrieNode<T> child : children.getValues()) { 
    299295            followingSymbols.add(child.getSymbol()); 
    300296        } 
     
    346342            graph.addChild(new Edge(), parent, currentVertex); 
    347343        } 
    348         for (TrieNode<T> node : children) { 
     344        for (TrieNode<T> node : children.getValues()) { 
    349345            node.getGraph(currentVertex, graph); 
    350346        } 
     
    370366        stringBuilder.append(" " + hashCode() + " [label=\"" + thisSaneId + "\"];" + 
    371367            StringTools.ENDLINE); 
    372         for (TrieNode<T> childNode : children) { 
     368        for (TrieNode<T> childNode : children.getValues()) { 
    373369            stringBuilder.append(" " + hashCode() + " -> " + childNode.hashCode() + ";" + 
    374370                StringTools.ENDLINE); 
    375371        } 
    376         for (TrieNode<T> childNode : children) { 
     372        for (TrieNode<T> childNode : children.getValues()) { 
    377373            childNode.appendDotRepresentation(stringBuilder); 
    378374        } 
     
    412408    protected void getLeafAncestors(List<TrieNode<T>> ancestors) { 
    413409        boolean isAncestor = false; 
    414         for (TrieNode<T> child : children) { 
     410        for (TrieNode<T> child : children.getValues()) { 
    415411            child.getLeafAncestors(ancestors); 
    416412            isAncestor |= child.isLeaf(); 
     
    431427    protected int getNumLeafs() { 
    432428        int numLeafs = 0; 
    433         for (TrieNode<T> child : children) { 
     429        for (TrieNode<T> child : children.getValues()) { 
    434430            if (child.isLeaf()) { 
    435431                numLeafs++; 
Note: See TracChangeset for help on using the changeset viewer.