├── .travis.yml ├── LICENSE.txt ├── README.md ├── archive └── Readme.md ├── code ├── .idea │ └── .gitignore ├── pom.xml └── src │ ├── etc │ ├── Permuterm.patch │ └── header.txt │ ├── main │ └── java │ │ └── com │ │ └── googlecode │ │ └── concurrenttrees │ │ ├── common │ │ ├── CharSequences.java │ │ ├── Iterables.java │ │ ├── KeyValuePair.java │ │ ├── LazyIterator.java │ │ ├── PrettyPrinter.java │ │ └── SetFromMap.java │ │ ├── radix │ │ ├── ConcurrentRadixTree.java │ │ ├── RadixTree.java │ │ └── node │ │ │ ├── Node.java │ │ │ ├── NodeFactory.java │ │ │ ├── NodeList.java │ │ │ ├── SimpleNodeList.java │ │ │ ├── concrete │ │ │ ├── DefaultByteArrayNodeFactory.java │ │ │ ├── DefaultCharArrayNodeFactory.java │ │ │ ├── DefaultCharSequenceNodeFactory.java │ │ │ ├── SmartArrayBasedNodeFactory.java │ │ │ ├── bytearray │ │ │ │ ├── ByteArrayCharSequence.java │ │ │ │ ├── ByteArrayNodeDefault.java │ │ │ │ ├── ByteArrayNodeLeafNullValue.java │ │ │ │ ├── ByteArrayNodeLeafVoidValue.java │ │ │ │ ├── ByteArrayNodeLeafWithValue.java │ │ │ │ ├── ByteArrayNodeNonLeafNullValue.java │ │ │ │ └── ByteArrayNodeNonLeafVoidValue.java │ │ │ ├── chararray │ │ │ │ ├── CharArrayNodeDefault.java │ │ │ │ ├── CharArrayNodeLeafNullValue.java │ │ │ │ ├── CharArrayNodeLeafVoidValue.java │ │ │ │ ├── CharArrayNodeLeafWithValue.java │ │ │ │ ├── CharArrayNodeNonLeafNullValue.java │ │ │ │ └── CharArrayNodeNonLeafVoidValue.java │ │ │ ├── charsequence │ │ │ │ ├── CharSequenceNodeDefault.java │ │ │ │ ├── CharSequenceNodeLeafNullValue.java │ │ │ │ ├── CharSequenceNodeLeafVoidValue.java │ │ │ │ ├── CharSequenceNodeLeafWithValue.java │ │ │ │ ├── CharSequenceNodeNonLeafNullValue.java │ │ │ │ └── CharSequenceNodeNonLeafVoidValue.java │ │ │ └── voidvalue │ │ │ │ └── VoidValue.java │ │ │ └── util │ │ │ ├── AtomicNodeReferenceArray.java │ │ │ ├── NodeCharacterComparator.java │ │ │ ├── NodeCharacterKey.java │ │ │ ├── NodeCharacterProvider.java │ │ │ ├── NodeUtil.java │ │ │ └── PrettyPrintable.java │ │ ├── radixinverted │ │ ├── ConcurrentInvertedRadixTree.java │ │ └── InvertedRadixTree.java │ │ ├── radixreversed │ │ ├── ConcurrentReversedRadixTree.java │ │ └── ReversedRadixTree.java │ │ ├── solver │ │ └── LCSubstringSolver.java │ │ └── suffix │ │ ├── ConcurrentSuffixTree.java │ │ └── SuffixTree.java │ └── test │ ├── java │ └── com │ │ └── googlecode │ │ └── concurrenttrees │ │ ├── common │ │ ├── CharSequencesTest.java │ │ ├── IterablesTest.java │ │ ├── LazyIteratorTest.java │ │ └── PrettyPrinterTest.java │ │ ├── examples │ │ ├── filesystem │ │ │ ├── ConcurrentRadixTreeInMemoryFileSystem.java │ │ │ ├── InMemoryFileSystem.java │ │ │ └── InMemoryFileSystemUsage.java │ │ ├── shakespeare │ │ │ ├── BuildShakespeareSinglePlaySuffixTree.java │ │ │ ├── BuildShakespeareTragediesSuffixTree.java │ │ │ ├── BuildShakespeareWordRadixTree.java │ │ │ ├── BuildShakespeareWordSuffixTree.java │ │ │ ├── FindLongestCommonSubstring.java │ │ │ └── util │ │ │ │ └── IOUtil.java │ │ └── usage │ │ │ ├── InvertedRadixTreeUsage.java │ │ │ ├── IterablesUsage.java │ │ │ ├── LCSubstringSolverUsage.java │ │ │ ├── RadixTreeUsage.java │ │ │ ├── ReversedRadixTreeUsage.java │ │ │ └── SuffixTreeUsage.java │ │ ├── radix │ │ ├── ConcurrentRadixTreeTest.java │ │ └── node │ │ │ ├── concrete │ │ │ ├── DefaultByteArrayNodeFactoryTest.java │ │ │ ├── DefaultCharArrayNodeFactoryTest.java │ │ │ ├── DefaultCharSequenceNodeFactoryTest.java │ │ │ ├── SmartArrayBasedNodeFactoryTest.java │ │ │ ├── bytearray │ │ │ │ ├── ByteArrayCharSequenceTest.java │ │ │ │ ├── ByteArrayNodeDefaultTest.java │ │ │ │ ├── ByteArrayNodeLeafNullValueTest.java │ │ │ │ ├── ByteArrayNodeLeafVoidValueTest.java │ │ │ │ ├── ByteArrayNodeLeafWithValueTest.java │ │ │ │ ├── ByteArrayNodeNonLeafNullValueTest.java │ │ │ │ ├── ByteArrayNodeNonLeafVoidValueTest.java │ │ │ │ └── functional │ │ │ │ │ ├── ByteArrayNodeFactory_InvertedRadixTreeTest.java │ │ │ │ │ ├── ByteArrayNodeFactory_RadixTreeTest.java │ │ │ │ │ ├── ByteArrayNodeFactory_ReversedRadixTreeTest.java │ │ │ │ │ └── ByteArrayNodeFactory_SuffixTreeTest.java │ │ │ ├── chararray │ │ │ │ ├── CharArrayNodeDefaultTest.java │ │ │ │ ├── CharArrayNodeLeafNullValueTest.java │ │ │ │ ├── CharArrayNodeLeafVoidValueTest.java │ │ │ │ ├── CharArrayNodeLeafWithValueTest.java │ │ │ │ ├── CharArrayNodeNonLeafNullValueTest.java │ │ │ │ └── CharArrayNodeNonLeafVoidValueTest.java │ │ │ ├── charsequence │ │ │ │ ├── CharSequenceNodeLeafNullValueTest.java │ │ │ │ ├── CharSequenceNodeLeafVoidValueTest.java │ │ │ │ ├── CharSequenceNodeLeafWithValueTest.java │ │ │ │ ├── CharSequenceNodeNonLeafNullValueTest.java │ │ │ │ ├── CharSequenceNodeNonLeafVoidValueTest.java │ │ │ │ └── DefaultCharSequenceNodeTest.java │ │ │ └── voidvalue │ │ │ │ └── VoidValueTest.java │ │ │ └── util │ │ │ └── NodeUtilTest.java │ │ ├── radixinverted │ │ └── ConcurrentInvertedRadixTreeTest.java │ │ ├── radixreversed │ │ └── ConcurrentReversedRadixTreeTest.java │ │ ├── solver │ │ └── LCSubstringSolverTest.java │ │ ├── suffix │ │ └── ConcurrentSuffixTreeTest.java │ │ └── testutil │ │ └── TestUtility.java │ └── resources │ ├── shakespeare-trees │ ├── radix-tree-words-shakespeare-collected-works.txt │ ├── suffix-tree-words-shakespeare-collected-works.txt │ └── tragedies-longest-common-substring.txt │ ├── shakespeare │ ├── comedies │ │ ├── a_midsummer_nights_dream.txt │ │ ├── alls_well_that_ends_well.txt │ │ ├── as_you_like_it.txt │ │ ├── comedy_of_errors.txt │ │ ├── cymbeline.txt │ │ ├── loves_labours_lost.txt │ │ ├── measure_for_measure.txt │ │ ├── merchant_of_venice.txt │ │ ├── merry_wives_of_windsor.txt │ │ ├── much_ado_about_nothing.txt │ │ ├── pericles_prince_of_tyre.txt │ │ ├── the_taming_of_the_shrew.txt │ │ ├── the_tempest.txt │ │ ├── the_winters_tale.txt │ │ ├── troilus_and_cressida.txt │ │ ├── twelfth_night.txt │ │ └── two_gentlemen_of_verona.txt │ ├── histories │ │ ├── king_henry_iv_part_1.txt │ │ ├── king_henry_iv_part_2.txt │ │ ├── king_henry_v.txt │ │ ├── king_henry_vi_part_1.txt │ │ ├── king_henry_vi_part_2.txt │ │ ├── king_henry_vi_part_3.txt │ │ ├── king_henry_viii.txt │ │ ├── king_john.txt │ │ ├── king_richard_ii.txt │ │ └── king_richard_iii.txt │ ├── poetry │ │ ├── a_lovers_complaint.txt │ │ ├── sonnets.txt │ │ ├── the_passionate_pilgrim.txt │ │ ├── the_rape_of_lucrece.txt │ │ └── venus_and_adonis.txt │ └── tragedies │ │ ├── antony_and_cleopatra.txt │ │ ├── coriolanus.txt │ │ ├── hamlet.txt │ │ ├── julius_caesar.txt │ │ ├── king_lear.txt │ │ ├── macbeth.txt │ │ ├── othello.txt │ │ ├── romeo_and_juliet.txt │ │ ├── timon_of_athens.txt │ │ └── titus_andronicus.txt │ └── travis-ci-validation.txt └── documentation ├── ConcurrentInvertedRadixTreeUsage.md ├── ConcurrentRadixTreeUsage.md ├── ConcurrentReversedRadixTreeUsage.md ├── ConcurrentSuffixTreeUsage.md ├── Downloads.md ├── FrequentlyAskedQuestions.md ├── InMemoryFileSystemUsage.md ├── LCSubstringSolverUsage.md ├── NodeFactoryAndMemoryUsage.md ├── ReleaseNotes.md ├── ShakespeareCollectedWorks.md ├── TreeDesign.md ├── documents ├── download-statistics.csv ├── tree-apply-patch.dia ├── tree-test-team-insert-toast.dia ├── tree-test-team-toast.dia └── tree-test-team.dia ├── images ├── concurrent-trees-downloads-june-2019.png ├── dfs-comic.png └── tree-apply-patch.png └── javadoc ├── Readme.md └── apidocs ├── allclasses-frame.html ├── allclasses-noframe.html ├── com └── googlecode │ └── concurrenttrees │ ├── common │ ├── CharSequences.html │ ├── Iterables.html │ ├── KeyValuePair.html │ ├── LazyIterator.html │ ├── PrettyPrinter.html │ ├── class-use │ │ ├── CharSequences.html │ │ ├── Iterables.html │ │ ├── KeyValuePair.html │ │ ├── LazyIterator.html │ │ └── PrettyPrinter.html │ ├── package-frame.html │ ├── package-summary.html │ ├── package-tree.html │ └── package-use.html │ ├── radix │ ├── ConcurrentRadixTree.KeyValuePairImpl.html │ ├── ConcurrentRadixTree.NodeKeyPair.html │ ├── ConcurrentRadixTree.html │ ├── RadixTree.html │ ├── class-use │ │ ├── ConcurrentRadixTree.KeyValuePairImpl.html │ │ ├── ConcurrentRadixTree.NodeKeyPair.html │ │ ├── ConcurrentRadixTree.html │ │ └── RadixTree.html │ ├── node │ │ ├── Node.html │ │ ├── NodeFactory.html │ │ ├── class-use │ │ │ ├── Node.html │ │ │ └── NodeFactory.html │ │ ├── concrete │ │ │ ├── DefaultByteArrayNodeFactory.html │ │ │ ├── DefaultCharArrayNodeFactory.html │ │ │ ├── DefaultCharSequenceNodeFactory.html │ │ │ ├── SmartArrayBasedNodeFactory.html │ │ │ ├── bytearray │ │ │ │ ├── ByteArrayCharSequence.IncompatibleCharacterException.html │ │ │ │ ├── ByteArrayCharSequence.html │ │ │ │ ├── ByteArrayNodeDefault.html │ │ │ │ ├── ByteArrayNodeLeafNullValue.html │ │ │ │ ├── ByteArrayNodeLeafVoidValue.html │ │ │ │ ├── ByteArrayNodeLeafWithValue.html │ │ │ │ ├── ByteArrayNodeNonLeafNullValue.html │ │ │ │ ├── ByteArrayNodeNonLeafVoidValue.html │ │ │ │ ├── class-use │ │ │ │ │ ├── ByteArrayCharSequence.IncompatibleCharacterException.html │ │ │ │ │ ├── ByteArrayCharSequence.html │ │ │ │ │ ├── ByteArrayNodeDefault.html │ │ │ │ │ ├── ByteArrayNodeLeafNullValue.html │ │ │ │ │ ├── ByteArrayNodeLeafVoidValue.html │ │ │ │ │ ├── ByteArrayNodeLeafWithValue.html │ │ │ │ │ ├── ByteArrayNodeNonLeafNullValue.html │ │ │ │ │ └── ByteArrayNodeNonLeafVoidValue.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ ├── package-tree.html │ │ │ │ └── package-use.html │ │ │ ├── chararray │ │ │ │ ├── CharArrayNodeDefault.html │ │ │ │ ├── CharArrayNodeLeafNullValue.html │ │ │ │ ├── CharArrayNodeLeafVoidValue.html │ │ │ │ ├── CharArrayNodeLeafWithValue.html │ │ │ │ ├── CharArrayNodeNonLeafNullValue.html │ │ │ │ ├── CharArrayNodeNonLeafVoidValue.html │ │ │ │ ├── class-use │ │ │ │ │ ├── CharArrayNodeDefault.html │ │ │ │ │ ├── CharArrayNodeLeafNullValue.html │ │ │ │ │ ├── CharArrayNodeLeafVoidValue.html │ │ │ │ │ ├── CharArrayNodeLeafWithValue.html │ │ │ │ │ ├── CharArrayNodeNonLeafNullValue.html │ │ │ │ │ └── CharArrayNodeNonLeafVoidValue.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ ├── package-tree.html │ │ │ │ └── package-use.html │ │ │ ├── charsequence │ │ │ │ ├── CharSequenceNodeDefault.html │ │ │ │ ├── CharSequenceNodeLeafNullValue.html │ │ │ │ ├── CharSequenceNodeLeafVoidValue.html │ │ │ │ ├── CharSequenceNodeLeafWithValue.html │ │ │ │ ├── CharSequenceNodeNonLeafNullValue.html │ │ │ │ ├── CharSequenceNodeNonLeafVoidValue.html │ │ │ │ ├── class-use │ │ │ │ │ ├── CharSequenceNodeDefault.html │ │ │ │ │ ├── CharSequenceNodeLeafNullValue.html │ │ │ │ │ ├── CharSequenceNodeLeafVoidValue.html │ │ │ │ │ ├── CharSequenceNodeLeafWithValue.html │ │ │ │ │ ├── CharSequenceNodeNonLeafNullValue.html │ │ │ │ │ └── CharSequenceNodeNonLeafVoidValue.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ ├── package-tree.html │ │ │ │ └── package-use.html │ │ │ ├── class-use │ │ │ │ ├── DefaultByteArrayNodeFactory.html │ │ │ │ ├── DefaultCharArrayNodeFactory.html │ │ │ │ ├── DefaultCharSequenceNodeFactory.html │ │ │ │ └── SmartArrayBasedNodeFactory.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ ├── package-use.html │ │ │ └── voidvalue │ │ │ │ ├── VoidValue.html │ │ │ │ ├── class-use │ │ │ │ └── VoidValue.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ ├── package-tree.html │ │ │ │ └── package-use.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ ├── package-use.html │ │ └── util │ │ │ ├── AtomicReferenceArrayListAdapter.html │ │ │ ├── NodeCharacterComparator.html │ │ │ ├── NodeCharacterKey.html │ │ │ ├── NodeCharacterProvider.html │ │ │ ├── NodeUtil.html │ │ │ ├── PrettyPrintable.html │ │ │ ├── class-use │ │ │ ├── AtomicReferenceArrayListAdapter.html │ │ │ ├── NodeCharacterComparator.html │ │ │ ├── NodeCharacterKey.html │ │ │ ├── NodeCharacterProvider.html │ │ │ ├── NodeUtil.html │ │ │ └── PrettyPrintable.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ └── package-use.html │ ├── package-frame.html │ ├── package-summary.html │ ├── package-tree.html │ └── package-use.html │ ├── radixinverted │ ├── ConcurrentInvertedRadixTree.html │ ├── InvertedRadixTree.html │ ├── class-use │ │ ├── ConcurrentInvertedRadixTree.html │ │ └── InvertedRadixTree.html │ ├── package-frame.html │ ├── package-summary.html │ ├── package-tree.html │ └── package-use.html │ ├── radixreversed │ ├── ConcurrentReversedRadixTree.html │ ├── ReversedRadixTree.html │ ├── class-use │ │ ├── ConcurrentReversedRadixTree.html │ │ └── ReversedRadixTree.html │ ├── package-frame.html │ ├── package-summary.html │ ├── package-tree.html │ └── package-use.html │ ├── solver │ ├── LCSubstringSolver.html │ ├── class-use │ │ └── LCSubstringSolver.html │ ├── package-frame.html │ ├── package-summary.html │ ├── package-tree.html │ └── package-use.html │ └── suffix │ ├── ConcurrentSuffixTree.html │ ├── SuffixTree.html │ ├── class-use │ ├── ConcurrentSuffixTree.html │ └── SuffixTree.html │ ├── package-frame.html │ ├── package-summary.html │ ├── package-tree.html │ └── package-use.html ├── constant-values.html ├── deprecated-list.html ├── help-doc.html ├── index-all.html ├── index.html ├── overview-frame.html ├── overview-summary.html ├── overview-tree.html ├── package-list ├── script.js ├── serialized-form.html └── stylesheet.css /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | dist: trusty 4 | 5 | jdk: 6 | - openjdk8 7 | 8 | install: /bin/true 9 | 10 | branches: 11 | only: 12 | - master 13 | 14 | script: 15 | - cd code 16 | - mvn install -DskipTests=true -Dmaven.javadoc.skip=true --batch-mode --show-version 17 | - mvn test verify --batch-mode 18 | -------------------------------------------------------------------------------- /archive/Readme.md: -------------------------------------------------------------------------------- 1 | The googlecode-tags directory in [this revision](https://github.com/npgall/concurrent-trees/tree/5eb1c0e8d4de4f107d5263b1799e15deb6261157/archive/googlecode-tags) contains complete copies of Concurrent-Trees source code for each of the Concurrent-Trees releases which were made while Concurrent-Trees was hosted in Subversion on Google Code: versions <=2.4.0, released prior to September 2015. 2 | 3 | Concurrent-Trees versions >2.4.0 (since September 2015), will be released from GitHub, and tags for those versions can be found directly in the GitHub repository. 4 | 5 | This project was previously hosted at: https://code.google.com/p/concurrent-trees/ 6 | -------------------------------------------------------------------------------- /code/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /code/src/etc/header.txt: -------------------------------------------------------------------------------- 1 | Copyright 2012-2013 Niall Gallagher 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/common/KeyValuePair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.common; 17 | 18 | /** 19 | * Encapsulates a key and a value. 20 | * 21 | * @param The type of the value 22 | * @author Niall Gallagher 23 | */ 24 | public interface KeyValuePair { 25 | 26 | /** 27 | * Returns the key with which the value is associated 28 | * @return The key with which the value is associated 29 | */ 30 | CharSequence getKey(); 31 | 32 | /** 33 | * Returns the value associated with the key 34 | * @return The value associated with the key 35 | */ 36 | O getValue(); 37 | 38 | /** 39 | * Compares this {@link KeyValuePair} object with another for equality. 40 | *

41 | * This is implemented based on equality of the keys. 42 | * 43 | * @param o The other object to compare 44 | * @return True if the other object is also a {@link KeyValuePair} and is equal to this one as specified above 45 | */ 46 | @Override 47 | boolean equals(Object o); 48 | 49 | /** 50 | * Returns a hash code for this object. 51 | */ 52 | @Override 53 | int hashCode(); 54 | 55 | /** 56 | * Returns a string representation as {@code (key, value)}. 57 | * @return A string representation as {@code (key, value)} 58 | */ 59 | @Override 60 | String toString(); 61 | } -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/common/LazyIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * Copyright 2007 The Guava Authors 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.googlecode.concurrenttrees.common; 18 | 19 | import java.util.Iterator; 20 | import java.util.NoSuchElementException; 21 | 22 | /** 23 | * An unmodifiable iterator which computes the next element to return only when it is requested. 24 | *

25 | * This class is inspired by com.google.common.collect.AbstractIterator in Google Guava, 26 | * which was written by the Google Guava Authors, in particular by Kevin Bourrillion. 27 | * 28 | * @author Niall Gallagher 29 | */ 30 | public abstract class LazyIterator implements Iterator { 31 | 32 | T next = null; 33 | 34 | enum State { READY, NOT_READY, DONE, FAILED } 35 | 36 | State state = State.NOT_READY; 37 | 38 | @Override 39 | public void remove() { 40 | throw new UnsupportedOperationException("Iterator.remove() is not supported"); 41 | } 42 | 43 | @Override 44 | public final boolean hasNext() { 45 | if (state == State.FAILED) { 46 | throw new IllegalStateException("This iterator is in an inconsistent state, and can no longer be used, " + 47 | "due to an exception previously thrown by the computeNext() method"); 48 | } 49 | switch (state) { 50 | case DONE: 51 | return false; 52 | case READY: 53 | return true; 54 | } 55 | return tryToComputeNext(); 56 | } 57 | 58 | boolean tryToComputeNext() { 59 | state = State.FAILED; // temporary pessimism 60 | next = computeNext(); 61 | if (state != State.DONE) { 62 | state = State.READY; 63 | return true; 64 | } 65 | return false; 66 | } 67 | 68 | @Override 69 | public final T next() { 70 | if (!hasNext()) { 71 | throw new NoSuchElementException(); 72 | } 73 | state = State.NOT_READY; 74 | return next; 75 | } 76 | 77 | /** 78 | * 79 | * @return a dummy value which if returned by the computeNext() method, signals that there are no more 80 | * elements to return 81 | */ 82 | protected final T endOfData() { 83 | state = State.DONE; 84 | return null; 85 | } 86 | 87 | /** 88 | * @return The next element which the iterator should return, or the result of calling endOfData() 89 | * if there are no more elements to return 90 | */ 91 | protected abstract T computeNext(); 92 | } 93 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/common/SetFromMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.common; 17 | 18 | import java.io.IOException; 19 | import java.io.ObjectInputStream; 20 | import java.io.Serializable; 21 | import java.util.*; 22 | 23 | /** 24 | * A facade implementation of a Java set for representing a Java map implementation. 25 | * 26 | * @param The element type. 27 | */ 28 | public class SetFromMap extends AbstractSet implements Serializable { 29 | 30 | private static final long serialVersionUID = 1L; 31 | 32 | private final Map delegate; 33 | 34 | private transient Set keySet; 35 | 36 | public SetFromMap(Map delegate) { 37 | this.delegate = delegate; 38 | keySet = delegate.keySet(); 39 | } 40 | 41 | private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { 42 | stream.defaultReadObject(); 43 | keySet = delegate.keySet(); 44 | } 45 | 46 | @Override 47 | public int size() { 48 | return delegate.size(); 49 | } 50 | 51 | @Override 52 | public boolean isEmpty() { 53 | return delegate.isEmpty(); 54 | } 55 | 56 | @Override 57 | public boolean contains(Object o) { 58 | return delegate.containsKey(o); 59 | } 60 | 61 | @Override 62 | public boolean remove(Object o) { 63 | return delegate.remove(o) != null; 64 | } 65 | 66 | @Override 67 | public void clear() { 68 | delegate.clear(); 69 | } 70 | 71 | @Override 72 | public boolean add(E e) { 73 | return delegate.put(e, Boolean.TRUE) == null; 74 | } 75 | 76 | @Override 77 | public Iterator iterator() { 78 | return keySet.iterator(); 79 | } 80 | 81 | @Override 82 | public Object[] toArray() { 83 | return keySet.toArray(); 84 | } 85 | 86 | @Override 87 | public T[] toArray(T[] a) { 88 | return keySet.toArray(a); 89 | } 90 | 91 | @Override 92 | public String toString() { 93 | return keySet.toString(); 94 | } 95 | 96 | @Override 97 | public int hashCode() { 98 | return keySet.hashCode(); 99 | } 100 | 101 | @Override 102 | public boolean equals(Object o) { 103 | return o == this || keySet.equals(o); 104 | } 105 | 106 | @Override 107 | public boolean containsAll(Collection c) { 108 | return keySet.containsAll(c); 109 | } 110 | 111 | @Override 112 | public boolean removeAll(Collection c) { 113 | return keySet.removeAll(c); 114 | } 115 | 116 | @Override 117 | public boolean retainAll(Collection c) { 118 | return keySet.retainAll(c); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node; 17 | 18 | import java.io.Serializable; 19 | import java.util.List; 20 | 21 | /** 22 | * An interface for a factory which creates new {@link Node} objects on demand, to encapsulate specified variables. 23 | * Factory objects can choose to return implementations of the {@link Node} interface which are memory-optimized for 24 | * storing only the given variables, potentially further optimized based on variable values. 25 | * 26 | * @author Niall Gallagher 27 | */ 28 | public interface NodeFactory extends Serializable { 29 | 30 | /** 31 | * Returns a new {@link Node} object which encapsulates the arguments supplied, optionally returning implementations 32 | * of the {@link Node} interface which are memory-optimized for storing only the supplied combination of variables, 33 | * potentially further optimized based on variable values. 34 | * 35 | * @param edgeCharacters Provides edge characters to be stored in the node. This is never null. In the case of 36 | * (re-)constructing the root node, this will contain zero characters, otherwise will always contain one or more 37 | * characters 38 | * 39 | * @param value An arbitrary object to associate with the node. This can be null, but it will not be null if 40 | * dealing with a leaf node (when childNodes will be empty) 41 | * 42 | * @param childNodes A list of child nodes to store in the node. This will never be null, but may be empty when 43 | * building a leaf node 44 | * 45 | * @param isRoot Indicates if this will be the root node, in which case edge characters will be non-null but empty, 46 | * value will be null, and child nodes will be non-null but may be empty 47 | * 48 | * @return An object implementing the {@link Node} interface which stores the given variables 49 | */ 50 | Node createNode(CharSequence edgeCharacters, Object value, NodeList childNodes, boolean isRoot); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node; 17 | 18 | import java.util.Collection; 19 | 20 | /** 21 | * A list of {@link Node}s represented by a tree. This interface is used rather then a Java list, 22 | * to allow representing concurrent arrays as such lists and to avoid allocating wrapper instances. 23 | */ 24 | public interface NodeList { 25 | 26 | int size(); 27 | 28 | Node get(int index); 29 | 30 | boolean isEmpty(); 31 | 32 | void set(int index, Node node); 33 | 34 | boolean contains(Node node); 35 | 36 | void addTo(Collection nodes); 37 | 38 | Node[] toArray(); 39 | } 40 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/SimpleNodeList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node; 17 | 18 | import java.util.Arrays; 19 | import java.util.Collection; 20 | import java.util.Collections; 21 | import java.util.List; 22 | 23 | /** 24 | * A simple implementation of a {@link NodeList} backed by a {@link List}. 25 | */ 26 | public class SimpleNodeList implements NodeList { 27 | 28 | private final List nodes; 29 | 30 | public static final NodeList EMPTY = new SimpleNodeList(); 31 | 32 | SimpleNodeList() { 33 | this.nodes = Collections.emptyList(); 34 | } 35 | 36 | public SimpleNodeList(Node node) { 37 | this.nodes = Collections.singletonList(node); 38 | } 39 | 40 | public SimpleNodeList(Node... nodes) { 41 | this.nodes = Arrays.asList(nodes); 42 | } 43 | 44 | public SimpleNodeList(List nodes) { 45 | this.nodes = nodes; 46 | } 47 | 48 | @Override 49 | public int size() { 50 | return nodes.size(); 51 | } 52 | 53 | @Override 54 | public Node get(int index) { 55 | return nodes.get(index); 56 | } 57 | 58 | @Override 59 | public boolean contains(Node node) { 60 | return nodes.contains(node); 61 | } 62 | 63 | @Override 64 | public boolean isEmpty() { 65 | return nodes.isEmpty(); 66 | } 67 | 68 | @Override 69 | public void set(int index, Node node) { 70 | nodes.set(index, node); 71 | } 72 | 73 | @Override 74 | public void addTo(Collection nodes) { 75 | nodes.addAll(this.nodes); 76 | } 77 | 78 | @Override 79 | public Node[] toArray() { 80 | return nodes.toArray(new Node[0]); 81 | } 82 | 83 | @Override 84 | public String toString() { 85 | return nodes.toString(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete; 17 | 18 | import com.googlecode.concurrenttrees.common.CharSequences; 19 | import com.googlecode.concurrenttrees.radix.node.Node; 20 | import com.googlecode.concurrenttrees.radix.node.NodeFactory; 21 | import com.googlecode.concurrenttrees.radix.node.NodeList; 22 | import com.googlecode.concurrenttrees.radix.node.concrete.bytearray.*; 23 | import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; 24 | import com.googlecode.concurrenttrees.radix.node.util.NodeUtil; 25 | 26 | /** 27 | * A {@link NodeFactory} which creates {@link Node} objects which store incoming edge characters as a byte array inside 28 | * the node. This is similar to {@link DefaultCharArrayNodeFactory}, except nodes use a single byte to represent each 29 | * character in UTF-8, instead of Java's default 2-byte UFT-16 encoding. 30 | *

31 | * This can reduce the memory overhead of storing character data by 50%, but supports only characters which can be 32 | * represented as a single byte in UTF-8. Throws an exception if characters are encountered which cannot be represented 33 | * as a single byte. 34 | * 35 | * @author Niall Gallagher 36 | */ 37 | public class DefaultByteArrayNodeFactory implements NodeFactory { 38 | 39 | private static final long serialVersionUID = 1L; 40 | 41 | private final boolean fast; 42 | 43 | public DefaultByteArrayNodeFactory() { 44 | fast = false; 45 | } 46 | 47 | DefaultByteArrayNodeFactory(boolean fast) { 48 | this.fast = fast; 49 | } 50 | 51 | @Override 52 | public Node createNode(CharSequence edgeCharacters, Object value, NodeList childNodes, boolean isRoot) { 53 | assert edgeCharacters != null : "The edgeCharacters argument was null"; 54 | assert isRoot || edgeCharacters.length() > 0 : "Invalid edge characters for non-root node: " + CharSequences.toString(edgeCharacters); 55 | assert childNodes != null : "The edgeCharacters argument was null"; 56 | assert NodeUtil.hasNoDuplicateEdges(childNodes) : "Duplicate edge detected in list of nodes supplied: " + childNodes; 57 | byte[] incomingEdgeCharArray = ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharacters, fast); 58 | if (incomingEdgeCharArray == null) { 59 | return null; 60 | } 61 | if (childNodes.isEmpty()) { 62 | // Leaf node... 63 | if (value instanceof VoidValue) { 64 | return new ByteArrayNodeLeafVoidValue(incomingEdgeCharArray); 65 | } 66 | else if (value != null) { 67 | return new ByteArrayNodeLeafWithValue(incomingEdgeCharArray, value); 68 | } 69 | else { 70 | return new ByteArrayNodeLeafNullValue(incomingEdgeCharArray); 71 | } 72 | } 73 | else { 74 | // Non-leaf node... 75 | if (value instanceof VoidValue) { 76 | return new ByteArrayNodeNonLeafVoidValue(incomingEdgeCharArray, childNodes); 77 | } 78 | else if (value == null) { 79 | return new ByteArrayNodeNonLeafNullValue(incomingEdgeCharArray, childNodes); 80 | } 81 | else { 82 | return new ByteArrayNodeDefault(incomingEdgeCharArray, value, childNodes); 83 | } 84 | } 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete; 17 | 18 | import com.googlecode.concurrenttrees.common.CharSequences; 19 | import com.googlecode.concurrenttrees.radix.node.Node; 20 | import com.googlecode.concurrenttrees.radix.node.NodeFactory; 21 | import com.googlecode.concurrenttrees.radix.node.NodeList; 22 | import com.googlecode.concurrenttrees.radix.node.concrete.chararray.*; 23 | import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; 24 | import com.googlecode.concurrenttrees.radix.node.util.NodeUtil; 25 | 26 | /** 27 | * A {@link NodeFactory} which creates various implementations of {@link Node} objects all of which store incoming 28 | * edge characters as a character array inside the node. 29 | *

30 | * Returns an optimal node implementation depending on arguments supplied, which will be one of: 31 | *

38 | *

39 | * When the application supplies {@link VoidValue} for a value, this factory will omit actually storing that value 40 | * in the tree and will return one of the VoidValue-optimized nodes above which can reduce memory usage. 41 | * 42 | * @author Niall Gallagher 43 | */ 44 | public class DefaultCharArrayNodeFactory implements NodeFactory { 45 | 46 | private static final long serialVersionUID = 1L; 47 | 48 | @Override 49 | public Node createNode(CharSequence edgeCharacters, Object value, NodeList childNodes, boolean isRoot) { 50 | assert edgeCharacters != null : "The edgeCharacters argument was null"; 51 | assert isRoot || edgeCharacters.length() > 0 : "Invalid edge characters for non-root node: " + CharSequences.toString(edgeCharacters); 52 | assert childNodes != null : "The edgeCharacters argument was null"; 53 | assert NodeUtil.hasNoDuplicateEdges(childNodes) : "Duplicate edge detected in list of nodes supplied: " + childNodes; 54 | if (childNodes.isEmpty()) { 55 | // Leaf node... 56 | if (value instanceof VoidValue) { 57 | return new CharArrayNodeLeafVoidValue(edgeCharacters); 58 | } 59 | else if (value != null) { 60 | return new CharArrayNodeLeafWithValue(edgeCharacters, value); 61 | } 62 | else { 63 | return new CharArrayNodeLeafNullValue(edgeCharacters); 64 | } 65 | } 66 | else { 67 | // Non-leaf node... 68 | if (value instanceof VoidValue) { 69 | return new CharArrayNodeNonLeafVoidValue(edgeCharacters, childNodes); 70 | } 71 | else if (value == null) { 72 | return new CharArrayNodeNonLeafNullValue(edgeCharacters, childNodes); 73 | } 74 | else { 75 | return new CharArrayNodeDefault(edgeCharacters, value, childNodes); 76 | } 77 | } 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.NodeFactory; 20 | import com.googlecode.concurrenttrees.radix.node.NodeList; 21 | import com.googlecode.concurrenttrees.radix.node.concrete.bytearray.ByteArrayCharSequence; 22 | 23 | /** 24 | * A {@link NodeFactory} which internally uses {@link DefaultByteArrayNodeFactory} to create nodes by default (which 25 | * can reduce memory overhead), but falls back to {@link DefaultCharArrayNodeFactory} if characters are detected which 26 | * cannot be represented as a single byte. 27 | * 28 | * @author Niall Gallagher 29 | */ 30 | public class SmartArrayBasedNodeFactory implements NodeFactory { 31 | 32 | private static final long serialVersionUID = 1L; 33 | 34 | final NodeFactory charArrayNodeFactory = new DefaultCharArrayNodeFactory(); 35 | final NodeFactory byteArrayNodeFactory = new DefaultByteArrayNodeFactory(true); 36 | 37 | @Override 38 | public Node createNode(CharSequence edgeCharacters, Object value, NodeList childNodes, boolean isRoot) { 39 | Node node = byteArrayNodeFactory.createNode(edgeCharacters, value, childNodes, isRoot); 40 | if (node == null) { 41 | return charArrayNodeFactory.createNode(edgeCharacters, value, childNodes, isRoot); 42 | } else { 43 | return node; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.NodeList; 20 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 21 | 22 | /** 23 | * Similar to {@link com.googlecode.concurrenttrees.radix.node.concrete.chararray.CharArrayNodeLeafNullValue} but represents 24 | * each character in UTF-8, instead of Java's default 2-byte UFT-16 encoding. 25 | *

26 | * Supports only characters which can be represented as a single byte in UTF-8. Throws an exception if characters 27 | * are encountered which cannot be represented as a single byte. 28 | * 29 | * @author Niall Gallagher 30 | */ 31 | public class ByteArrayNodeLeafNullValue implements Node { 32 | 33 | private static final long serialVersionUID = 1L; 34 | 35 | // Characters in the edge arriving at this node from a parent node. 36 | // Once assigned, we never modify this... 37 | private final byte[] incomingEdgeCharArray; 38 | 39 | public ByteArrayNodeLeafNullValue(CharSequence edgeCharSequence) { 40 | this(ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence)); 41 | } 42 | 43 | public ByteArrayNodeLeafNullValue(byte[] incomingEdgeCharArray) { 44 | this.incomingEdgeCharArray = incomingEdgeCharArray; 45 | } 46 | 47 | @Override 48 | public CharSequence getIncomingEdge() { 49 | return new ByteArrayCharSequence(incomingEdgeCharArray, 0, incomingEdgeCharArray.length); 50 | } 51 | 52 | @Override 53 | public char getIncomingEdgeFirstCharacter() { 54 | return (char) (incomingEdgeCharArray[0] & 0xFF); 55 | } 56 | 57 | @Override 58 | public int getIncomingEdgeLength() { 59 | return incomingEdgeCharArray.length; 60 | } 61 | 62 | @Override 63 | public char getIncomingEdgeCharacterAt(int index) { 64 | return (char) (incomingEdgeCharArray[index] & 0xFF); 65 | } 66 | 67 | @Override 68 | public Object getValue() { 69 | return null; 70 | } 71 | 72 | @Override 73 | public Node getOutgoingEdge(char edgeFirstCharacter) { 74 | return null; 75 | } 76 | 77 | @Override 78 | public void updateOutgoingEdge(Node childNode) { 79 | throw new IllegalStateException("Cannot update the reference to the following child node for the edge starting with '" + childNode.getIncomingEdgeFirstCharacter() +"', no such edge already exists: " + childNode); 80 | } 81 | 82 | @Override 83 | public NodeList getOutgoingEdges() { 84 | return SimpleNodeList.EMPTY; 85 | } 86 | 87 | @Override 88 | public String toString() { 89 | StringBuilder sb = new StringBuilder(); 90 | sb.append("Node{"); 91 | sb.append("edge=").append(getIncomingEdge()); 92 | sb.append(", value=null"); 93 | sb.append(", edges=[]"); 94 | sb.append("}"); 95 | return sb.toString(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.NodeList; 20 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 21 | import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; 22 | 23 | /** 24 | * Similar to {@link com.googlecode.concurrenttrees.radix.node.concrete.chararray.CharArrayNodeLeafVoidValue} but represents 25 | * each character in UTF-8, instead of Java's default 2-byte UFT-16 encoding. 26 | *

27 | * Supports only characters which can be represented as a single byte in UTF-8. Throws an exception if characters 28 | * are encountered which cannot be represented as a single byte. 29 | * 30 | * @author Niall Gallagher 31 | */ 32 | public class ByteArrayNodeLeafVoidValue implements Node { 33 | 34 | private static final long serialVersionUID = 1L; 35 | 36 | // Characters in the edge arriving at this node from a parent node. 37 | // Once assigned, we never modify this... 38 | private final byte[] incomingEdgeCharArray; 39 | 40 | public ByteArrayNodeLeafVoidValue(CharSequence edgeCharSequence) { 41 | this(ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence)); 42 | } 43 | 44 | public ByteArrayNodeLeafVoidValue(byte[] incomingEdgeCharArray) { 45 | this.incomingEdgeCharArray = incomingEdgeCharArray; 46 | } 47 | 48 | @Override 49 | public CharSequence getIncomingEdge() { 50 | return new ByteArrayCharSequence(incomingEdgeCharArray, 0, incomingEdgeCharArray.length); 51 | } 52 | 53 | @Override 54 | public char getIncomingEdgeFirstCharacter() { 55 | return (char) (incomingEdgeCharArray[0] & 0xFF); 56 | } 57 | 58 | @Override 59 | public int getIncomingEdgeLength() { 60 | return incomingEdgeCharArray.length; 61 | } 62 | 63 | @Override 64 | public char getIncomingEdgeCharacterAt(int index) { 65 | return (char) (incomingEdgeCharArray[index] & 0xFF); 66 | } 67 | 68 | @Override 69 | public Object getValue() { 70 | return VoidValue.SINGLETON; 71 | } 72 | 73 | @Override 74 | public Node getOutgoingEdge(char edgeFirstCharacter) { 75 | return null; 76 | } 77 | 78 | @Override 79 | public void updateOutgoingEdge(Node childNode) { 80 | throw new IllegalStateException("Cannot update the reference to the following child node for the edge starting with '" + childNode.getIncomingEdgeFirstCharacter() +"', no such edge already exists: " + childNode); 81 | } 82 | 83 | @Override 84 | public NodeList getOutgoingEdges() { 85 | return SimpleNodeList.EMPTY; 86 | } 87 | 88 | @Override 89 | public String toString() { 90 | StringBuilder sb = new StringBuilder(); 91 | sb.append("Node{"); 92 | sb.append("edge=").append(getIncomingEdge()); 93 | sb.append(", value=").append(VoidValue.SINGLETON); 94 | sb.append(", edges=[]"); 95 | sb.append("}"); 96 | return sb.toString(); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.NodeList; 20 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 21 | 22 | /** 23 | * Similar to {@link com.googlecode.concurrenttrees.radix.node.concrete.chararray.CharArrayNodeLeafWithValue} but represents 24 | * each character in UTF-8, instead of Java's default 2-byte UFT-16 encoding. 25 | *

26 | * Supports only characters which can be represented as a single byte in UTF-8. Throws an exception if characters 27 | * are encountered which cannot be represented as a single byte. 28 | * 29 | * @author Niall Gallagher 30 | */ 31 | public class ByteArrayNodeLeafWithValue implements Node { 32 | 33 | private static final long serialVersionUID = 1L; 34 | 35 | // Characters in the edge arriving at this node from a parent node. 36 | // Once assigned, we never modify this... 37 | private final byte[] incomingEdgeCharArray; 38 | 39 | // An arbitrary value which the application associates with a key matching the path to this node in the tree. 40 | // This value can be null... 41 | private final Object value; 42 | 43 | public ByteArrayNodeLeafWithValue(CharSequence edgeCharSequence, Object value) { 44 | this(ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence), value); 45 | } 46 | 47 | public ByteArrayNodeLeafWithValue(byte[] incomingEdgeCharArray, Object value) { 48 | this.incomingEdgeCharArray = incomingEdgeCharArray; 49 | this.value = value; 50 | } 51 | 52 | @Override 53 | public CharSequence getIncomingEdge() { 54 | return new ByteArrayCharSequence(incomingEdgeCharArray, 0, incomingEdgeCharArray.length); 55 | } 56 | 57 | @Override 58 | public char getIncomingEdgeFirstCharacter() { 59 | return (char) (incomingEdgeCharArray[0] & 0xFF); 60 | } 61 | 62 | @Override 63 | public int getIncomingEdgeLength() { 64 | return incomingEdgeCharArray.length; 65 | } 66 | 67 | @Override 68 | public char getIncomingEdgeCharacterAt(int index) { 69 | return (char) (incomingEdgeCharArray[index] & 0xFF); 70 | } 71 | 72 | @Override 73 | public Object getValue() { 74 | return value; 75 | } 76 | 77 | @Override 78 | public Node getOutgoingEdge(char edgeFirstCharacter) { 79 | return null; 80 | } 81 | 82 | @Override 83 | public void updateOutgoingEdge(Node childNode) { 84 | throw new IllegalStateException("Cannot update the reference to the following child node for the edge starting with '" + childNode.getIncomingEdgeFirstCharacter() +"', no such edge already exists: " + childNode); 85 | } 86 | 87 | @Override 88 | public NodeList getOutgoingEdges() { 89 | return SimpleNodeList.EMPTY; 90 | } 91 | 92 | @Override 93 | public String toString() { 94 | StringBuilder sb = new StringBuilder(); 95 | sb.append("Node{"); 96 | sb.append("edge=").append(getIncomingEdge()); 97 | sb.append(", value=").append(value); 98 | sb.append(", edges=[]"); 99 | sb.append("}"); 100 | return sb.toString(); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.chararray; 17 | 18 | import com.googlecode.concurrenttrees.common.CharSequences; 19 | import com.googlecode.concurrenttrees.radix.node.Node; 20 | import com.googlecode.concurrenttrees.radix.node.NodeList; 21 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 22 | 23 | /** 24 | * Stores only incoming edge as a {@code char[]}. 25 | * Returns {@code null} for the value. Does not store any outgoing edges. 26 | * 27 | * @author Niall Gallagher 28 | */ 29 | public class CharArrayNodeLeafNullValue implements Node { 30 | 31 | private static final long serialVersionUID = 1L; 32 | 33 | // Characters in the edge arriving at this node from a parent node. 34 | // Once assigned, we never modify this... 35 | private final char[] incomingEdgeCharArray; 36 | 37 | public CharArrayNodeLeafNullValue(CharSequence edgeCharSequence) { 38 | this.incomingEdgeCharArray = CharSequences.toCharArray(edgeCharSequence); 39 | } 40 | 41 | @Override 42 | public CharSequence getIncomingEdge() { 43 | return CharSequences.fromCharArray(incomingEdgeCharArray); 44 | } 45 | 46 | @Override 47 | public char getIncomingEdgeFirstCharacter() { 48 | return incomingEdgeCharArray[0]; 49 | } 50 | 51 | @Override 52 | public int getIncomingEdgeLength() { 53 | return incomingEdgeCharArray.length; 54 | } 55 | 56 | @Override 57 | public char getIncomingEdgeCharacterAt(int index) { 58 | return incomingEdgeCharArray[index]; 59 | } 60 | 61 | @Override 62 | public Object getValue() { 63 | return null; 64 | } 65 | 66 | @Override 67 | public Node getOutgoingEdge(char edgeFirstCharacter) { 68 | return null; 69 | } 70 | 71 | @Override 72 | public void updateOutgoingEdge(Node childNode) { 73 | throw new IllegalStateException("Cannot update the reference to the following child node for the edge starting with '" + childNode.getIncomingEdgeFirstCharacter() +"', no such edge already exists: " + childNode); 74 | } 75 | 76 | @Override 77 | public NodeList getOutgoingEdges() { 78 | return SimpleNodeList.EMPTY; 79 | } 80 | 81 | @Override 82 | public String toString() { 83 | StringBuilder sb = new StringBuilder(); 84 | sb.append("Node{"); 85 | sb.append("edge=").append(incomingEdgeCharArray); 86 | sb.append(", value=null"); 87 | sb.append(", edges=[]"); 88 | sb.append("}"); 89 | return sb.toString(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.chararray; 17 | 18 | import com.googlecode.concurrenttrees.common.CharSequences; 19 | import com.googlecode.concurrenttrees.radix.node.Node; 20 | import com.googlecode.concurrenttrees.radix.node.NodeList; 21 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 22 | import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; 23 | 24 | /** 25 | * Stores only incoming edge as a {@code char[]}. 26 | * Returns {@link VoidValue} for the value. Does not store any outgoing edges. 27 | * 28 | * @author Niall Gallagher 29 | */ 30 | public class CharArrayNodeLeafVoidValue implements Node { 31 | 32 | private static final long serialVersionUID = 1L; 33 | 34 | // Characters in the edge arriving at this node from a parent node. 35 | // Once assigned, we never modify this... 36 | private final char[] incomingEdgeCharArray; 37 | 38 | public CharArrayNodeLeafVoidValue(CharSequence edgeCharSequence) { 39 | this.incomingEdgeCharArray = CharSequences.toCharArray(edgeCharSequence); 40 | } 41 | 42 | @Override 43 | public CharSequence getIncomingEdge() { 44 | return CharSequences.fromCharArray(incomingEdgeCharArray); 45 | } 46 | 47 | @Override 48 | public char getIncomingEdgeFirstCharacter() { 49 | return incomingEdgeCharArray[0]; 50 | } 51 | 52 | @Override 53 | public int getIncomingEdgeLength() { 54 | return incomingEdgeCharArray.length; 55 | } 56 | 57 | @Override 58 | public char getIncomingEdgeCharacterAt(int index) { 59 | return incomingEdgeCharArray[index]; 60 | } 61 | 62 | @Override 63 | public Object getValue() { 64 | return VoidValue.SINGLETON; 65 | } 66 | 67 | @Override 68 | public Node getOutgoingEdge(char edgeFirstCharacter) { 69 | return null; 70 | } 71 | 72 | @Override 73 | public void updateOutgoingEdge(Node childNode) { 74 | throw new IllegalStateException("Cannot update the reference to the following child node for the edge starting with '" + childNode.getIncomingEdgeFirstCharacter() +"', no such edge already exists: " + childNode); 75 | } 76 | 77 | @Override 78 | public NodeList getOutgoingEdges() { 79 | return SimpleNodeList.EMPTY; 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | StringBuilder sb = new StringBuilder(); 85 | sb.append("Node{"); 86 | sb.append("edge=").append(incomingEdgeCharArray); 87 | sb.append(", value=").append(VoidValue.SINGLETON); 88 | sb.append(", edges=[]"); 89 | sb.append("}"); 90 | return sb.toString(); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.chararray; 17 | 18 | import com.googlecode.concurrenttrees.common.CharSequences; 19 | import com.googlecode.concurrenttrees.radix.node.Node; 20 | import com.googlecode.concurrenttrees.radix.node.NodeList; 21 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 22 | 23 | /** 24 | * Stores only incoming edge as a {@code char[]}, and a reference to a value. Does not store any outgoing 25 | * edges. 26 | * 27 | * @author Niall Gallagher 28 | */ 29 | public class CharArrayNodeLeafWithValue implements Node { 30 | 31 | private static final long serialVersionUID = 1L; 32 | 33 | // Characters in the edge arriving at this node from a parent node. 34 | // Once assigned, we never modify this... 35 | private final char[] incomingEdgeCharArray; 36 | 37 | // An arbitrary value which the application associates with a key matching the path to this node in the tree. 38 | // This value can be null... 39 | private final Object value; 40 | 41 | public CharArrayNodeLeafWithValue(CharSequence edgeCharSequence, Object value) { 42 | this.incomingEdgeCharArray = CharSequences.toCharArray(edgeCharSequence); 43 | this.value = value; 44 | } 45 | 46 | @Override 47 | public CharSequence getIncomingEdge() { 48 | return CharSequences.fromCharArray(incomingEdgeCharArray); 49 | } 50 | 51 | @Override 52 | public char getIncomingEdgeFirstCharacter() { 53 | return incomingEdgeCharArray[0]; 54 | } 55 | 56 | @Override 57 | public int getIncomingEdgeLength() { 58 | return incomingEdgeCharArray.length; 59 | } 60 | 61 | @Override 62 | public char getIncomingEdgeCharacterAt(int index) { 63 | return incomingEdgeCharArray[index]; 64 | } 65 | 66 | @Override 67 | public Object getValue() { 68 | return value; 69 | } 70 | 71 | @Override 72 | public Node getOutgoingEdge(char edgeFirstCharacter) { 73 | return null; 74 | } 75 | 76 | @Override 77 | public void updateOutgoingEdge(Node childNode) { 78 | throw new IllegalStateException("Cannot update the reference to the following child node for the edge starting with '" + childNode.getIncomingEdgeFirstCharacter() +"', no such edge already exists: " + childNode); 79 | } 80 | 81 | @Override 82 | public NodeList getOutgoingEdges() { 83 | return SimpleNodeList.EMPTY; 84 | } 85 | 86 | @Override 87 | public String toString() { 88 | StringBuilder sb = new StringBuilder(); 89 | sb.append("Node{"); 90 | sb.append("edge=").append(incomingEdgeCharArray); 91 | sb.append(", value=").append(value); 92 | sb.append(", edges=[]"); 93 | sb.append("}"); 94 | return sb.toString(); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.NodeList; 20 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 21 | 22 | /** 23 | * Stores only incoming edge as a {@link CharSequence} (a view onto the original key) rather than copying the 24 | * edge into a character array. Returns {@code null} for the value. Does not store any outgoing edges. 25 | * 26 | * @author Niall Gallagher 27 | */ 28 | public class CharSequenceNodeLeafNullValue implements Node { 29 | 30 | private static final long serialVersionUID = 1L; 31 | 32 | // Characters in the edge arriving at this node from a parent node. 33 | // Once assigned, we never modify this... 34 | private final CharSequence incomingEdgeCharSequence; 35 | 36 | public CharSequenceNodeLeafNullValue(CharSequence edgeCharSequence) { 37 | this.incomingEdgeCharSequence = edgeCharSequence; 38 | } 39 | 40 | @Override 41 | public CharSequence getIncomingEdge() { 42 | return incomingEdgeCharSequence; 43 | } 44 | 45 | @Override 46 | public char getIncomingEdgeFirstCharacter() { 47 | return incomingEdgeCharSequence.charAt(0); 48 | } 49 | 50 | @Override 51 | public int getIncomingEdgeLength() { 52 | return incomingEdgeCharSequence.length(); 53 | } 54 | 55 | @Override 56 | public char getIncomingEdgeCharacterAt(int index) { 57 | return incomingEdgeCharSequence.charAt(index); 58 | } 59 | 60 | @Override 61 | public Object getValue() { 62 | return null; 63 | } 64 | 65 | @Override 66 | public Node getOutgoingEdge(char edgeFirstCharacter) { 67 | return null; 68 | } 69 | 70 | @Override 71 | public void updateOutgoingEdge(Node childNode) { 72 | throw new IllegalStateException("Cannot update the reference to the following child node for the edge starting with '" + childNode.getIncomingEdgeFirstCharacter() +"', no such edge already exists: " + childNode); 73 | } 74 | 75 | @Override 76 | public NodeList getOutgoingEdges() { 77 | return SimpleNodeList.EMPTY; 78 | } 79 | 80 | @Override 81 | public String toString() { 82 | StringBuilder sb = new StringBuilder(); 83 | sb.append("Node{"); 84 | sb.append("edge=").append(incomingEdgeCharSequence); 85 | sb.append(", value=null"); 86 | sb.append(", edges=[]"); 87 | sb.append("}"); 88 | return sb.toString(); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.NodeList; 20 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 21 | import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; 22 | 23 | /** 24 | * Stores only incoming edge as a {@link CharSequence} (a view onto the original key) rather than copying the 25 | * edge into a character array. Returns {@link VoidValue} for the value. Does not store any outgoing edges. 26 | * 27 | * @author Niall Gallagher 28 | */ 29 | public class CharSequenceNodeLeafVoidValue implements Node { 30 | 31 | private static final long serialVersionUID = 1L; 32 | 33 | // Characters in the edge arriving at this node from a parent node. 34 | // Once assigned, we never modify this... 35 | private final CharSequence incomingEdgeCharSequence; 36 | 37 | public CharSequenceNodeLeafVoidValue(CharSequence edgeCharSequence) { 38 | this.incomingEdgeCharSequence = edgeCharSequence; 39 | } 40 | 41 | @Override 42 | public CharSequence getIncomingEdge() { 43 | return incomingEdgeCharSequence; 44 | } 45 | 46 | @Override 47 | public char getIncomingEdgeFirstCharacter() { 48 | return incomingEdgeCharSequence.charAt(0); 49 | } 50 | 51 | @Override 52 | public int getIncomingEdgeLength() { 53 | return incomingEdgeCharSequence.length(); 54 | } 55 | 56 | @Override 57 | public char getIncomingEdgeCharacterAt(int index) { 58 | return incomingEdgeCharSequence.charAt(index); 59 | } 60 | 61 | @Override 62 | public Object getValue() { 63 | return VoidValue.SINGLETON; 64 | } 65 | 66 | @Override 67 | public Node getOutgoingEdge(char edgeFirstCharacter) { 68 | return null; 69 | } 70 | 71 | @Override 72 | public void updateOutgoingEdge(Node childNode) { 73 | throw new IllegalStateException("Cannot update the reference to the following child node for the edge starting with '" + childNode.getIncomingEdgeFirstCharacter() +"', no such edge already exists: " + childNode); 74 | } 75 | 76 | @Override 77 | public NodeList getOutgoingEdges() { 78 | return SimpleNodeList.EMPTY; 79 | } 80 | 81 | @Override 82 | public String toString() { 83 | StringBuilder sb = new StringBuilder(); 84 | sb.append("Node{"); 85 | sb.append("edge=").append(incomingEdgeCharSequence); 86 | sb.append(", value=").append(VoidValue.SINGLETON); 87 | sb.append(", edges=[]"); 88 | sb.append("}"); 89 | return sb.toString(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.NodeList; 20 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 21 | 22 | /** 23 | * Stores incoming edge as a {@link CharSequence} (a view onto the original key) rather than copying the 24 | * edge into a character array. Also stores a reference to a value. Does not store any outgoing edges. 25 | * 26 | * @author Niall Gallagher 27 | */ 28 | public class CharSequenceNodeLeafWithValue implements Node { 29 | 30 | private static final long serialVersionUID = 1L; 31 | 32 | // Characters in the edge arriving at this node from a parent node. 33 | // Once assigned, we never modify this... 34 | private final CharSequence incomingEdgeCharSequence; 35 | 36 | // An arbitrary value which the application associates with a key matching the path to this node in the tree. 37 | // This value can be null... 38 | private final Object value; 39 | 40 | public CharSequenceNodeLeafWithValue(CharSequence edgeCharSequence, Object value) { 41 | // Sort the child nodes... 42 | this.incomingEdgeCharSequence = edgeCharSequence; 43 | this.value = value; 44 | } 45 | 46 | @Override 47 | public CharSequence getIncomingEdge() { 48 | return incomingEdgeCharSequence; 49 | } 50 | 51 | @Override 52 | public char getIncomingEdgeFirstCharacter() { 53 | return incomingEdgeCharSequence.charAt(0); 54 | } 55 | 56 | @Override 57 | public int getIncomingEdgeLength() { 58 | return incomingEdgeCharSequence.length(); 59 | } 60 | 61 | @Override 62 | public char getIncomingEdgeCharacterAt(int index) { 63 | return incomingEdgeCharSequence.charAt(index); 64 | } 65 | 66 | @Override 67 | public Object getValue() { 68 | return value; 69 | } 70 | 71 | @Override 72 | public Node getOutgoingEdge(char edgeFirstCharacter) { 73 | return null; 74 | } 75 | 76 | @Override 77 | public void updateOutgoingEdge(Node childNode) { 78 | throw new IllegalStateException("Cannot update the reference to the following child node for the edge starting with '" + childNode.getIncomingEdgeFirstCharacter() +"', no such edge already exists: " + childNode); 79 | } 80 | 81 | @Override 82 | public NodeList getOutgoingEdges() { 83 | return SimpleNodeList.EMPTY; 84 | } 85 | 86 | @Override 87 | public String toString() { 88 | StringBuilder sb = new StringBuilder(); 89 | sb.append("Node{"); 90 | sb.append("edge=").append(incomingEdgeCharSequence); 91 | sb.append(", value=").append(value); 92 | sb.append(", edges=[]"); 93 | sb.append("}"); 94 | return sb.toString(); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/voidvalue/VoidValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.voidvalue; 17 | 18 | /** 19 | * A dummy object which if supplied as a value for an entry in a tree, will not actually be stored in the tree by 20 | * {@link com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharArrayNodeFactory} or 21 | * {@link com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharSequenceNodeFactory} to save memory. 22 | * 23 | * @author Niall Gallagher 24 | */ 25 | public class VoidValue { 26 | 27 | @Override 28 | public int hashCode() { 29 | return 1; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | return obj instanceof VoidValue; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "-"; 40 | } 41 | 42 | VoidValue() { 43 | } 44 | 45 | public static final VoidValue SINGLETON = new VoidValue(); 46 | } 47 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/AtomicNodeReferenceArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.util; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.NodeList; 20 | 21 | import java.util.Collection; 22 | import java.util.concurrent.atomic.AtomicReferenceArray; 23 | 24 | public class AtomicNodeReferenceArray extends AtomicReferenceArray implements NodeList { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | public AtomicNodeReferenceArray(Node[] array) { 29 | super(array); 30 | } 31 | 32 | @Override 33 | public int size() { 34 | return length(); 35 | } 36 | 37 | @Override 38 | public boolean isEmpty() { 39 | return length() == 0; 40 | } 41 | 42 | @Override 43 | public boolean contains(Node node) { 44 | for (int index = 0; index < length(); index++) { 45 | if (node == null && get(index) == null || node != null && node.equals(get(index))) { 46 | return true; 47 | } 48 | } 49 | return false; 50 | } 51 | 52 | @Override 53 | public void addTo(Collection nodes) { 54 | for (int index = 0; index < length(); index++) { 55 | nodes.add(get(index)); 56 | } 57 | } 58 | 59 | @Override 60 | public Node[] toArray() { 61 | Node[] nodes = new Node[length()]; 62 | for (int index = 0; index < nodes.length; index++) { 63 | nodes[index] = get(index); 64 | } 65 | return nodes; 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | StringBuilder sb = new StringBuilder(); 71 | sb.append('['); 72 | for (int index = 0; index < length(); index++) { 73 | if (index > 0) { 74 | sb.append(", "); 75 | } 76 | sb.append(get(index)); 77 | } 78 | sb.append(']'); 79 | return sb.toString(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.util; 17 | 18 | import java.util.Comparator; 19 | 20 | /** 21 | * Specifies binary search compatibility, and sorting compatibility, of nodes based on 22 | * {@link com.googlecode.concurrenttrees.radix.node.Node#getIncomingEdgeFirstCharacter()}. 23 | * 24 | * @author Niall Gallagher 25 | */ 26 | public class NodeCharacterComparator implements Comparator { 27 | 28 | NodeCharacterComparator() { 29 | } 30 | 31 | @Override 32 | public int compare(NodeCharacterProvider o1, NodeCharacterProvider o2) { 33 | return o1.getIncomingEdgeFirstCharacter() - o2.getIncomingEdgeFirstCharacter(); 34 | } 35 | 36 | public static final Comparator SINGLETON = new NodeCharacterComparator(); 37 | } 38 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.util; 17 | 18 | /** 19 | * A lightweight object which simply wraps a {@code char} and implements {@link NodeCharacterProvider}, which 20 | * can be used as a key to locate a node having the same edge first character in a list of nodes using binary search. 21 | * 22 | * @author Niall Gallagher 23 | */ 24 | public class NodeCharacterKey implements NodeCharacterProvider { 25 | 26 | private final char character; 27 | 28 | public NodeCharacterKey(char character) { 29 | this.character = character; 30 | } 31 | 32 | @Override 33 | public char getIncomingEdgeFirstCharacter() { 34 | return character; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.util; 17 | 18 | /** 19 | * A super-interface of both {@link com.googlecode.concurrenttrees.radix.node.Node} and {@link NodeCharacterKey} 20 | * which, by sharing this common interface, enables binary search of nodes via 21 | * {@link java.util.Collections#binarySearch(java.util.List, Object, java.util.Comparator)}. 22 | * 23 | * @see NodeCharacterComparator 24 | * @see NodeCharacterKey 25 | * 26 | * @author Niall Gallagher 27 | */ 28 | public interface NodeCharacterProvider { 29 | 30 | char getIncomingEdgeFirstCharacter(); 31 | } 32 | -------------------------------------------------------------------------------- /code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/PrettyPrintable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.util; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | 20 | /** 21 | * An internal interface implemented by trees, which allows internal details of trees to be accessed by 22 | * {@link com.googlecode.concurrenttrees.common.PrettyPrinter}. 23 | * 24 | * @author Niall Gallagher 25 | */ 26 | public interface PrettyPrintable { 27 | Node getNode(); 28 | } 29 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/common/IterablesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.common; 17 | 18 | import org.junit.Assert; 19 | import org.junit.Test; 20 | 21 | import java.util.*; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class IterablesTest { 27 | 28 | final Iterable DUMMY_COLLECTION = new ArrayList(Arrays.asList(1, 2, 3, 4)); 29 | final Iterable DUMMY_ITERABLE = new Iterable() { 30 | @Override 31 | public Iterator iterator() { 32 | return LazyIteratorTest.newLazyIterator(1, 2, 3, 4); 33 | } 34 | }; 35 | 36 | @Test 37 | public void testToList() { 38 | Assert.assertTrue("should be an instance of ArrayList", Iterables.toList(DUMMY_COLLECTION) instanceof ArrayList); 39 | Assert.assertTrue("should have 4 elements", Iterables.count(Iterables.toList(DUMMY_COLLECTION)) == 4); 40 | Assert.assertEquals("[1, 2, 3, 4]", Iterables.toString(Iterables.toList(DUMMY_COLLECTION))); 41 | 42 | 43 | Assert.assertTrue("should be an instance of LinkedList", Iterables.toList(DUMMY_ITERABLE) instanceof LinkedList); 44 | Assert.assertTrue("should have 4 elements", Iterables.count(Iterables.toList(DUMMY_ITERABLE)) == 4); 45 | Assert.assertEquals("[1, 2, 3, 4]", Iterables.toString(Iterables.toList(DUMMY_ITERABLE))); 46 | } 47 | 48 | @Test 49 | public void testToSet() { 50 | Assert.assertTrue("should be an instance of LinkedHashSet", Iterables.toSet(DUMMY_COLLECTION) instanceof LinkedHashSet); 51 | Assert.assertTrue("should have 4 elements", Iterables.count(Iterables.toSet(DUMMY_COLLECTION)) == 4); 52 | Assert.assertEquals("[1, 2, 3, 4]", Iterables.toString(Iterables.toSet(DUMMY_COLLECTION))); 53 | 54 | Assert.assertTrue("should be an instance of LinkedHashSet", Iterables.toSet(DUMMY_ITERABLE) instanceof LinkedHashSet); 55 | Assert.assertTrue("should have 4 elements", Iterables.count(Iterables.toSet(DUMMY_ITERABLE)) == 4); 56 | Assert.assertEquals("[1, 2, 3, 4]", Iterables.toString(Iterables.toSet(DUMMY_ITERABLE))); 57 | 58 | } 59 | 60 | @Test 61 | public void testToString() { 62 | Assert.assertEquals("[1, 2, 3, 4]", Iterables.toString(DUMMY_COLLECTION)); 63 | } 64 | 65 | @Test 66 | public void testCount() { 67 | Assert.assertEquals(4, Iterables.count(DUMMY_COLLECTION)); 68 | } 69 | 70 | @Test 71 | public void testConstructor() { 72 | Assert.assertNotNull(new Iterables()); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/common/LazyIteratorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.common; 17 | 18 | import org.junit.Assert; 19 | import org.junit.Test; 20 | 21 | import java.util.*; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class LazyIteratorTest { 27 | 28 | static LazyIterator newLazyIterator(final Integer... values) { 29 | return new LazyIterator() { 30 | 31 | final Iterator backingIterator = Arrays.asList(values).iterator(); 32 | 33 | @Override 34 | protected Integer computeNext() { 35 | if (backingIterator.hasNext()) { 36 | return backingIterator.next(); 37 | } 38 | else { 39 | return endOfData(); 40 | } 41 | } 42 | }; 43 | } 44 | 45 | static LazyIterator newFaultyLazyIterator() { 46 | return new LazyIterator() { 47 | @Override 48 | protected Integer computeNext() { 49 | throw new RuntimeException(); 50 | } 51 | }; 52 | } 53 | 54 | static void advance(LazyIterator lazyIterator, int elementsToAdvance) { 55 | for (int i = 0; i < elementsToAdvance; i++) { 56 | lazyIterator.next(); 57 | } 58 | } 59 | 60 | @Test(expected = UnsupportedOperationException.class) 61 | public void testRemove() { 62 | LazyIterator lazyIterator = newLazyIterator(1, 2, 3, 4); 63 | lazyIterator.remove(); 64 | } 65 | 66 | @Test 67 | public void testIteration() { 68 | LazyIterator lazyIterator = newLazyIterator(1, 2, 3, 4); 69 | advance(lazyIterator, 3); 70 | Assert.assertTrue("should return true indefinitely until objects consumed", lazyIterator.hasNext()); 71 | Assert.assertTrue("should return true indefinitely until objects consumed", lazyIterator.hasNext()); 72 | 73 | List values = new ArrayList(); 74 | while (lazyIterator.hasNext()) { 75 | values.add(lazyIterator.next()); 76 | } 77 | Assert.assertEquals("[4]", values.toString()); 78 | } 79 | 80 | @Test(expected = NoSuchElementException.class) 81 | public void testNext_NoSuchElement() { 82 | LazyIterator lazyIterator = newLazyIterator(1, 2, 3, 4); 83 | advance(lazyIterator, 4); 84 | lazyIterator.next(); 85 | } 86 | 87 | @Test 88 | public void testHasNext_IllegalState() { 89 | LazyIterator lazyIterator = newFaultyLazyIterator(); 90 | try { 91 | lazyIterator.hasNext(); 92 | } 93 | catch (RuntimeException expected) { } 94 | 95 | try { 96 | lazyIterator.hasNext(); 97 | Assert.fail("should throw IllegalStateException on second call to hasNext, if previous call failed"); 98 | } 99 | catch (IllegalStateException expected) { } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/examples/filesystem/InMemoryFileSystem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.examples.filesystem; 17 | 18 | import java.util.Collection; 19 | 20 | /** 21 | * A skeleton interface for a file system, as proof of concept. 22 | * 23 | * @param The type of file-like object to store in the file system 24 | * 25 | * @author Niall Gallagher 26 | */ 27 | public interface InMemoryFileSystem { 28 | 29 | void addFile(String containingDirectory, String fileName, F file); 30 | 31 | F getFile(String containingDirectory, String fileName); 32 | 33 | Collection getFileNamesInDirectory(String containingDirectory); 34 | 35 | Collection getFilesInDirectory(String containingDirectory); 36 | 37 | Collection getFileNamesInDirectoryRecursive(String containingDirectory); 38 | 39 | Collection getFilesInDirectoryRecursive(String containingDirectory); 40 | } 41 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/examples/filesystem/InMemoryFileSystemUsage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.examples.filesystem; 17 | 18 | import com.googlecode.concurrenttrees.common.PrettyPrinter; 19 | import com.googlecode.concurrenttrees.radix.node.util.PrettyPrintable; 20 | 21 | import java.util.Collection; 22 | 23 | /** 24 | * Example usage of the {@link InMemoryFileSystem} proof of concept. 25 | *

26 | * Creates a bunch of Brochure objects, and stores those in various "directories" and with various "file names" in the 27 | * in-memory file system. Then retrieves files by searching directories recursively etc. 28 | * 29 | * @author Niall Gallagher 30 | */ 31 | public class InMemoryFileSystemUsage { 32 | 33 | static class Brochure { 34 | final String content; 35 | 36 | Brochure(String content) { 37 | this.content = content; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return content; 43 | } 44 | } 45 | 46 | public static void main(String[] args) { 47 | // A file system to store Brochure objects... 48 | InMemoryFileSystem fileSystem = new ConcurrentRadixTreeInMemoryFileSystem(); 49 | 50 | Brochure fordFocusBrochure = new Brochure("Marketing stuff for Ford Focus"); 51 | Brochure fordF150Brochure = new Brochure("Marketing stuff for Ford F150"); 52 | Brochure hondaCivicBrochure = new Brochure("Marketing stuff for Honda Civic"); 53 | 54 | fileSystem.addFile("/brochures/ford/", "ford_focus_brochure.txt", fordFocusBrochure); 55 | fileSystem.addFile("/brochures/ford/", "ford_f150_brochure.txt", fordF150Brochure); 56 | fileSystem.addFile("/brochures/honda/", "honda_civic_brochure.txt", hondaCivicBrochure); 57 | 58 | System.out.println("Internal file system representation (not public):-"); 59 | PrettyPrinter.prettyPrint((PrettyPrintable) fileSystem, System.out); 60 | 61 | System.out.println(); 62 | System.out.println("Retrieve Ford brochure names in directory: " + fileSystem.getFileNamesInDirectory("/brochures/ford/")); 63 | System.out.println("Retrieve Honda brochure names in directory: " + fileSystem.getFileNamesInDirectory("/brochures/honda/")); 64 | System.out.println("Retrieve All brochure names recursively: " + fileSystem.getFileNamesInDirectoryRecursive("/brochures/")); 65 | 66 | System.out.println(); 67 | Brochure fordF150BrochureRetrieved = fileSystem.getFile("/brochures/ford/", "ford_f150_brochure.txt"); 68 | System.out.println("Retrieve Ford F150 brochure contents using exact file name: " + fordF150BrochureRetrieved); 69 | 70 | System.out.println(); 71 | System.out.println("Retrieve all Ford brochure contents in directory:-"); 72 | Collection fordBrochuresRetrieved = fileSystem.getFilesInDirectory("/brochures/ford/"); 73 | for (Brochure fordBrochure : fordBrochuresRetrieved) { 74 | System.out.println(fordBrochure); 75 | } 76 | 77 | System.out.println(); 78 | System.out.println("Retrieve contents from entire file system recursively:-"); 79 | Collection allFiles = fileSystem.getFilesInDirectoryRecursive("/"); 80 | for (Brochure file : allFiles) { 81 | System.out.println(file); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareSinglePlaySuffixTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.examples.shakespeare; 17 | 18 | 19 | import com.googlecode.concurrenttrees.common.PrettyPrinter; 20 | import com.googlecode.concurrenttrees.examples.shakespeare.util.IOUtil; 21 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharSequenceNodeFactory; 22 | import com.googlecode.concurrenttrees.suffix.ConcurrentSuffixTree; 23 | 24 | import java.io.IOException; 25 | import java.util.Arrays; 26 | import java.util.List; 27 | 28 | /** 29 | * @author Niall Gallagher 30 | */ 31 | public class BuildShakespeareSinglePlaySuffixTree { 32 | 33 | static final List files = Arrays.asList( 34 | "/shakespeare/tragedies/antony_and_cleopatra.txt" 35 | ); 36 | 37 | public static void main(String[] args) throws Exception { 38 | ConcurrentSuffixTree tree = new ConcurrentSuffixTree(new DefaultCharSequenceNodeFactory()); 39 | for (String file : files) { 40 | String manuscript = IOUtil.loadTextFileFromClasspath(file, true, true, true); // true = convert to lowercase 41 | String manuscriptName = file.replaceAll("/.*/.*/", "").replace(".txt", ""); 42 | tree.put(manuscript, manuscriptName); 43 | System.out.println("Added " + manuscriptName); 44 | } 45 | System.out.println("Built Suffix Tree. Estimating size on disk..."); 46 | DummyAppendable dummyAppendable = new DummyAppendable(); 47 | PrettyPrinter.prettyPrint(tree, dummyAppendable); 48 | System.out.println("Done. Size on disk estimate:"); 49 | System.out.println("Lines: " + dummyAppendable.lineCount); 50 | System.out.println("Characters: " + dummyAppendable.charCount); 51 | } 52 | 53 | static class DummyAppendable implements Appendable { 54 | 55 | public long lineCount = 0; 56 | public long charCount = 0; 57 | 58 | @Override 59 | public Appendable append(CharSequence csq) throws IOException { 60 | if (csq.length() > 0 && csq.charAt(csq.length() -1) == '\n') { 61 | lineCount++; 62 | } 63 | charCount+= csq.length(); 64 | return this; 65 | } 66 | 67 | @Override 68 | public Appendable append(CharSequence csq, int start, int end) throws IOException { 69 | throw new UnsupportedOperationException("Not implemented"); 70 | } 71 | 72 | @Override 73 | public Appendable append(char c) throws IOException { 74 | throw new UnsupportedOperationException("Not implemented"); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareTragediesSuffixTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.examples.shakespeare; 17 | 18 | 19 | import com.googlecode.concurrenttrees.common.PrettyPrinter; 20 | import com.googlecode.concurrenttrees.examples.shakespeare.util.IOUtil; 21 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharSequenceNodeFactory; 22 | import com.googlecode.concurrenttrees.suffix.ConcurrentSuffixTree; 23 | 24 | import java.io.IOException; 25 | import java.util.Arrays; 26 | import java.util.List; 27 | 28 | /** 29 | * @author Niall Gallagher 30 | */ 31 | public class BuildShakespeareTragediesSuffixTree { 32 | 33 | static final List files = Arrays.asList( 34 | "/shakespeare/tragedies/antony_and_cleopatra.txt", 35 | "/shakespeare/tragedies/coriolanus.txt", 36 | "/shakespeare/tragedies/hamlet.txt", 37 | "/shakespeare/tragedies/julius_caesar.txt", 38 | "/shakespeare/tragedies/king_lear.txt", 39 | "/shakespeare/tragedies/macbeth.txt", 40 | "/shakespeare/tragedies/othello.txt", 41 | "/shakespeare/tragedies/romeo_and_juliet.txt", 42 | "/shakespeare/tragedies/timon_of_athens.txt", 43 | "/shakespeare/tragedies/titus_andronicus.txt" 44 | ); 45 | 46 | public static void main(String[] args) throws Exception { 47 | ConcurrentSuffixTree tree = new ConcurrentSuffixTree(new DefaultCharSequenceNodeFactory()); 48 | for (String file : files) { 49 | String manuscript = IOUtil.loadTextFileFromClasspath(file, true, true, true); // true = convert to lowercase 50 | String manuscriptName = file.replaceAll("/.*/.*/", "").replace(".txt", ""); 51 | tree.put(manuscript, manuscriptName); 52 | System.out.println("Added " + manuscriptName); 53 | } 54 | System.out.println("Built Suffix Tree. Estimating size on disk..."); 55 | Thread.sleep(30000); 56 | DummyAppendable dummyAppendable = new DummyAppendable(); 57 | PrettyPrinter.prettyPrint(tree, dummyAppendable); 58 | System.out.println("Done. Size on disk estimate:"); 59 | System.out.println("Lines: " + dummyAppendable.lineCount); 60 | System.out.println("Characters: " + dummyAppendable.charCount); 61 | } 62 | 63 | static class DummyAppendable implements Appendable { 64 | 65 | public long lineCount = 0; 66 | public long charCount = 0; 67 | 68 | @Override 69 | public Appendable append(CharSequence csq) throws IOException { 70 | if (csq.length() > 0 && csq.charAt(csq.length() -1) == '\n') { 71 | lineCount++; 72 | } 73 | charCount+= csq.length(); 74 | return this; 75 | } 76 | 77 | @Override 78 | public Appendable append(CharSequence csq, int start, int end) throws IOException { 79 | throw new UnsupportedOperationException("Not implemented"); 80 | } 81 | 82 | @Override 83 | public Appendable append(char c) throws IOException { 84 | throw new UnsupportedOperationException("Not implemented"); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/FindLongestCommonSubstring.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.examples.shakespeare; 17 | 18 | 19 | import com.googlecode.concurrenttrees.examples.shakespeare.util.IOUtil; 20 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharSequenceNodeFactory; 21 | import com.googlecode.concurrenttrees.solver.LCSubstringSolver; 22 | 23 | import java.util.Arrays; 24 | import java.util.List; 25 | 26 | /** 27 | * Finds the longest common substring in Shakespeare's Tragedies. 28 | * 29 | * @author Niall Gallagher 30 | */ 31 | public class FindLongestCommonSubstring { 32 | 33 | static final List files = Arrays.asList( 34 | "/shakespeare/tragedies/antony_and_cleopatra.txt", 35 | "/shakespeare/tragedies/coriolanus.txt", 36 | "/shakespeare/tragedies/hamlet.txt", 37 | "/shakespeare/tragedies/julius_caesar.txt", 38 | "/shakespeare/tragedies/king_lear.txt", 39 | "/shakespeare/tragedies/macbeth.txt", 40 | "/shakespeare/tragedies/othello.txt", 41 | "/shakespeare/tragedies/romeo_and_juliet.txt", 42 | "/shakespeare/tragedies/timon_of_athens.txt", 43 | "/shakespeare/tragedies/titus_andronicus.txt" 44 | ); 45 | 46 | // This program needs 2-3GB of RAM with the DefaultCharSequenceNodeFactory (set -Xmx accordingly). 47 | // Example output in: test/resources/shakespeare-trees/tragedies-longest-common-substring.txt 48 | public static void main(String[] args) throws Exception { 49 | LCSubstringSolver solver = new LCSubstringSolver(new DefaultCharSequenceNodeFactory()); 50 | System.out.println("Building suffix tree..."); 51 | long startTime = System.nanoTime(); 52 | for (String file : files) { 53 | // Load manuscript and strip punctuation, strip line breaks, convert to lowercase (respectively).. 54 | String manuscript = IOUtil.loadTextFileFromClasspath(file, true, true, true); 55 | String manuscriptName = file.replaceAll("/.*/.*/", "").replace(".txt", ""); 56 | solver.add(manuscript); 57 | System.out.println("Added manuscript: " + manuscriptName); 58 | } 59 | System.out.println("Built suffix tree in " + ((System.nanoTime() - startTime)/1000000000) + " seconds."); 60 | long searchTime = System.nanoTime(); 61 | System.out.println("Searching for longest common substring..."); 62 | CharSequence longestCommonSubstring = solver.getLongestCommonSubstring(); 63 | System.out.println("Found longest common substring in " 64 | + ((System.nanoTime() - searchTime)/1000000000) + " seconds."); 65 | System.out.println("Longest common substring: [" + longestCommonSubstring + "]"); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/examples/usage/InvertedRadixTreeUsage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.examples.usage; 17 | 18 | import com.googlecode.concurrenttrees.common.Iterables; 19 | import com.googlecode.concurrenttrees.common.PrettyPrinter; 20 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharArrayNodeFactory; 21 | import com.googlecode.concurrenttrees.radix.node.util.PrettyPrintable; 22 | import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree; 23 | import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree; 24 | 25 | /** 26 | * @author Niall Gallagher 27 | */ 28 | public class InvertedRadixTreeUsage { 29 | 30 | public static void main(String[] args) { 31 | InvertedRadixTree tree = new ConcurrentInvertedRadixTree(new DefaultCharArrayNodeFactory()); 32 | 33 | tree.put("TEST", 1); 34 | tree.put("TOAST", 2); 35 | tree.put("TEAM", 3); 36 | 37 | System.out.println("Tree structure:"); 38 | // PrettyPrintable is a non-public API for testing, prints semi-graphical representations of trees... 39 | PrettyPrinter.prettyPrint((PrettyPrintable) tree, System.out); 40 | 41 | System.out.println(); 42 | System.out.println("Value for 'TEST' (exact match): " + tree.getValueForExactKey("TEST")); 43 | System.out.println("Value for 'TOAST' (exact match): " + tree.getValueForExactKey("TOAST")); 44 | System.out.println(); 45 | System.out.println("Keys contained in 'MY TEAM LIKES TOAST': " + Iterables.toString(tree.getKeysContainedIn("MY TEAM LIKES TOAST"))); 46 | System.out.println("Keys contained in 'MY TEAM LIKES TOASTERS': " + Iterables.toString(tree.getKeysContainedIn("MY TEAM LIKES TOASTERS"))); 47 | System.out.println("Values for keys contained in 'MY TEAM LIKES TOAST': " + Iterables.toString(tree.getValuesForKeysContainedIn("MY TEAM LIKES TOAST"))); 48 | System.out.println("Key-value pairs for keys contained in 'MY TEAM LIKES TOAST': " + Iterables.toString(tree.getKeyValuePairsForKeysContainedIn("MY TEAM LIKES TOAST"))); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/examples/usage/IterablesUsage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.examples.usage; 17 | 18 | import com.googlecode.concurrenttrees.common.Iterables; 19 | import com.googlecode.concurrenttrees.radix.ConcurrentRadixTree; 20 | import com.googlecode.concurrenttrees.radix.RadixTree; 21 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharArrayNodeFactory; 22 | 23 | import java.util.List; 24 | import java.util.Set; 25 | 26 | /** 27 | * @author Niall Gallagher 28 | */ 29 | public class IterablesUsage { 30 | 31 | public static void main(String[] args) { 32 | RadixTree tree = new ConcurrentRadixTree(new DefaultCharArrayNodeFactory()); 33 | 34 | tree.put("TEST", 1); 35 | tree.put("TOAST", 2); 36 | tree.put("TEAM", 3); 37 | 38 | Iterable keysStartingWithT = tree.getKeysStartingWith("T"); 39 | 40 | List listOfKeysStartingWithT = Iterables.toList (keysStartingWithT); 41 | Set setOfKeysStartingWithT = Iterables.toSet (keysStartingWithT); 42 | String toStringOfKeysStartingWithT = Iterables.toString(keysStartingWithT); 43 | 44 | System.out.println("Keys starting with 'T': " + toStringOfKeysStartingWithT); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/examples/usage/LCSubstringSolverUsage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.examples.usage; 17 | 18 | import com.googlecode.concurrenttrees.common.CharSequences; 19 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharSequenceNodeFactory; 20 | import com.googlecode.concurrenttrees.solver.LCSubstringSolver; 21 | 22 | /** 23 | * @author Niall Gallagher 24 | */ 25 | public class LCSubstringSolverUsage { 26 | 27 | static final String document1 = 28 | "albert einstein, was a german theoretical physicist who developed the theory of general relativity"; 29 | 30 | static final String document2 = 31 | "near the beginning of his career, albert einstein thought that newtonian mechanics was no longer " + 32 | "enough to reconcile the laws of classical mechanics with the laws of the electromagnetic field"; 33 | 34 | static final String document3 = 35 | "in late summer 1895, at the age of sixteen, albert einstein sat the entrance examinations for " + 36 | "the swiss federal polytechnic in zurich"; 37 | 38 | public static void main(String[] args) { 39 | LCSubstringSolver solver = new LCSubstringSolver(new DefaultCharSequenceNodeFactory()); 40 | 41 | solver.add(document1); 42 | solver.add(document2); 43 | solver.add(document3); 44 | 45 | String longestCommonSubstring = CharSequences.toString(solver.getLongestCommonSubstring()); 46 | System.out.println(longestCommonSubstring); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/examples/usage/RadixTreeUsage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.examples.usage; 17 | 18 | import com.googlecode.concurrenttrees.common.Iterables; 19 | import com.googlecode.concurrenttrees.common.PrettyPrinter; 20 | import com.googlecode.concurrenttrees.radix.ConcurrentRadixTree; 21 | import com.googlecode.concurrenttrees.radix.RadixTree; 22 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharArrayNodeFactory; 23 | import com.googlecode.concurrenttrees.radix.node.util.PrettyPrintable; 24 | 25 | /** 26 | * @author Niall Gallagher 27 | */ 28 | public class RadixTreeUsage { 29 | 30 | public static void main(String[] args) { 31 | RadixTree tree = new ConcurrentRadixTree(new DefaultCharArrayNodeFactory()); 32 | 33 | tree.put("TEST", 1); 34 | tree.put("TOAST", 2); 35 | tree.put("TEAM", 3); 36 | 37 | System.out.println("Tree structure:"); 38 | // PrettyPrintable is a non-public API for testing, prints semi-graphical representations of trees... 39 | PrettyPrinter.prettyPrint((PrettyPrintable) tree, System.out); 40 | 41 | System.out.println(); 42 | System.out.println("Value for 'TEST' (exact match): " + tree.getValueForExactKey("TEST")); 43 | System.out.println("Value for 'TOAST' (exact match): " + tree.getValueForExactKey("TOAST")); 44 | System.out.println(); 45 | System.out.println("Keys starting with 'T': " + Iterables.toString(tree.getKeysStartingWith("T"))); 46 | System.out.println("Keys starting with 'TE': " + Iterables.toString(tree.getKeysStartingWith("TE"))); 47 | System.out.println(); 48 | System.out.println("Values for keys starting with 'TE': " + Iterables.toString(tree.getValuesForKeysStartingWith("TE"))); 49 | System.out.println("Key-Value pairs for keys starting with 'TE': " + Iterables.toString(tree.getKeyValuePairsForKeysStartingWith("TE"))); 50 | System.out.println(); 51 | System.out.println("Keys closest to 'TEMPLE': " + Iterables.toString(tree.getClosestKeys("TEMPLE"))); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/examples/usage/ReversedRadixTreeUsage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.examples.usage; 17 | 18 | import com.googlecode.concurrenttrees.common.Iterables; 19 | import com.googlecode.concurrenttrees.common.PrettyPrinter; 20 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharArrayNodeFactory; 21 | import com.googlecode.concurrenttrees.radix.node.util.PrettyPrintable; 22 | import com.googlecode.concurrenttrees.radixreversed.ConcurrentReversedRadixTree; 23 | import com.googlecode.concurrenttrees.radixreversed.ReversedRadixTree; 24 | 25 | /** 26 | * @author Niall Gallagher 27 | */ 28 | public class ReversedRadixTreeUsage { 29 | 30 | public static void main(String[] args) { 31 | ReversedRadixTree tree = new ConcurrentReversedRadixTree(new DefaultCharArrayNodeFactory()); 32 | 33 | tree.put("TEST", 1); 34 | tree.put("TOAST", 2); 35 | tree.put("TEAM", 3); 36 | 37 | System.out.println("Tree structure:"); 38 | // PrettyPrintable is a non-public API for testing, prints semi-graphical representations of trees... 39 | PrettyPrinter.prettyPrint((PrettyPrintable) tree, System.out); 40 | 41 | System.out.println(); 42 | System.out.println("Value for 'TEST' (exact match): " + tree.getValueForExactKey("TEST")); 43 | System.out.println("Value for 'TOAST' (exact match): " + tree.getValueForExactKey("TOAST")); 44 | System.out.println(); 45 | System.out.println("Keys ending with 'ST': " + Iterables.toString(tree.getKeysEndingWith("ST"))); 46 | System.out.println("Keys ending with 'M': " + Iterables.toString(tree.getKeysEndingWith("M"))); 47 | System.out.println(); 48 | System.out.println("Values for keys ending with 'ST': " + Iterables.toString(tree.getValuesForKeysEndingWith("ST"))); 49 | System.out.println("Key-Value pairs for keys ending with 'ST': " + Iterables.toString(tree.getKeyValuePairsForKeysEndingWith("ST"))); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/examples/usage/SuffixTreeUsage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.examples.usage; 17 | 18 | import com.googlecode.concurrenttrees.common.CharSequences; 19 | import com.googlecode.concurrenttrees.common.Iterables; 20 | import com.googlecode.concurrenttrees.common.PrettyPrinter; 21 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharArrayNodeFactory; 22 | import com.googlecode.concurrenttrees.radix.node.util.PrettyPrintable; 23 | import com.googlecode.concurrenttrees.suffix.ConcurrentSuffixTree; 24 | import com.googlecode.concurrenttrees.suffix.SuffixTree; 25 | 26 | /** 27 | * @author Niall Gallagher 28 | */ 29 | public class SuffixTreeUsage { 30 | 31 | public static void main(String[] args) { 32 | System.out.println("Suffixes for 'TEST': " + Iterables.toString(CharSequences.generateSuffixes("TEST"))); 33 | System.out.println("Suffixes for 'TOAST': " + Iterables.toString(CharSequences.generateSuffixes("TOAST"))); 34 | System.out.println("Suffixes for 'TEAM': " + Iterables.toString(CharSequences.generateSuffixes("TEAM"))); 35 | 36 | SuffixTree tree = new ConcurrentSuffixTree(new DefaultCharArrayNodeFactory()); 37 | 38 | tree.put("TEST", 1); 39 | tree.put("TOAST", 2); 40 | tree.put("TEAM", 3); 41 | 42 | System.out.println(); 43 | System.out.println("Tree structure:"); 44 | // PrettyPrintable is a non-public API for testing, prints semi-graphical representations of trees... 45 | PrettyPrinter.prettyPrint((PrettyPrintable) tree, System.out); 46 | 47 | System.out.println(); 48 | System.out.println("Value for 'TEST' (exact match): " + tree.getValueForExactKey("TEST")); 49 | System.out.println("Value for 'TOAST' (exact match): " + tree.getValueForExactKey("TOAST")); 50 | System.out.println(); 51 | System.out.println("Keys ending with 'ST': " + Iterables.toString(tree.getKeysEndingWith("ST"))); 52 | System.out.println("Keys ending with 'M': " + Iterables.toString(tree.getKeysEndingWith("M"))); 53 | System.out.println("Values for keys ending with 'ST': " + Iterables.toString(tree.getValuesForKeysEndingWith("ST"))); 54 | System.out.println("Key-Value pairs for keys ending with 'ST': " + Iterables.toString(tree.getKeyValuePairsForKeysEndingWith("ST"))); 55 | System.out.println(); 56 | System.out.println("Keys containing 'TE': " + Iterables.toString(tree.getKeysContaining("TE"))); 57 | System.out.println("Keys containing 'A': " + Iterables.toString(tree.getKeysContaining("A"))); 58 | System.out.println("Values for keys containing 'A': " + Iterables.toString(tree.getValuesForKeysContaining("A"))); 59 | System.out.println("Key-Value pairs for keys containing 'A': " + Iterables.toString(tree.getKeyValuePairsForKeysContaining("A"))); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | import java.util.Collections; 24 | 25 | import static junit.framework.Assert.assertTrue; 26 | 27 | /** 28 | * @author Niall Gallagher 29 | */ 30 | public class DefaultByteArrayNodeFactoryTest { 31 | 32 | private boolean assertions; 33 | 34 | @Before 35 | public void setUp() { 36 | assert assertions = true; 37 | } 38 | 39 | @Test(expected = AssertionError.class) 40 | public void testCreateNode_NullEdge() throws Exception { 41 | assertTrue(assertions); 42 | //noinspection NullableProblems 43 | new DefaultByteArrayNodeFactory().createNode(null, 1, SimpleNodeList.EMPTY, false); 44 | } 45 | 46 | @Test(expected = AssertionError.class) 47 | public void testCreateNode_EmptyEdgeNonRoot() throws Exception { 48 | assertTrue(assertions); 49 | //noinspection NullableProblems 50 | new DefaultByteArrayNodeFactory().createNode("", 1, SimpleNodeList.EMPTY, false); 51 | } 52 | 53 | @Test(expected = AssertionError.class) 54 | public void testCreateNode_NullEdges() throws Exception { 55 | assertTrue(assertions); 56 | //noinspection NullableProblems 57 | new DefaultByteArrayNodeFactory().createNode("FOO", 1, null, false); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | import java.util.Collections; 24 | 25 | import static junit.framework.Assert.assertTrue; 26 | 27 | /** 28 | * @author Niall Gallagher 29 | */ 30 | public class DefaultCharArrayNodeFactoryTest { 31 | 32 | private boolean assertions; 33 | 34 | @Before 35 | public void setUp() { 36 | assert assertions = true; 37 | } 38 | 39 | @Test(expected = AssertionError.class) 40 | public void testCreateNode_NullEdge() throws Exception { 41 | assertTrue(assertions); 42 | //noinspection NullableProblems 43 | new DefaultCharArrayNodeFactory().createNode(null, 1, SimpleNodeList.EMPTY, false); 44 | } 45 | 46 | @Test(expected = AssertionError.class) 47 | public void testCreateNode_EmptyEdgeNonRoot() throws Exception { 48 | assertTrue(assertions); 49 | //noinspection NullableProblems 50 | new DefaultCharArrayNodeFactory().createNode("", 1, SimpleNodeList.EMPTY, false); 51 | } 52 | 53 | @Test(expected = AssertionError.class) 54 | public void testCreateNode_NullEdges() throws Exception { 55 | assertTrue(assertions); 56 | //noinspection NullableProblems 57 | new DefaultCharArrayNodeFactory().createNode("FOO", 1, null, false); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | import java.util.Collections; 24 | 25 | import static junit.framework.Assert.assertTrue; 26 | 27 | /** 28 | * @author Niall Gallagher 29 | */ 30 | public class DefaultCharSequenceNodeFactoryTest { 31 | 32 | private boolean assertions; 33 | 34 | @Before 35 | public void setUp() { 36 | assert assertions = true; 37 | } 38 | 39 | @Test(expected = AssertionError.class) 40 | public void testCreateNode_NullEdge() throws Exception { 41 | assertTrue(assertions); 42 | //noinspection NullableProblems 43 | new DefaultCharSequenceNodeFactory().createNode(null, 1, SimpleNodeList.EMPTY, false); 44 | } 45 | 46 | @Test(expected = AssertionError.class) 47 | public void testCreateNode_EmptyEdgeNonRoot() throws Exception { 48 | assertTrue(assertions); 49 | //noinspection NullableProblems 50 | new DefaultCharSequenceNodeFactory().createNode("", 1, SimpleNodeList.EMPTY, false); 51 | } 52 | 53 | @Test(expected = AssertionError.class) 54 | public void testCreateNode_NullEdges() throws Exception { 55 | assertTrue(assertions); 56 | //noinspection NullableProblems 57 | new DefaultCharSequenceNodeFactory().createNode("FOO", 1, null, false); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import com.googlecode.concurrenttrees.radix.node.concrete.bytearray.ByteArrayNodeLeafVoidValue; 21 | import com.googlecode.concurrenttrees.radix.node.concrete.chararray.CharArrayNodeLeafVoidValue; 22 | import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; 23 | import org.junit.Assert; 24 | import org.junit.Test; 25 | 26 | /** 27 | * @author Niall Gallagher 28 | */ 29 | public class SmartArrayBasedNodeFactoryTest { 30 | 31 | final SmartArrayBasedNodeFactory smartNodeFactory = new SmartArrayBasedNodeFactory(); 32 | 33 | @Test 34 | public void testCreateNode_CompatibleCharacters() throws Exception { 35 | Node node = smartNodeFactory.createNode("FOOBAR", VoidValue.SINGLETON, SimpleNodeList.EMPTY, false); 36 | Assert.assertEquals(ByteArrayNodeLeafVoidValue.class, node.getClass()); 37 | } 38 | 39 | @Test 40 | public void testCreateNode_IncompatibleCharacters() throws Exception { 41 | Node node = smartNodeFactory.createNode("FOOBAR○", VoidValue.SINGLETON, SimpleNodeList.EMPTY, false); 42 | Assert.assertEquals(CharArrayNodeLeafVoidValue.class, node.getClass()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefaultTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Test; 21 | 22 | /** 23 | * @author Niall Gallagher 24 | */ 25 | public class ByteArrayNodeDefaultTest { 26 | 27 | @Test(expected = IllegalStateException.class) 28 | public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { 29 | Node node = new ByteArrayNodeDefault("FOO", null, SimpleNodeList.EMPTY); 30 | node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR", null, SimpleNodeList.EMPTY)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class ByteArrayNodeLeafNullValueTest { 27 | 28 | @Test(expected = IllegalStateException.class) 29 | public void testUpdateOutgoingEdge() throws Exception { 30 | Node node = new ByteArrayNodeLeafNullValue("FOO"); 31 | node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR", null, SimpleNodeList.EMPTY)); 32 | } 33 | 34 | @Test 35 | public void testToString() throws Exception { 36 | Node node = new ByteArrayNodeLeafNullValue("FOO"); 37 | Assert.assertEquals("Node{edge=FOO, value=null, edges=[]}", node.toString()); 38 | } 39 | 40 | @Test 41 | public void testGetIncomingEdgeFirstCharacter() throws Exception { 42 | Node node = new ByteArrayNodeLeafNullValue("FOO"); 43 | Assert.assertEquals('F', node.getIncomingEdgeFirstCharacter()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class ByteArrayNodeLeafVoidValueTest { 27 | 28 | @Test(expected = IllegalStateException.class) 29 | public void testUpdateOutgoingEdge() throws Exception { 30 | Node node = new ByteArrayNodeLeafVoidValue("FOO"); 31 | node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR", null, SimpleNodeList.EMPTY)); 32 | } 33 | 34 | @Test 35 | public void testToString() throws Exception { 36 | Node node = new ByteArrayNodeLeafVoidValue("FOO"); 37 | Assert.assertEquals("Node{edge=FOO, value=-, edges=[]}", node.toString()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class ByteArrayNodeLeafWithValueTest { 27 | 28 | @Test(expected = IllegalStateException.class) 29 | public void testUpdateOutgoingEdge() throws Exception { 30 | Node node = new ByteArrayNodeLeafWithValue("FOO", 1); 31 | node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR", null, SimpleNodeList.EMPTY)); 32 | } 33 | 34 | @Test 35 | public void testToString() throws Exception { 36 | Node node = new ByteArrayNodeLeafWithValue("FOO", 1); 37 | Assert.assertEquals("Node{edge=FOO, value=1, edges=[]}", node.toString()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class ByteArrayNodeNonLeafNullValueTest { 27 | 28 | @Test 29 | public void testUpdateOutgoingEdge() throws Exception { 30 | Node node = new ByteArrayNodeNonLeafNullValue("FOO", new SimpleNodeList(new ByteArrayNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); 31 | node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR2", null, SimpleNodeList.EMPTY)); 32 | } 33 | 34 | @Test(expected = IllegalStateException.class) 35 | public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { 36 | Node node = new ByteArrayNodeNonLeafNullValue("FOO", new SimpleNodeList(new ByteArrayNodeDefault("BAR", 1, SimpleNodeList.EMPTY))); 37 | node.updateOutgoingEdge(new ByteArrayNodeDefault("CAR", null, SimpleNodeList.EMPTY)); 38 | } 39 | 40 | @Test 41 | public void testToString() throws Exception { 42 | Node node = new ByteArrayNodeNonLeafNullValue("FOO", SimpleNodeList.EMPTY); 43 | Assert.assertEquals("Node{edge=FOO, value=null, edges=[]}", node.toString()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class ByteArrayNodeNonLeafVoidValueTest { 27 | 28 | @Test 29 | public void testUpdateOutgoingEdge() throws Exception { 30 | Node node = new ByteArrayNodeNonLeafVoidValue("FOO", new SimpleNodeList(new ByteArrayNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); 31 | node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR2", null, SimpleNodeList.EMPTY)); 32 | } 33 | 34 | @Test(expected = IllegalStateException.class) 35 | public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { 36 | Node node = new ByteArrayNodeNonLeafVoidValue("FOO", new SimpleNodeList(new ByteArrayNodeDefault("BAR", 1, SimpleNodeList.EMPTY))); 37 | node.updateOutgoingEdge(new ByteArrayNodeDefault("CAR", null, SimpleNodeList.EMPTY)); 38 | } 39 | 40 | @Test 41 | public void testToString() throws Exception { 42 | Node node = new ByteArrayNodeNonLeafVoidValue("FOO", SimpleNodeList.EMPTY); 43 | Assert.assertEquals("Node{edge=FOO, value=-, edges=[]}", node.toString()); 44 | } 45 | 46 | @Test 47 | public void testGetOutgoingEdge() throws Exception { 48 | Node node = new ByteArrayNodeNonLeafVoidValue("FOO", new SimpleNodeList(new ByteArrayNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); 49 | Assert.assertNotNull(node.getOutgoingEdge('B')); 50 | Assert.assertEquals(1, node.getOutgoingEdge('B').getValue()); 51 | } 52 | 53 | @Test 54 | public void testGetOutgoingEdge_NonExistent() throws Exception { 55 | Node node = new ByteArrayNodeNonLeafVoidValue("FOO", new SimpleNodeList(new ByteArrayNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); 56 | Assert.assertNull(node.getOutgoingEdge('C')); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_InvertedRadixTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.bytearray.functional; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.NodeFactory; 19 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory; 20 | import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTreeTest; 21 | 22 | /** 23 | * @author Niall Gallagher 24 | */ 25 | public class ByteArrayNodeFactory_InvertedRadixTreeTest extends ConcurrentInvertedRadixTreeTest { 26 | 27 | private final NodeFactory nodeFactory = new DefaultByteArrayNodeFactory(); 28 | @Override 29 | protected NodeFactory getNodeFactory() { 30 | return nodeFactory; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_RadixTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.bytearray.functional; 17 | 18 | import com.googlecode.concurrenttrees.radix.ConcurrentRadixTreeTest; 19 | import com.googlecode.concurrenttrees.radix.node.NodeFactory; 20 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory; 21 | 22 | /** 23 | * @author Niall Gallagher 24 | */ 25 | public class ByteArrayNodeFactory_RadixTreeTest extends ConcurrentRadixTreeTest { 26 | 27 | private final NodeFactory nodeFactory = new DefaultByteArrayNodeFactory(); 28 | @Override 29 | protected NodeFactory getNodeFactory() { 30 | return nodeFactory; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_ReversedRadixTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.bytearray.functional; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.NodeFactory; 19 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory; 20 | import com.googlecode.concurrenttrees.radixreversed.ConcurrentReversedRadixTreeTest; 21 | 22 | /** 23 | * @author Niall Gallagher 24 | */ 25 | public class ByteArrayNodeFactory_ReversedRadixTreeTest extends ConcurrentReversedRadixTreeTest { 26 | 27 | private final NodeFactory nodeFactory = new DefaultByteArrayNodeFactory(); 28 | @Override 29 | protected NodeFactory getNodeFactory() { 30 | return nodeFactory; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_SuffixTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.bytearray.functional; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.NodeFactory; 19 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory; 20 | import com.googlecode.concurrenttrees.suffix.ConcurrentSuffixTreeTest; 21 | 22 | /** 23 | * @author Niall Gallagher 24 | */ 25 | public class ByteArrayNodeFactory_SuffixTreeTest extends ConcurrentSuffixTreeTest { 26 | 27 | private final NodeFactory nodeFactory = new DefaultByteArrayNodeFactory(); 28 | @Override 29 | protected NodeFactory getNodeFactory() { 30 | return nodeFactory; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefaultTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.chararray; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Test; 21 | 22 | /** 23 | * @author Niall Gallagher 24 | */ 25 | public class CharArrayNodeDefaultTest { 26 | 27 | @Test(expected = IllegalStateException.class) 28 | public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { 29 | Node node = new CharArrayNodeDefault("FOO", null, SimpleNodeList.EMPTY); 30 | node.updateOutgoingEdge(new CharArrayNodeDefault("BAR", null, SimpleNodeList.EMPTY)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.chararray; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class CharArrayNodeLeafNullValueTest { 27 | 28 | @Test(expected = IllegalStateException.class) 29 | public void testUpdateOutgoingEdge() throws Exception { 30 | Node node = new CharArrayNodeLeafNullValue("FOO"); 31 | node.updateOutgoingEdge(new CharArrayNodeDefault("BAR", null, SimpleNodeList.EMPTY)); 32 | } 33 | 34 | @Test 35 | public void testToString() throws Exception { 36 | Node node = new CharArrayNodeLeafNullValue("FOO"); 37 | Assert.assertEquals("Node{edge=FOO, value=null, edges=[]}", node.toString()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.chararray; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class CharArrayNodeLeafVoidValueTest { 27 | 28 | @Test(expected = IllegalStateException.class) 29 | public void testUpdateOutgoingEdge() throws Exception { 30 | Node node = new CharArrayNodeLeafVoidValue("FOO"); 31 | node.updateOutgoingEdge(new CharArrayNodeDefault("BAR", null, SimpleNodeList.EMPTY)); 32 | } 33 | 34 | @Test 35 | public void testToString() throws Exception { 36 | Node node = new CharArrayNodeLeafVoidValue("FOO"); 37 | Assert.assertEquals("Node{edge=FOO, value=-, edges=[]}", node.toString()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.chararray; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class CharArrayNodeLeafWithValueTest { 27 | 28 | @Test(expected = IllegalStateException.class) 29 | public void testUpdateOutgoingEdge() throws Exception { 30 | Node node = new CharArrayNodeLeafWithValue("FOO", 1); 31 | node.updateOutgoingEdge(new CharArrayNodeDefault("BAR", null, SimpleNodeList.EMPTY)); 32 | } 33 | 34 | @Test 35 | public void testToString() throws Exception { 36 | Node node = new CharArrayNodeLeafWithValue("FOO", 1); 37 | Assert.assertEquals("Node{edge=FOO, value=1, edges=[]}", node.toString()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.chararray; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class CharArrayNodeNonLeafNullValueTest { 27 | 28 | @Test 29 | public void testUpdateOutgoingEdge() throws Exception { 30 | Node node = new CharArrayNodeNonLeafNullValue("FOO", new SimpleNodeList(new CharArrayNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); 31 | node.updateOutgoingEdge(new CharArrayNodeDefault("BAR2", null, SimpleNodeList.EMPTY)); 32 | } 33 | 34 | @Test(expected = IllegalStateException.class) 35 | public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { 36 | Node node = new CharArrayNodeNonLeafNullValue("FOO", new SimpleNodeList(new CharArrayNodeDefault("BAR", 1, SimpleNodeList.EMPTY))); 37 | node.updateOutgoingEdge(new CharArrayNodeDefault("CAR", null, SimpleNodeList.EMPTY)); 38 | } 39 | 40 | @Test 41 | public void testToString() throws Exception { 42 | Node node = new CharArrayNodeNonLeafNullValue("FOO", SimpleNodeList.EMPTY); 43 | Assert.assertEquals("Node{edge=FOO, value=null, edges=[]}", node.toString()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.chararray; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class CharArrayNodeNonLeafVoidValueTest { 27 | 28 | @Test 29 | public void testUpdateOutgoingEdge() throws Exception { 30 | Node node = new CharArrayNodeNonLeafVoidValue("FOO", new SimpleNodeList(new CharArrayNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); 31 | node.updateOutgoingEdge(new CharArrayNodeDefault("BAR2", null, SimpleNodeList.EMPTY)); 32 | } 33 | 34 | @Test(expected = IllegalStateException.class) 35 | public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { 36 | Node node = new CharArrayNodeNonLeafVoidValue("FOO", new SimpleNodeList(new CharArrayNodeDefault("BAR", 1, SimpleNodeList.EMPTY))); 37 | node.updateOutgoingEdge(new CharArrayNodeDefault("CAR", null, SimpleNodeList.EMPTY)); 38 | } 39 | 40 | @Test 41 | public void testToString() throws Exception { 42 | Node node = new CharArrayNodeNonLeafVoidValue("FOO", SimpleNodeList.EMPTY); 43 | Assert.assertEquals("Node{edge=FOO, value=-, edges=[]}", node.toString()); 44 | } 45 | 46 | @Test 47 | public void testGetOutgoingEdge() throws Exception { 48 | Node node = new CharArrayNodeNonLeafVoidValue("FOO", new SimpleNodeList(new CharArrayNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); 49 | Assert.assertNotNull(node.getOutgoingEdge('B')); 50 | Assert.assertEquals(1, node.getOutgoingEdge('B').getValue()); 51 | } 52 | 53 | @Test 54 | public void testGetOutgoingEdge_NonExistent() throws Exception { 55 | Node node = new CharArrayNodeNonLeafVoidValue("FOO", new SimpleNodeList(new CharArrayNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); 56 | Assert.assertNull(node.getOutgoingEdge('C')); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class CharSequenceNodeLeafNullValueTest { 27 | 28 | @Test(expected = IllegalStateException.class) 29 | public void testUpdateOutgoingEdge() throws Exception { 30 | Node node = new CharSequenceNodeLeafNullValue("FOO"); 31 | node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR", null, SimpleNodeList.EMPTY)); 32 | } 33 | 34 | @Test 35 | public void testToString() throws Exception { 36 | Node node = new CharSequenceNodeLeafNullValue("FOO"); 37 | Assert.assertEquals("Node{edge=FOO, value=null, edges=[]}", node.toString()); 38 | } 39 | 40 | @Test 41 | public void testGetIncomingEdgeFirstCharacter() { 42 | Node node = new CharSequenceNodeLeafNullValue("FOO"); 43 | Assert.assertEquals('F', node.getIncomingEdgeFirstCharacter()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class CharSequenceNodeLeafVoidValueTest { 27 | 28 | @Test(expected = IllegalStateException.class) 29 | public void testUpdateOutgoingEdge() throws Exception { 30 | Node node = new CharSequenceNodeLeafVoidValue("FOO"); 31 | node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR", null, SimpleNodeList.EMPTY)); 32 | } 33 | 34 | @Test 35 | public void testToString() throws Exception { 36 | Node node = new CharSequenceNodeLeafVoidValue("FOO"); 37 | Assert.assertEquals("Node{edge=FOO, value=-, edges=[]}", node.toString()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class CharSequenceNodeLeafWithValueTest { 27 | 28 | @Test(expected = IllegalStateException.class) 29 | public void testUpdateOutgoingEdge() throws Exception { 30 | Node node = new CharSequenceNodeLeafWithValue("FOO", 1); 31 | node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR", null, SimpleNodeList.EMPTY)); 32 | } 33 | 34 | @Test 35 | public void testToString() throws Exception { 36 | Node node = new CharSequenceNodeLeafWithValue("FOO", 1); 37 | Assert.assertEquals("Node{edge=FOO, value=1, edges=[]}", node.toString()); 38 | } 39 | 40 | @Test 41 | public void testGetOutgoingEdge() { 42 | Node node = new CharSequenceNodeLeafWithValue("FOO", 1); 43 | Assert.assertNull(node.getOutgoingEdge('A')); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class CharSequenceNodeNonLeafNullValueTest { 27 | 28 | @Test 29 | public void testUpdateOutgoingEdge() throws Exception { 30 | Node node = new CharSequenceNodeNonLeafNullValue("FOO", new SimpleNodeList(new CharSequenceNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); 31 | node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR2", null, SimpleNodeList.EMPTY)); 32 | } 33 | 34 | @Test(expected = IllegalStateException.class) 35 | public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { 36 | Node node = new CharSequenceNodeNonLeafNullValue("FOO", new SimpleNodeList(new CharSequenceNodeDefault("BAR", 1, SimpleNodeList.EMPTY))); 37 | node.updateOutgoingEdge(new CharSequenceNodeDefault("CAR", null, SimpleNodeList.EMPTY)); 38 | } 39 | 40 | @Test 41 | public void testToString() throws Exception { 42 | Node node = new CharSequenceNodeNonLeafNullValue("FOO", SimpleNodeList.EMPTY); 43 | Assert.assertEquals("Node{edge=FOO, value=null, edges=[]}", node.toString()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class CharSequenceNodeNonLeafVoidValueTest { 27 | 28 | @Test 29 | public void testUpdateOutgoingEdge() throws Exception { 30 | Node node = new CharSequenceNodeNonLeafVoidValue("FOO", new SimpleNodeList(new CharSequenceNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); 31 | node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR2", null, SimpleNodeList.EMPTY)); 32 | } 33 | 34 | @Test(expected = IllegalStateException.class) 35 | public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { 36 | Node node = new CharSequenceNodeNonLeafVoidValue("FOO", new SimpleNodeList(new CharSequenceNodeDefault("BAR", 1, SimpleNodeList.EMPTY))); 37 | node.updateOutgoingEdge(new CharSequenceNodeDefault("CAR", null, SimpleNodeList.EMPTY)); 38 | } 39 | 40 | @Test 41 | public void testToString() throws Exception { 42 | Node node = new CharSequenceNodeNonLeafVoidValue("FOO", SimpleNodeList.EMPTY); 43 | Assert.assertEquals("Node{edge=FOO, value=-, edges=[]}", node.toString()); 44 | } 45 | 46 | @Test 47 | public void testGetOutgoingEdge() throws Exception { 48 | Node node = new CharSequenceNodeNonLeafVoidValue("FOO", new SimpleNodeList(new CharSequenceNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); 49 | Assert.assertNotNull(node.getOutgoingEdge('B')); 50 | Assert.assertEquals(1, node.getOutgoingEdge('B').getValue()); 51 | } 52 | 53 | @Test 54 | public void testGetOutgoingEdge_NonExistent() throws Exception { 55 | Node node = new CharSequenceNodeNonLeafVoidValue("FOO", new SimpleNodeList(new CharSequenceNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); 56 | Assert.assertNull(node.getOutgoingEdge('C')); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/DefaultCharSequenceNodeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Niall Gallagher 25 | */ 26 | public class DefaultCharSequenceNodeTest { 27 | 28 | @Test 29 | public void testToString() throws Exception { 30 | Node node = new CharSequenceNodeDefault("FOO", null, SimpleNodeList.EMPTY); 31 | Assert.assertEquals("Node{edge=FOO, value=null, edges=[]}", node.toString()); 32 | 33 | } 34 | 35 | @Test(expected = IllegalStateException.class) 36 | public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { 37 | Node node = new CharSequenceNodeDefault("FOO", null, SimpleNodeList.EMPTY); 38 | node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR", null, SimpleNodeList.EMPTY)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/voidvalue/VoidValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.concrete.voidvalue; 17 | 18 | import org.junit.Assert; 19 | import org.junit.Test; 20 | 21 | /** 22 | * @author Niall Gallagher 23 | */ 24 | public class VoidValueTest { 25 | 26 | @Test 27 | public void testHashCode() throws Exception { 28 | Assert.assertEquals(1, new VoidValue().hashCode()); 29 | } 30 | 31 | @Test 32 | public void testEquals() throws Exception { 33 | Assert.assertTrue(new VoidValue().equals(new VoidValue())); 34 | Assert.assertFalse(new VoidValue().equals(new Object())); 35 | //noinspection NullableProblems,ObjectEqualsNull 36 | Assert.assertFalse(new VoidValue().equals(null)); 37 | } 38 | 39 | @Test 40 | public void testToString() throws Exception { 41 | Assert.assertEquals("-", new VoidValue().toString()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.radix.node.util; 17 | 18 | import com.googlecode.concurrenttrees.radix.node.Node; 19 | import com.googlecode.concurrenttrees.radix.node.NodeFactory; 20 | import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; 21 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharArrayNodeFactory; 22 | import org.junit.Assert; 23 | import org.junit.Test; 24 | 25 | import java.util.Arrays; 26 | import java.util.Collections; 27 | import java.util.List; 28 | import java.util.concurrent.atomic.AtomicReferenceArray; 29 | 30 | import static junit.framework.Assert.assertFalse; 31 | 32 | /** 33 | * @author Niall Gallagher 34 | */ 35 | public class NodeUtilTest { 36 | 37 | @Test 38 | @SuppressWarnings({"NullableProblems"}) 39 | public void testBinarySearchForEdge() throws Exception { 40 | NodeFactory nodeFactory = new DefaultCharArrayNodeFactory(); 41 | Node[] nodes = new Node[] { 42 | nodeFactory.createNode("A", null, SimpleNodeList.EMPTY, false), 43 | nodeFactory.createNode("B", null, SimpleNodeList.EMPTY, false), 44 | nodeFactory.createNode("C", null, SimpleNodeList.EMPTY, false) 45 | }; 46 | AtomicReferenceArray atomicReferenceArray = new AtomicReferenceArray(nodes); 47 | Assert.assertEquals(0, NodeUtil.binarySearchForEdge(atomicReferenceArray, 'A')); 48 | Assert.assertEquals(1, NodeUtil.binarySearchForEdge(atomicReferenceArray, 'B')); 49 | Assert.assertEquals(2, NodeUtil.binarySearchForEdge(atomicReferenceArray, 'C')); 50 | Assert.assertTrue(NodeUtil.binarySearchForEdge(atomicReferenceArray, 'D') < 0); 51 | } 52 | 53 | @Test 54 | @SuppressWarnings({"NullableProblems"}) 55 | public void testEnsureNoDuplicateEdges_Positive() throws Exception { 56 | NodeFactory nodeFactory = new DefaultCharArrayNodeFactory(); 57 | List nodes = Arrays.asList( 58 | nodeFactory.createNode("A", null, SimpleNodeList.EMPTY, false), 59 | nodeFactory.createNode("B", null, SimpleNodeList.EMPTY, false), 60 | nodeFactory.createNode("C", null, SimpleNodeList.EMPTY, false) 61 | ); 62 | } 63 | 64 | @Test 65 | @SuppressWarnings({"NullableProblems"}) 66 | public void testEnsureNoDuplicateEdges_Negative() throws Exception { 67 | NodeFactory nodeFactory = new DefaultCharArrayNodeFactory(); 68 | SimpleNodeList nodes = new SimpleNodeList( 69 | nodeFactory.createNode("A", null, SimpleNodeList.EMPTY, false), 70 | nodeFactory.createNode("B", null, SimpleNodeList.EMPTY, false), 71 | nodeFactory.createNode("B", null, SimpleNodeList.EMPTY, false), 72 | nodeFactory.createNode("C", null, SimpleNodeList.EMPTY, false) 73 | ); 74 | assertFalse(NodeUtil.hasNoDuplicateEdges(nodes)); 75 | } 76 | 77 | @Test 78 | public void testConstructor() { 79 | Assert.assertNotNull(new NodeUtil()); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/solver/LCSubstringSolverTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.solver; 17 | 18 | import com.googlecode.concurrenttrees.common.PrettyPrinter; 19 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharSequenceNodeFactory; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | import static org.junit.Assert.*; 24 | 25 | /** 26 | * @author Niall Gallagher 27 | */ 28 | public class LCSubstringSolverTest { 29 | 30 | final String document1 = 31 | "albert einstein, was a german theoretical physicist who developed the theory of general relativity"; 32 | 33 | final String document2 = 34 | "near the beginning of his career, albert einstein thought that newtonian mechanics was no longer " + 35 | "enough to reconcile the laws of classical mechanics with the laws of the electromagnetic field"; 36 | 37 | final String document3 = 38 | "in late summer 1895, at the age of sixteen, albert einstein sat the entrance examinations for " + 39 | "the swiss federal polytechnic in zurich"; 40 | 41 | 42 | @Test 43 | public void testGetLongestCommonSubstring() throws Exception { 44 | LCSubstringSolver solver = new LCSubstringSolver(new DefaultCharSequenceNodeFactory()); 45 | 46 | solver.add(document1); 47 | solver.add(document2); 48 | solver.add(document3); 49 | 50 | String longestCommonSubstring = solver.getLongestCommonSubstring().toString(); 51 | 52 | assertEquals("albert einstein", longestCommonSubstring); 53 | } 54 | 55 | @Test 56 | public void testAddSuffixesToRadixTree_DuplicateHandling() { 57 | LCSubstringSolver solver = new LCSubstringSolver(new DefaultCharSequenceNodeFactory()); 58 | solver.addSuffixesToRadixTree("FOO"); 59 | // This would not really happen since add method prevents duplicates. Simulate adding duplicate to tree... 60 | // Would update existing document references instead of creating new... 61 | solver.addSuffixesToRadixTree("FOO"); 62 | String expected = 63 | "○\n" + 64 | "├── ○ FOO ([FOO])\n" + 65 | "└── ○ O ([FOO])\n" + 66 | " └── ○ O ([FOO])\n"; 67 | Assert.assertEquals(expected, PrettyPrinter.prettyPrint(solver.suffixTree)); 68 | } 69 | 70 | @Test 71 | public void testAdd_Duplicate() { 72 | LCSubstringSolver solver = new LCSubstringSolver(new DefaultCharSequenceNodeFactory()); 73 | Assert.assertTrue(solver.add("FOO")); 74 | Assert.assertFalse(solver.add("FOO")); 75 | } 76 | 77 | @Test(expected = IllegalArgumentException.class) 78 | public void testAdd_ArgumentValidation1() { 79 | LCSubstringSolver solver = new LCSubstringSolver(new DefaultCharSequenceNodeFactory()); 80 | solver.add(""); 81 | } 82 | 83 | @Test(expected = IllegalArgumentException.class) 84 | public void testAdd_ArgumentValidation2() { 85 | LCSubstringSolver solver = new LCSubstringSolver(new DefaultCharSequenceNodeFactory()); 86 | //noinspection NullableProblems 87 | solver.add(null); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /code/src/test/java/com/googlecode/concurrenttrees/testutil/TestUtility.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Niall Gallagher 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.googlecode.concurrenttrees.testutil; 17 | 18 | import java.io.ByteArrayInputStream; 19 | import java.io.ByteArrayOutputStream; 20 | import java.io.ObjectInputStream; 21 | import java.io.ObjectOutputStream; 22 | 23 | /** 24 | * Helper methods used by unit tests only. 25 | * 26 | * @author niall.gallagher 27 | */ 28 | public class TestUtility { 29 | 30 | public static byte[] serialize(Object object) { 31 | try { 32 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 33 | ObjectOutputStream out = new ObjectOutputStream(baos); 34 | out.writeObject(object); 35 | out.flush(); 36 | return baos.toByteArray(); 37 | } 38 | catch (Exception e) { 39 | throw new IllegalStateException(e); 40 | } 41 | } 42 | 43 | @SuppressWarnings("unchecked") 44 | public static T deserialize(Class expectedType, byte[] data) { 45 | try { 46 | ObjectInputStream out = new ObjectInputStream(new ByteArrayInputStream(data)); 47 | Object o = out.readObject(); 48 | out.close(); 49 | if (!(expectedType.isAssignableFrom(o.getClass()))) { 50 | throw new IllegalStateException("Unexpected type: " + o.getClass()); 51 | } 52 | return (T) o; 53 | } 54 | catch (Exception e) { 55 | throw new IllegalStateException(e); 56 | } 57 | } 58 | 59 | /** 60 | * Constructor, not used. 61 | */ 62 | TestUtility() { 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /code/src/test/resources/shakespeare-trees/tragedies-longest-common-substring.txt: -------------------------------------------------------------------------------- 1 | # Output from: src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/FindLongestCommonSubstring.java 2 | 3 | Building suffix tree... 4 | Added manuscript: antony_and_cleopatra 5 | Added manuscript: coriolanus 6 | Added manuscript: hamlet 7 | Added manuscript: julius_caesar 8 | Added manuscript: king_lear 9 | Added manuscript: macbeth 10 | Added manuscript: othello 11 | Added manuscript: romeo_and_juliet 12 | Added manuscript: timon_of_athens 13 | Added manuscript: titus_andronicus 14 | Built suffix tree in 24 seconds. 15 | Searching for longest common substring... 16 | Found longest common substring in 148 seconds. 17 | Longest common substring: [ dramatis personae ] 18 | -------------------------------------------------------------------------------- /code/src/test/resources/travis-ci-validation.txt: -------------------------------------------------------------------------------- 1 | Dummy file to validate Travis CI integration. -------------------------------------------------------------------------------- /documentation/ConcurrentInvertedRadixTreeUsage.md: -------------------------------------------------------------------------------- 1 | # Example Usage for ConcurrentInvertedRadixTree # 2 | 3 | 4 | ## General Usage ## 5 | * Create a concurrent inverted radix tree 6 | * Insert **_keywords_** "TEST", "TOAST", "TEAM", associate with integer values 1, 2, 3 7 | * Graphically print the structure of the tree 8 | * Find values for keywords exactly matching "TEST", "TOAST" 9 | * Find keywords **_contained in example document_** "MY TEAM LIKES TOAST" 10 | * Find keywords contained in example document "MY TEAM LIKES TOASTERS" 11 | * Find values for keywords contained in example document "MY TEAM LIKES TOAST" 12 | * Find keyword-value pairs for keywords contained in example document "MY TEAM LIKES TOAST" 13 | 14 | ### Code ### 15 | ```java 16 | public static void main(String[] args) { 17 | InvertedRadixTree tree = new ConcurrentInvertedRadixTree(new DefaultCharArrayNodeFactory()); 18 | 19 | tree.put("TEST", 1); 20 | tree.put("TOAST", 2); 21 | tree.put("TEAM", 3); 22 | 23 | System.out.println("Tree structure:"); 24 | // PrettyPrintable is a non-public API for testing, prints semi-graphical representations of trees... 25 | PrettyPrinter.prettyPrint((PrettyPrintable) tree, System.out); 26 | 27 | System.out.println(); 28 | System.out.println("Value for 'TEST' (exact match): " + tree.getValueForExactKey("TEST")); 29 | System.out.println("Value for 'TOAST' (exact match): " + tree.getValueForExactKey("TOAST")); 30 | System.out.println(); 31 | System.out.println("Keys contained in 'MY TEAM LIKES TOAST': " + Iterables.toString(tree.getKeysContainedIn("MY TEAM LIKES TOAST"))); 32 | System.out.println("Keys contained in 'MY TEAM LIKES TOASTERS': " + Iterables.toString(tree.getKeysContainedIn("MY TEAM LIKES TOASTERS"))); 33 | System.out.println("Values for keys contained in 'MY TEAM LIKES TOAST': " + Iterables.toString(tree.getValuesForKeysContainedIn("MY TEAM LIKES TOAST"))); 34 | System.out.println("Key-value pairs for keys contained in 'MY TEAM LIKES TOAST': " + Iterables.toString(tree.getKeyValuePairsForKeysContainedIn("MY TEAM LIKES TOAST"))); 35 | } 36 | ``` 37 | 38 | ### Output ### 39 | ``` 40 | Tree structure: 41 | ○ 42 | └── ○ T 43 | ├── ○ E 44 | │ ├── ○ AM (3) 45 | │ └── ○ ST (1) 46 | └── ○ OAST (2) 47 | 48 | Value for 'TEST' (exact match): 1 49 | Value for 'TOAST' (exact match): 2 50 | 51 | Keys contained in 'MY TEAM LIKES TOAST': [TEAM, TOAST] 52 | Keys contained in 'MY TEAM LIKES TOASTERS': [TEAM, TOAST] 53 | Values for keys contained in 'MY TEAM LIKES TOAST': [3, 2] 54 | Key-value pairs for keys contained in 'MY TEAM LIKES TOAST': [(TEAM, 3), (TOAST, 2)] 55 | ``` 56 | 57 | ## Adding Keys without Values ## 58 | ```java 59 | tree.put("FOO", VoidValue.SINGLETON); 60 | ``` 61 | Supplying [VoidValue](http://htmlpreview.github.io/?http://raw.githubusercontent.com/npgall/concurrent-trees/master/documentation/javadoc/apidocs/com/googlecode/concurrenttrees/radix/node/concrete/voidvalue/VoidValue.html) as above, stores the key in the tree without associating it with any value. 62 | 63 | Internally, a special type of node will be used which omits a field for storing a value entirely, which can reduce memory usage when values are not needed and there will be a lot of such nodes. 64 | 65 | For more details see [NodeFactoryAndMemoryUsage](NodeFactoryAndMemoryUsage.md). -------------------------------------------------------------------------------- /documentation/ConcurrentRadixTreeUsage.md: -------------------------------------------------------------------------------- 1 | # Example Usage for ConcurrentRadixTree # 2 | 3 | 4 | ## General Usage ## 5 | * Create a concurrent radix tree 6 | * Insert keys "TEST", "TOAST", "TEAM", associate with integer values 1, 2, 3 7 | * Graphically print the structure of the tree 8 | * Find values for keys exactly matching "TEST", "TOAST" 9 | * Find keys starting with "T", "TE" 10 | * Find values for keys starting with "TE" 11 | * Find key-value pairs for keys starting with "TE" 12 | * Find keys closest to non-existent key 'TEMPLE' 13 | 14 | ### Code ### 15 | ```java 16 | public static void main(String[] args) { 17 | RadixTree tree = new ConcurrentRadixTree(new DefaultCharArrayNodeFactory()); 18 | 19 | tree.put("TEST", 1); 20 | tree.put("TOAST", 2); 21 | tree.put("TEAM", 3); 22 | 23 | System.out.println("Tree structure:"); 24 | // PrettyPrintable is a non-public API for testing, prints semi-graphical representations of trees... 25 | PrettyPrinter.prettyPrint((PrettyPrintable) tree, System.out); 26 | 27 | System.out.println(); 28 | System.out.println("Value for 'TEST' (exact match): " + tree.getValueForExactKey("TEST")); 29 | System.out.println("Value for 'TOAST' (exact match): " + tree.getValueForExactKey("TOAST")); 30 | System.out.println(); 31 | System.out.println("Keys starting with 'T': " + Iterables.toString(tree.getKeysStartingWith("T"))); 32 | System.out.println("Keys starting with 'TE': " + Iterables.toString(tree.getKeysStartingWith("TE"))); 33 | System.out.println(); 34 | System.out.println("Values for keys starting with 'TE': " + Iterables.toString(tree.getValuesForKeysStartingWith("TE"))); 35 | System.out.println("Key-Value pairs for keys starting with 'TE': " + Iterables.toString(tree.getKeyValuePairsForKeysStartingWith("TE"))); 36 | System.out.println(); 37 | System.out.println("Keys closest to 'TEMPLE': " + Iterables.toString(tree.getClosestKeys("TEMPLE"))); 38 | } 39 | ``` 40 | 41 | ### Output ### 42 | ``` 43 | Tree structure: 44 | ○ 45 | └── ○ T 46 | ├── ○ E 47 | │ ├── ○ AM (3) 48 | │ └── ○ ST (1) 49 | └── ○ OAST (2) 50 | 51 | Value for 'TEST' (exact match): 1 52 | Value for 'TOAST' (exact match): 2 53 | 54 | Keys starting with 'T': [TEAM, TEST, TOAST] 55 | Keys starting with 'TE': [TEAM, TEST] 56 | 57 | Values for keys starting with 'TE': [3, 1] 58 | Key-Value pairs for keys starting with 'TE': [(TEAM, 3), (TEST, 1)] 59 | 60 | Keys closest to 'TEMPLE': [TEAM, TEST] 61 | ``` 62 | 63 | ## Adding Keys without Values ## 64 | ```java 65 | tree.put("FOO", VoidValue.SINGLETON); 66 | ``` 67 | Supplying [VoidValue](http://htmlpreview.github.io/?http://raw.githubusercontent.com/npgall/concurrent-trees/master/documentation/javadoc/apidocs/com/googlecode/concurrenttrees/radix/node/concrete/voidvalue/VoidValue.html) as above, stores the key in the tree without associating it with any value. 68 | 69 | Internally, a special type of node will be used which omits a field for storing a value entirely, which can reduce memory usage when values are not needed and there will be a lot of such nodes. 70 | 71 | For more details see [NodeFactoryAndMemoryUsage](NodeFactoryAndMemoryUsage.md). -------------------------------------------------------------------------------- /documentation/ConcurrentReversedRadixTreeUsage.md: -------------------------------------------------------------------------------- 1 | # Example Usage for ConcurrentReversedRadixTree # 2 | 3 | 4 | ## General Usage ## 5 | * Create a concurrent reversed radix tree 6 | * Insert keys "TEST", "TOAST", "TEAM", associate with integer values 1, 2, 3 7 | * Graphically print the structure of the tree 8 | * Find values for keys exactly matching "TEST", "TOAST" 9 | * Find keys ending with "ST", "M" 10 | * Find values for keys ending with "ST" 11 | * Find key-value pairs for keys ending with "ST" 12 | 13 | ### Code ### 14 | ```java 15 | public static void main(String[] args) { 16 | ReversedRadixTree tree = new ConcurrentReversedRadixTree(new DefaultCharArrayNodeFactory()); 17 | 18 | tree.put("TEST", 1); 19 | tree.put("TOAST", 2); 20 | tree.put("TEAM", 3); 21 | 22 | System.out.println("Tree structure:"); 23 | // PrettyPrintable is a non-public API for testing, prints semi-graphical representations of trees... 24 | PrettyPrinter.prettyPrint((PrettyPrintable) tree, System.out); 25 | 26 | System.out.println(); 27 | System.out.println("Value for 'TEST' (exact match): " + tree.getValueForExactKey("TEST")); 28 | System.out.println("Value for 'TOAST' (exact match): " + tree.getValueForExactKey("TOAST")); 29 | System.out.println(); 30 | System.out.println("Keys ending with 'ST': " + Iterables.toString(tree.getKeysEndingWith("ST"))); 31 | System.out.println("Keys ending with 'M': " + Iterables.toString(tree.getKeysEndingWith("M"))); 32 | System.out.println(); 33 | System.out.println("Values for keys ending with 'ST': " + Iterables.toString(tree.getValuesForKeysEndingWith("ST"))); 34 | System.out.println("Key-Value pairs for keys ending with 'ST': " + Iterables.toString(tree.getKeyValuePairsForKeysEndingWith("ST"))); 35 | } 36 | ``` 37 | 38 | ### Output ### 39 | ``` 40 | Tree structure: 41 | ○ 42 | ├── ○ MAET (3) 43 | └── ○ TS 44 | ├── ○ AOT (2) 45 | └── ○ ET (1) 46 | 47 | Value for 'TEST' (exact match): 1 48 | Value for 'TOAST' (exact match): 2 49 | 50 | Keys ending with 'ST': [TOAST, TEST] 51 | Keys ending with 'M': [TEAM] 52 | 53 | Values for keys ending with 'ST': [2, 1] 54 | Key-Value pairs for keys ending with 'ST': [(TOAST, 2), (TEST, 1)] 55 | ``` 56 | 57 | ## Adding Keys without Values ## 58 | ```java 59 | tree.put("FOO", VoidValue.SINGLETON); 60 | ``` 61 | Supplying [VoidValue](http://htmlpreview.github.io/?http://raw.githubusercontent.com/npgall/concurrent-trees/master/documentation/javadoc/apidocs/com/googlecode/concurrenttrees/radix/node/concrete/voidvalue/VoidValue.html) as above, stores the key in the tree without associating it with any value. 62 | 63 | Internally, a special type of node will be used which omits a field for storing a value entirely, which can reduce memory usage when values are not needed and there will be a lot of such nodes. 64 | 65 | For more details see [NodeFactoryAndMemoryUsage](NodeFactoryAndMemoryUsage.md). -------------------------------------------------------------------------------- /documentation/ConcurrentSuffixTreeUsage.md: -------------------------------------------------------------------------------- 1 | # Example Usage for ConcurrentSuffixTree # 2 | 3 | ## Objective ## 4 | * Print the suffixes of "TEST", "TOAST", "TEAM" (for reference only) 5 | * Create a concurrent suffix tree 6 | * Insert keys "TEST", "TOAST", "TEAM", associate with integer values 1, 2, 3 7 | * Graphically print the structure of the tree 8 | * Find values for keys exactly matching "TEST", "TOAST" 9 | * Find keys ending with "ST", "M" 10 | * Find values for keys ending with "ST" 11 | * Find key-value pairs for keys ending with "ST" 12 | * Find keys containing "TE", "A" 13 | * Find values for keys containing "A" 14 | * Find key-value pairs for keys containing "A" 15 | 16 | ## Code ## 17 | ```java 18 | public static void main(String[] args) { 19 | System.out.println("Suffixes for 'TEST': " + Iterables.toString(CharSequences.generateSuffixes("TEST"))); 20 | System.out.println("Suffixes for 'TOAST': " + Iterables.toString(CharSequences.generateSuffixes("TOAST"))); 21 | System.out.println("Suffixes for 'TEAM': " + Iterables.toString(CharSequences.generateSuffixes("TEAM"))); 22 | 23 | SuffixTree tree = new ConcurrentSuffixTree(new DefaultCharArrayNodeFactory()); 24 | 25 | tree.put("TEST", 1); 26 | tree.put("TOAST", 2); 27 | tree.put("TEAM", 3); 28 | 29 | System.out.println(); 30 | System.out.println("Tree structure:"); 31 | // PrettyPrintable is a non-public API for testing, prints semi-graphical representations of trees... 32 | PrettyPrinter.prettyPrint((PrettyPrintable) tree, System.out); 33 | 34 | System.out.println(); 35 | System.out.println("Value for 'TEST' (exact match): " + tree.getValueForExactKey("TEST")); 36 | System.out.println("Value for 'TOAST' (exact match): " + tree.getValueForExactKey("TOAST")); 37 | System.out.println(); 38 | System.out.println("Keys ending with 'ST': " + Iterables.toString(tree.getKeysEndingWith("ST"))); 39 | System.out.println("Keys ending with 'M': " + Iterables.toString(tree.getKeysEndingWith("M"))); 40 | System.out.println("Values for keys ending with 'ST': " + Iterables.toString(tree.getValuesForKeysEndingWith("ST"))); 41 | System.out.println("Key-Value pairs for keys ending with 'ST': " + Iterables.toString(tree.getKeyValuePairsForKeysEndingWith("ST"))); 42 | System.out.println(); 43 | System.out.println("Keys containing 'TE': " + Iterables.toString(tree.getKeysContaining("TE"))); 44 | System.out.println("Keys containing 'A': " + Iterables.toString(tree.getKeysContaining("A"))); 45 | System.out.println("Values for keys containing 'A': " + Iterables.toString(tree.getValuesForKeysContaining("A"))); 46 | System.out.println("Key-Value pairs for keys containing 'A': " + Iterables.toString(tree.getKeyValuePairsForKeysContaining("A"))); 47 | } 48 | ``` 49 | 50 | ## Output ## 51 | ``` 52 | Suffixes for 'TEST': [TEST, EST, ST, T] 53 | Suffixes for 'TOAST': [TOAST, OAST, AST, ST, T] 54 | Suffixes for 'TEAM': [TEAM, EAM, AM, M] 55 | 56 | Tree structure: 57 | ○ 58 | ├── ○ A 59 | │ ├── ○ M ([TEAM]) 60 | │ └── ○ ST ([TOAST]) 61 | ├── ○ E 62 | │ ├── ○ AM ([TEAM]) 63 | │ └── ○ ST ([TEST]) 64 | ├── ○ M ([TEAM]) 65 | ├── ○ OAST ([TOAST]) 66 | ├── ○ ST ([TOAST, TEST]) 67 | └── ○ T ([TOAST, TEST]) 68 | ├── ○ E 69 | │ ├── ○ AM ([TEAM]) 70 | │ └── ○ ST ([TEST]) 71 | └── ○ OAST ([TOAST]) 72 | 73 | Value for 'TEST' (exact match): 1 74 | Value for 'TOAST' (exact match): 2 75 | 76 | Keys ending with 'ST': [TOAST, TEST] 77 | Keys ending with 'M': [TEAM] 78 | Values for keys ending with 'ST': [2, 1] 79 | Key-Value pairs for keys ending with 'ST': [(TEST, 1), (TOAST, 2)] 80 | 81 | Keys containing 'TE': [TEAM, TEST] 82 | Keys containing 'A': [TEAM, TOAST] 83 | Values for keys containing 'A': [3, 2] 84 | Key-Value pairs for keys containing 'A': [(TEAM, 3), (TOAST, 2)] 85 | ``` -------------------------------------------------------------------------------- /documentation/Downloads.md: -------------------------------------------------------------------------------- 1 | # Download Information # 2 | 3 | ## Download for Maven Projects ## 4 | 5 | Concurrent-Trees is in Maven Central, and can be added to a Maven project as follows: 6 | ``` 7 | 8 | com.googlecode.concurrent-trees 9 | concurrent-trees 10 | x.x.x 11 | 12 | ``` 13 | 14 | See [ReleaseNotes](ReleaseNotes.md) for the latest version number. 15 | 16 | ## Download for Non-Maven Projects ## 17 | The jar file can be downloaded directly from [maven central](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.googlecode.concurrent-trees%22%20AND%20a%3A%22concurrent-trees%22). 18 | -------------------------------------------------------------------------------- /documentation/LCSubstringSolverUsage.md: -------------------------------------------------------------------------------- 1 | # Example Usage to find the Longest Common Substring in a collection of documents # 2 | 3 | ## Objective ## 4 | * Solve the [longest common substring problem](http://en.wikipedia.org/wiki/Longest_common_substring_problem) using the included `LCSubstringSolver` 5 | 6 | ## Code ## 7 | ```java 8 | static final String document1 = 9 | "albert einstein, was a german theoretical physicist who developed the theory of general relativity"; 10 | 11 | static final String document2 = 12 | "near the beginning of his career, albert einstein thought that newtonian mechanics was no longer " + 13 | "enough to reconcile the laws of classical mechanics with the laws of the electromagnetic field"; 14 | 15 | static final String document3 = 16 | "in late summer 1895, at the age of sixteen, albert einstein sat the entrance examinations for " + 17 | "the swiss federal polytechnic in zurich"; 18 | 19 | public static void main(String[] args) { 20 | LCSubstringSolver solver = new LCSubstringSolver(new DefaultCharSequenceNodeFactory()); 21 | 22 | solver.add(document1); 23 | solver.add(document2); 24 | solver.add(document3); 25 | 26 | String longestCommonSubstring = CharSequences.toString(solver.getLongestCommonSubstring()); 27 | System.out.println(longestCommonSubstring); 28 | } 29 | ``` 30 | 31 | ## Output ## 32 | ``` 33 | albert einstein 34 | ``` -------------------------------------------------------------------------------- /documentation/ShakespeareCollectedWorks.md: -------------------------------------------------------------------------------- 1 | # Text Analysis of The Collected Works of William Shakespeare # 2 | 3 | The Collected Works of William Shakespeare was used as a dataset to test trees during development. This is not actually a large dataset by today's standards, at <10 MB of text files, but nonetheless useful for testing. It's unclear how the Bard would feel about his work being used for this purpose, no offense intended! 4 | 5 | Standalone programs to build trees from and analyze The Collected Works of William Shakespeare can be found [here](../code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/). 6 | 7 | Some output from these programs: 8 | 9 | * Radix Tree of the **individual words** contained in all of Shakespeare's works 10 | * Tree [viewable here](../code/src/test/resources/shakespeare-trees/radix-tree-words-shakespeare-collected-works.txt) 11 | * Values are the works containing those words 12 | * 29,008 nodes 13 | 14 | * Suffix Tree of the **individual words** contained in all of Shakespeare's works 15 | * Tree [viewable here](../code/src/test/resources/shakespeare-trees/suffix-tree-words-shakespeare-collected-works.txt) 16 | * Values in this output are the complete words associated with each suffix 17 | * 75,780 nodes 18 | 19 | * Suffix Tree of Shakespeare's Tragedy, Antony and Cleopatra 20 | * 280 MB in RAM using `DefaultCharSequenceNodeFactory` 21 | * Insufficient RAM to build tree using `DefaultCharArrayNodeFactory` 22 | * 29.438 GB if written to disk (highlights problems suffered by `DefaultCharArrayNodeFactory`) 23 | * 217,697 nodes 24 | 25 | * Suffix Tree of the entirety of Shakespeare's Tragedies (10 plays) 26 | * 2.0 GB in RAM using `DefaultCharSequenceNodeFactory` 27 | * Insufficient RAM to build tree using `DefaultCharArrayNodeFactory` 28 | * 248.997 GB if written to disk (highlights memory which would be required by `DefaultCharArrayNodeFactory`) 29 | * 1,965,884 nodes 30 | 31 | * The Longest Common Substring of Shakespeare's Tragedies (10 plays) 32 | * Output [viewable here](../code/src/test/resources/shakespeare-trees/tragedies-longest-common-substring.txt) 33 | * Longest common substring is: "**` dramatis personae `**" -------------------------------------------------------------------------------- /documentation/documents/download-statistics.csv: -------------------------------------------------------------------------------- 1 | Month,Downloads 2 | 07/2012,32 3 | 08/2012,36 4 | 09/2012,51 5 | 10/2012,46 6 | 11/2012,83 7 | 12/2012,109 8 | 01/2013,119 9 | 02/2013,223 10 | 03/2013,270 11 | 04/2013,315 12 | -------------------------------------------------------------------------------- /documentation/documents/tree-apply-patch.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raphw/concurrent-trees/470cd5d8b2273c2965c643b16b4ef65315a7a977/documentation/documents/tree-apply-patch.dia -------------------------------------------------------------------------------- /documentation/documents/tree-test-team-insert-toast.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raphw/concurrent-trees/470cd5d8b2273c2965c643b16b4ef65315a7a977/documentation/documents/tree-test-team-insert-toast.dia -------------------------------------------------------------------------------- /documentation/documents/tree-test-team-toast.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raphw/concurrent-trees/470cd5d8b2273c2965c643b16b4ef65315a7a977/documentation/documents/tree-test-team-toast.dia -------------------------------------------------------------------------------- /documentation/documents/tree-test-team.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raphw/concurrent-trees/470cd5d8b2273c2965c643b16b4ef65315a7a977/documentation/documents/tree-test-team.dia -------------------------------------------------------------------------------- /documentation/images/concurrent-trees-downloads-june-2019.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raphw/concurrent-trees/470cd5d8b2273c2965c643b16b4ef65315a7a977/documentation/images/concurrent-trees-downloads-june-2019.png -------------------------------------------------------------------------------- /documentation/images/dfs-comic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raphw/concurrent-trees/470cd5d8b2273c2965c643b16b4ef65315a7a977/documentation/images/dfs-comic.png -------------------------------------------------------------------------------- /documentation/images/tree-apply-patch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raphw/concurrent-trees/470cd5d8b2273c2965c643b16b4ef65315a7a977/documentation/images/tree-apply-patch.png -------------------------------------------------------------------------------- /documentation/javadoc/Readme.md: -------------------------------------------------------------------------------- 1 | **To view Concurrent-Trees JavaDocs click [here](http://htmlpreview.github.io/?http://raw.githubusercontent.com/npgall/concurrent-trees/master/documentation/javadoc/apidocs/index.html).** -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/com/googlecode/concurrenttrees/common/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.googlecode.concurrenttrees.common (Concurrent-Trees 2.6.0 API) 8 | 9 | 10 | 11 | 12 | 13 |

com.googlecode.concurrenttrees.common

14 |
15 |

Interfaces

16 | 19 |

Classes

20 | 26 |
27 | 28 | 29 | -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.googlecode.concurrenttrees.radix.node.concrete.bytearray (Concurrent-Trees 2.6.0 API) 8 | 9 | 10 | 11 | 12 | 13 |

com.googlecode.concurrenttrees.radix.node.concrete.bytearray

14 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/com/googlecode/concurrenttrees/radix/node/concrete/chararray/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.googlecode.concurrenttrees.radix.node.concrete.chararray (Concurrent-Trees 2.6.0 API) 8 | 9 | 10 | 11 | 12 | 13 |

com.googlecode.concurrenttrees.radix.node.concrete.chararray

14 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.googlecode.concurrenttrees.radix.node.concrete.charsequence (Concurrent-Trees 2.6.0 API) 8 | 9 | 10 | 11 | 12 | 13 |

com.googlecode.concurrenttrees.radix.node.concrete.charsequence

14 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/com/googlecode/concurrenttrees/radix/node/concrete/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.googlecode.concurrenttrees.radix.node.concrete (Concurrent-Trees 2.6.0 API) 8 | 9 | 10 | 11 | 12 | 13 |

com.googlecode.concurrenttrees.radix.node.concrete

14 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/com/googlecode/concurrenttrees/radix/node/concrete/voidvalue/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.googlecode.concurrenttrees.radix.node.concrete.voidvalue (Concurrent-Trees 2.6.0 API) 8 | 9 | 10 | 11 | 12 | 13 |

com.googlecode.concurrenttrees.radix.node.concrete.voidvalue

14 |
15 |

Classes

16 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/com/googlecode/concurrenttrees/radix/node/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.googlecode.concurrenttrees.radix.node (Concurrent-Trees 2.6.0 API) 8 | 9 | 10 | 11 | 12 | 13 |

com.googlecode.concurrenttrees.radix.node

14 |
15 |

Interfaces

16 | 20 |
21 | 22 | 23 | -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/com/googlecode/concurrenttrees/radix/node/util/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.googlecode.concurrenttrees.radix.node.util (Concurrent-Trees 2.6.0 API) 8 | 9 | 10 | 11 | 12 | 13 |

com.googlecode.concurrenttrees.radix.node.util

14 |
15 |

Interfaces

16 | 20 |

Classes

21 | 27 |
28 | 29 | 30 | -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/com/googlecode/concurrenttrees/radix/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.googlecode.concurrenttrees.radix (Concurrent-Trees 2.6.0 API) 8 | 9 | 10 | 11 | 12 | 13 |

com.googlecode.concurrenttrees.radix

14 |
15 |

Interfaces

16 | 19 |

Classes

20 | 25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/com/googlecode/concurrenttrees/radixinverted/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.googlecode.concurrenttrees.radixinverted (Concurrent-Trees 2.6.0 API) 8 | 9 | 10 | 11 | 12 | 13 |

com.googlecode.concurrenttrees.radixinverted

14 |
15 |

Interfaces

16 | 19 |

Classes

20 | 23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/com/googlecode/concurrenttrees/radixreversed/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.googlecode.concurrenttrees.radixreversed (Concurrent-Trees 2.6.0 API) 8 | 9 | 10 | 11 | 12 | 13 |

com.googlecode.concurrenttrees.radixreversed

14 |
15 |

Interfaces

16 | 19 |

Classes

20 | 23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/com/googlecode/concurrenttrees/solver/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.googlecode.concurrenttrees.solver (Concurrent-Trees 2.6.0 API) 8 | 9 | 10 | 11 | 12 | 13 |

com.googlecode.concurrenttrees.solver

14 |
15 |

Classes

16 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/com/googlecode/concurrenttrees/suffix/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.googlecode.concurrenttrees.suffix (Concurrent-Trees 2.6.0 API) 8 | 9 | 10 | 11 | 12 | 13 |

com.googlecode.concurrenttrees.suffix

14 |
15 |

Interfaces

16 | 19 |

Classes

20 | 23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Concurrent-Trees 2.6.0 API 8 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | <noscript> 69 | <div>JavaScript is disabled on your browser.</div> 70 | </noscript> 71 | <h2>Frame Alert</h2> 72 | <p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="overview-summary.html">Non-frame version</a>.</p> 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/overview-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Overview List (Concurrent-Trees 2.6.0 API) 8 | 9 | 10 | 11 | 12 | 13 | 14 | 32 |

 

33 | 34 | 35 | -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/package-list: -------------------------------------------------------------------------------- 1 | com.googlecode.concurrenttrees.common 2 | com.googlecode.concurrenttrees.radix 3 | com.googlecode.concurrenttrees.radix.node 4 | com.googlecode.concurrenttrees.radix.node.concrete 5 | com.googlecode.concurrenttrees.radix.node.concrete.bytearray 6 | com.googlecode.concurrenttrees.radix.node.concrete.chararray 7 | com.googlecode.concurrenttrees.radix.node.concrete.charsequence 8 | com.googlecode.concurrenttrees.radix.node.concrete.voidvalue 9 | com.googlecode.concurrenttrees.radix.node.util 10 | com.googlecode.concurrenttrees.radixinverted 11 | com.googlecode.concurrenttrees.radixreversed 12 | com.googlecode.concurrenttrees.solver 13 | com.googlecode.concurrenttrees.suffix 14 | -------------------------------------------------------------------------------- /documentation/javadoc/apidocs/script.js: -------------------------------------------------------------------------------- 1 | function show(type) 2 | { 3 | count = 0; 4 | for (var key in methods) { 5 | var row = document.getElementById(key); 6 | if ((methods[key] & type) != 0) { 7 | row.style.display = ''; 8 | row.className = (count++ % 2) ? rowColor : altColor; 9 | } 10 | else 11 | row.style.display = 'none'; 12 | } 13 | updateTabs(type); 14 | } 15 | 16 | function updateTabs(type) 17 | { 18 | for (var value in tabs) { 19 | var sNode = document.getElementById(tabs[value][0]); 20 | var spanNode = sNode.firstChild; 21 | if (value == type) { 22 | sNode.className = activeTableTab; 23 | spanNode.innerHTML = tabs[value][1]; 24 | } 25 | else { 26 | sNode.className = tableTab; 27 | spanNode.innerHTML = "" + tabs[value][1] + ""; 28 | } 29 | } 30 | } 31 | --------------------------------------------------------------------------------