/** 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); }
/** 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 ); }
private Leaf<T> predNode(final T k) { final LongArrayBitVector v = LongArrayBitVector.copy(transform.toBitVector(k)); final long[] state = Hashes.preprocessMurmur(v, 42); final Node<T> exitNode = getExitNode(v, state).exitNode; if (v.compareTo(exitNode.extent(transform)) <= 0) return exitNode.rightLeaf(); else return exitNode.leftLeaf().prev; }
private Leaf<T> succNode(final T k) { final LongArrayBitVector v = LongArrayBitVector.copy(transform.toBitVector(k)); final long[] state = Hashes.preprocessMurmur(v, 42); final Node<T> exitNode = getExitNode(v, state).exitNode; if (v.compareTo(exitNode.extent(transform)) <= 0) return exitNode.leftLeaf(); else return exitNode.rightLeaf().next; }
for(final BitVector v : rankerArray) { while(bv != null) { cmp = bv.compareTo(v); if (cmp == 0) leavesBitVector.set(q); if (cmp >= 0) break;