/** Creates a trie from a set of elements. * * @param elements a set of elements * @param transformationStrategy a transformation strategy that must turn <code>elements</code> into a list of * distinct, lexicographically increasing (in iteration order) binary words. */ public ImmutableBinaryTrie(final Iterable<? extends T> elements, final TransformationStrategy<? super T> transformationStrategy) { this.transformationStrategy = transformationStrategy; defRetValue = -1; // Check order final Iterator<? extends T> iterator = elements.iterator(); final ObjectList<LongArrayBitVector> words = new ObjectArrayList<>(); int cmp; if (iterator.hasNext()) { final LongArrayBitVector prev = LongArrayBitVector.copy(transformationStrategy.toBitVector(iterator.next())); words.add(prev.copy()); BitVector curr; while(iterator.hasNext()) { curr = transformationStrategy.toBitVector(iterator.next()); cmp = prev.compareTo(curr); if (cmp == 0) throw new IllegalArgumentException("The trie elements are not unique"); if (cmp > 0) throw new IllegalArgumentException("The trie elements are not sorted"); prev.replace(curr); words.add(prev.copy()); } } root = buildTrie(words, 0); }
/** Creates a trie from a set of elements. * * @param elements a set of elements * @param transformationStrategy a transformation strategy that must turn <code>elements</code> into a list of * distinct, lexicographically increasing (in iteration order) binary words. */ public ImmutableBinaryTrie( final Iterable<? extends T> elements, final TransformationStrategy<? super T> transformationStrategy ) { this.transformationStrategy = transformationStrategy; defRetValue = -1; // Check order final Iterator<? extends T> iterator = elements.iterator(); final ObjectList<LongArrayBitVector> words = new ObjectArrayList<LongArrayBitVector>(); int cmp; if ( iterator.hasNext() ) { final LongArrayBitVector prev = LongArrayBitVector.copy( transformationStrategy.toBitVector( iterator.next() ) ); words.add( prev.copy() ); BitVector curr; while( iterator.hasNext() ) { curr = transformationStrategy.toBitVector( iterator.next() ); cmp = prev.compareTo( curr ); if ( cmp == 0 ) throw new IllegalArgumentException( "The trie elements are not unique" ); if ( cmp > 0 ) throw new IllegalArgumentException( "The trie elements are not sorted" ); prev.replace( curr ); words.add( prev.copy() ); } } root = buildTrie( words, 0 ); }
/** Creates a trie from a set of elements. * * @param elements a set of elements * @param transformationStrategy a transformation strategy that must turn <code>elements</code> into a list of * distinct, lexicographically increasing (in iteration order) binary words. */ public ImmutableBinaryTrie( final Iterable<? extends T> elements, final TransformationStrategy<? super T> transformationStrategy ) { this.transformationStrategy = transformationStrategy; defRetValue = -1; // Check order final Iterator<? extends T> iterator = elements.iterator(); final ObjectList<LongArrayBitVector> words = new ObjectArrayList<LongArrayBitVector>(); int cmp; if ( iterator.hasNext() ) { final LongArrayBitVector prev = LongArrayBitVector.copy( transformationStrategy.toBitVector( iterator.next() ) ); words.add( prev.copy() ); BitVector curr; while( iterator.hasNext() ) { curr = transformationStrategy.toBitVector( iterator.next() ); cmp = prev.compareTo( curr ); if ( cmp == 0 ) throw new IllegalArgumentException( "The trie elements are not unique" ); if ( cmp > 0 ) throw new IllegalArgumentException( "The trie elements are not sorted" ); prev.replace( curr ); words.add( prev.copy() ); } } root = buildTrie( words, 0 ); }
/** Creates a trie from a set of elements. * * @param elements a set of elements * @param transformationStrategy a transformation strategy that must turn <code>elements</code> into a list of * distinct, lexicographically increasing (in iteration order) binary words. */ public ImmutableBinaryTrie(final Iterable<? extends T> elements, final TransformationStrategy<? super T> transformationStrategy) { this.transformationStrategy = transformationStrategy; defRetValue = -1; // Check order final Iterator<? extends T> iterator = elements.iterator(); final ObjectList<LongArrayBitVector> words = new ObjectArrayList<>(); int cmp; if (iterator.hasNext()) { final LongArrayBitVector prev = LongArrayBitVector.copy(transformationStrategy.toBitVector(iterator.next())); words.add(prev.copy()); BitVector curr; while(iterator.hasNext()) { curr = transformationStrategy.toBitVector(iterator.next()); cmp = prev.compareTo(curr); if (cmp == 0) throw new IllegalArgumentException("The trie elements are not unique"); if (cmp > 0) throw new IllegalArgumentException("The trie elements are not sorted"); prev.replace(curr); words.add(prev.copy()); } } root = buildTrie(words, 0); }
curr.replace(transformationStrategy.toBitVector(iterator.next())); pl.lightUpdate(); prefix = (int)curr.longestCommonPrefixLength(prev); prevDelimiter.replace(shortest); prevDelimiter.replace(shortest); shortest.replace(curr); shortestIndex = count; shortest.replace(curr); shortestIndex = count; prev.replace(curr); maxLength = Math.max(maxLength, prev.length()); count++; curr.replace(transformationStrategy.toBitVector(iterator.next())); pl.lightUpdate(); if (! first) { prev.replace(curr);
curr.replace(transformationStrategy.toBitVector(iterator.next())); pl.lightUpdate(); prefix = (int)curr.longestCommonPrefixLength(prev); prevDelimiter.replace(prev); prevDelimiter.replace(prev); prev.replace(curr); maxLength = Math.max(maxLength, prev.length()); count++; curr.replace(transformationStrategy.toBitVector(iterator.next())); pl.lightUpdate(); if (! first) { prev.replace(curr);
curr.replace(transformationStrategy.toBitVector(iterator.next())); pl.lightUpdate(); prefix = (int)curr.longestCommonPrefixLength(prev); root = new Node(null, null, prev.copy()); if (DDEBUG) leaves.add(prev.copy()); prevDelimiter.replace(prev); prevDelimiter.replace(prev); prev.replace(curr); maxLength = Math.max(maxLength, prev.length()); count++; curr.replace(transformationStrategy.toBitVector(iterator.next())); pl.lightUpdate(); if (DDDEBUG) System.err.println("Analysing key " + curr + "..."); prev.replace(curr); c++;
curr.replace(transform.toBitVector(iterator.next())); if (DEBUG) System.err.println(curr); pl.lightUpdate();