com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharArrayNodeFactory Java Examples
The following examples show how to use
com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharArrayNodeFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReversedRadixTreeUsage.java From concurrent-trees with Apache License 2.0 | 6 votes |
public static void main(String[] args) { ReversedRadixTree<Integer> tree = new ConcurrentReversedRadixTree<Integer>(new DefaultCharArrayNodeFactory()); tree.put("TEST", 1); tree.put("TOAST", 2); tree.put("TEAM", 3); System.out.println("Tree structure:"); // PrettyPrintable is a non-public API for testing, prints semi-graphical representations of trees... PrettyPrinter.prettyPrint((PrettyPrintable) tree, System.out); System.out.println(); System.out.println("Value for 'TEST' (exact match): " + tree.getValueForExactKey("TEST")); System.out.println("Value for 'TOAST' (exact match): " + tree.getValueForExactKey("TOAST")); System.out.println(); System.out.println("Keys ending with 'ST': " + Iterables.toString(tree.getKeysEndingWith("ST"))); System.out.println("Keys ending with 'M': " + Iterables.toString(tree.getKeysEndingWith("M"))); System.out.println(); System.out.println("Values for keys ending with 'ST': " + Iterables.toString(tree.getValuesForKeysEndingWith("ST"))); System.out.println("Key-Value pairs for keys ending with 'ST': " + Iterables.toString(tree.getKeyValuePairsForKeysEndingWith("ST"))); }
Example #2
Source File: InvertedRadixTreeUsage.java From concurrent-trees with Apache License 2.0 | 6 votes |
public static void main(String[] args) { InvertedRadixTree<Integer> tree = new ConcurrentInvertedRadixTree<Integer>(new DefaultCharArrayNodeFactory()); tree.put("TEST", 1); tree.put("TOAST", 2); tree.put("TEAM", 3); System.out.println("Tree structure:"); // PrettyPrintable is a non-public API for testing, prints semi-graphical representations of trees... PrettyPrinter.prettyPrint((PrettyPrintable) tree, System.out); System.out.println(); System.out.println("Value for 'TEST' (exact match): " + tree.getValueForExactKey("TEST")); System.out.println("Value for 'TOAST' (exact match): " + tree.getValueForExactKey("TOAST")); System.out.println(); System.out.println("Keys contained in 'MY TEAM LIKES TOAST': " + Iterables.toString(tree.getKeysContainedIn("MY TEAM LIKES TOAST"))); System.out.println("Keys contained in 'MY TEAM LIKES TOASTERS': " + Iterables.toString(tree.getKeysContainedIn("MY TEAM LIKES TOASTERS"))); System.out.println("Values for keys contained in 'MY TEAM LIKES TOAST': " + Iterables.toString(tree.getValuesForKeysContainedIn("MY TEAM LIKES TOAST"))); System.out.println("Key-value pairs for keys contained in 'MY TEAM LIKES TOAST': " + Iterables.toString(tree.getKeyValuePairsForKeysContainedIn("MY TEAM LIKES TOAST"))); }
Example #3
Source File: RadixTreeUsage.java From concurrent-trees with Apache License 2.0 | 6 votes |
public static void main(String[] args) { RadixTree<Integer> tree = new ConcurrentRadixTree<Integer>(new DefaultCharArrayNodeFactory()); tree.put("TEST", 1); tree.put("TOAST", 2); tree.put("TEAM", 3); System.out.println("Tree structure:"); // PrettyPrintable is a non-public API for testing, prints semi-graphical representations of trees... PrettyPrinter.prettyPrint((PrettyPrintable) tree, System.out); System.out.println(); System.out.println("Value for 'TEST' (exact match): " + tree.getValueForExactKey("TEST")); System.out.println("Value for 'TOAST' (exact match): " + tree.getValueForExactKey("TOAST")); System.out.println(); System.out.println("Keys starting with 'T': " + Iterables.toString(tree.getKeysStartingWith("T"))); System.out.println("Keys starting with 'TE': " + Iterables.toString(tree.getKeysStartingWith("TE"))); System.out.println(); System.out.println("Values for keys starting with 'TE': " + Iterables.toString(tree.getValuesForKeysStartingWith("TE"))); System.out.println("Key-Value pairs for keys starting with 'TE': " + Iterables.toString(tree.getKeyValuePairsForKeysStartingWith("TE"))); System.out.println(); System.out.println("Keys closest to 'TEMPLE': " + Iterables.toString(tree.getClosestKeys("TEMPLE"))); }
Example #4
Source File: BuildShakespeareWordRadixTree.java From concurrent-trees with Apache License 2.0 | 6 votes |
public static void main(String[] args) { ConcurrentRadixTree<WordValue> tree = new ConcurrentRadixTree<WordValue>(new DefaultCharArrayNodeFactory()); for (String file : files) { Set<String> wordsInFile = IOUtil.loadWordsFromTextFileOnClasspath(file, true); // true = convert to lowercase for (String word : wordsInFile) { WordValue wordValue = tree.getValueForExactKey(word); if (wordValue == null) { wordValue = new WordValue(word); tree.put(word, wordValue); // not using concurrency support here } wordValue.manuscriptsContainingWord.add(file.replaceAll("/.*/.*/", "").replace(".txt", "")); } } final String radixTreePrinted = PrettyPrinter.prettyPrint(tree); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JTextArea textArea = new JTextArea(); textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); textArea.setText(radixTreePrinted); JScrollPane scrollPane = new JScrollPane(textArea); textArea.setEditable(false); JFrame frame = new JFrame("Shakespeare Radix Tree"); frame.add(scrollPane); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setSize(640, 480); frame.setVisible(true); } }); }
Example #5
Source File: NodeUtilTest.java From concurrent-trees with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings({"NullableProblems"}) public void testEnsureNoDuplicateEdges_Negative() throws Exception { NodeFactory nodeFactory = new DefaultCharArrayNodeFactory(); List<Node> nodes = Arrays.asList( nodeFactory.createNode("A", null, Collections.<Node>emptyList(), false), nodeFactory.createNode("B", null, Collections.<Node>emptyList(), false), nodeFactory.createNode("B", null, Collections.<Node>emptyList(), false), nodeFactory.createNode("C", null, Collections.<Node>emptyList(), false) ); try { NodeUtil.ensureNoDuplicateEdges(nodes); Assert.fail("Should throw exception"); } catch (IllegalStateException expected) { // Expected } }
Example #6
Source File: PrettyPrinterTest.java From concurrent-trees with Apache License 2.0 | 6 votes |
static Node getHandBuiltTestTree() { NodeFactory nodeFactory = new DefaultCharArrayNodeFactory(); // Build the tree by hand, as if the following strings were added: B, BA, BAN, BANDANA, BANAN, BANANA // ○ // └── ○ B (1) // └── ○ A (2) // └── ○ N (3) // ├── ○ AN (5) // │ └── ○ A (6) // └── ○ DANA (4) final Node n1, n2, n3, n4, n5, n6; n6 = nodeFactory.createNode("A", 6, Collections.<Node>emptyList(), false); n5 = nodeFactory.createNode("AN", 5, Arrays.asList(n6), false); n4 = nodeFactory.createNode("DANA", 4, Collections.<Node>emptyList(), false); n3 = nodeFactory.createNode("N", 3, Arrays.asList(n4, n5), false); // note: it should sort these such that n5 is first n2 = nodeFactory.createNode("A", 2, Arrays.asList(n3), false); n1 = nodeFactory.createNode("B", 1, Arrays.asList(n2), false); //noinspection NullableProblems return nodeFactory.createNode("", null, Arrays.asList(n1), true); // root }
Example #7
Source File: RadixTreeIndex.java From cqengine with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void clear(QueryOptions queryOptions) { this.tree = new ConcurrentRadixTree<StoredResultSet<O>>(new DefaultCharArrayNodeFactory()); }
Example #8
Source File: IpConcurrentRadixTree.java From onos with Apache License 2.0 | 5 votes |
@Override public void clear() { ipv4Tree = new ConcurrentRadixTree<>(new DefaultCharArrayNodeFactory()); ipv6Tree = new ConcurrentRadixTree<>(new DefaultCharArrayNodeFactory()); }
Example #9
Source File: AccessControl.java From outbackcdx with Apache License 2.0 | 5 votes |
RulesBySsurt(Collection<AccessRule> rules) { tree = new ConcurrentInvertedRadixTree<>(new DefaultCharArrayNodeFactory()); for (AccessRule rule: rules) { try { put(rule); } catch (IllegalArgumentException e) { log.log(Level.WARNING, "Skipping invalid access rule: " + rule.id, e); } } }
Example #10
Source File: ReversedRadixTreeIndexTest.java From cqengine with Apache License 2.0 | 5 votes |
@Test public void testNodeFactory() { ReversedRadixTreeIndex<String, Car> index1 = ReversedRadixTreeIndex.onAttribute(Car.MANUFACTURER); ReversedRadixTreeIndex<String, Car> index2 = ReversedRadixTreeIndex.onAttributeUsingNodeFactory(Car.MANUFACTURER, new DefaultCharArrayNodeFactory()); ReversedRadixTreeIndex<String, Car> index3 = ReversedRadixTreeIndex.onAttributeUsingNodeFactory(Car.MANUFACTURER, new SmartArrayBasedNodeFactory()); assertTrue(index1.nodeFactory instanceof DefaultCharArrayNodeFactory); assertTrue(index2.nodeFactory instanceof DefaultCharArrayNodeFactory); assertTrue(index3.nodeFactory instanceof SmartArrayBasedNodeFactory); }
Example #11
Source File: InvertedRadixTreeIndexTest.java From cqengine with Apache License 2.0 | 5 votes |
@Test public void testNodeFactory() { InvertedRadixTreeIndex<String, Car> index1 = InvertedRadixTreeIndex.onAttribute(Car.MANUFACTURER); InvertedRadixTreeIndex<String, Car> index2 = InvertedRadixTreeIndex.onAttributeUsingNodeFactory(Car.MANUFACTURER, new DefaultCharArrayNodeFactory()); InvertedRadixTreeIndex<String, Car> index3 = InvertedRadixTreeIndex.onAttributeUsingNodeFactory(Car.MANUFACTURER, new SmartArrayBasedNodeFactory()); assertTrue(index1.nodeFactory instanceof DefaultCharArrayNodeFactory); assertTrue(index2.nodeFactory instanceof DefaultCharArrayNodeFactory); assertTrue(index3.nodeFactory instanceof SmartArrayBasedNodeFactory); }
Example #12
Source File: SuffixTreeIndexTest.java From cqengine with Apache License 2.0 | 5 votes |
@Test public void testNodeFactory() { SuffixTreeIndex<String, Car> index1 = SuffixTreeIndex.onAttribute(Car.MANUFACTURER); SuffixTreeIndex<String, Car> index2 = SuffixTreeIndex.onAttributeUsingNodeFactory(Car.MANUFACTURER, new DefaultCharArrayNodeFactory()); SuffixTreeIndex<String, Car> index3 = SuffixTreeIndex.onAttributeUsingNodeFactory(Car.MANUFACTURER, new SmartArrayBasedNodeFactory()); assertTrue(index1.nodeFactory instanceof DefaultCharArrayNodeFactory); assertTrue(index2.nodeFactory instanceof DefaultCharArrayNodeFactory); assertTrue(index3.nodeFactory instanceof SmartArrayBasedNodeFactory); }
Example #13
Source File: RadixTreeIndexTest.java From cqengine with Apache License 2.0 | 5 votes |
@Test public void testNodeFactory() { RadixTreeIndex<String, Car> index1 = RadixTreeIndex.onAttribute(Car.MANUFACTURER); RadixTreeIndex<String, Car> index2 = RadixTreeIndex.onAttributeUsingNodeFactory(Car.MANUFACTURER, new DefaultCharArrayNodeFactory()); RadixTreeIndex<String, Car> index3 = RadixTreeIndex.onAttributeUsingNodeFactory(Car.MANUFACTURER, new SmartArrayBasedNodeFactory()); assertTrue(index1.nodeFactory instanceof DefaultCharArrayNodeFactory); assertTrue(index2.nodeFactory instanceof DefaultCharArrayNodeFactory); assertTrue(index3.nodeFactory instanceof SmartArrayBasedNodeFactory); }
Example #14
Source File: SuffixTreeUsage.java From concurrent-trees with Apache License 2.0 | 5 votes |
public static void main(String[] args) { System.out.println("Suffixes for 'TEST': " + Iterables.toString(CharSequences.generateSuffixes("TEST"))); System.out.println("Suffixes for 'TOAST': " + Iterables.toString(CharSequences.generateSuffixes("TOAST"))); System.out.println("Suffixes for 'TEAM': " + Iterables.toString(CharSequences.generateSuffixes("TEAM"))); SuffixTree<Integer> tree = new ConcurrentSuffixTree<Integer>(new DefaultCharArrayNodeFactory()); tree.put("TEST", 1); tree.put("TOAST", 2); tree.put("TEAM", 3); System.out.println(); System.out.println("Tree structure:"); // PrettyPrintable is a non-public API for testing, prints semi-graphical representations of trees... PrettyPrinter.prettyPrint((PrettyPrintable) tree, System.out); System.out.println(); System.out.println("Value for 'TEST' (exact match): " + tree.getValueForExactKey("TEST")); System.out.println("Value for 'TOAST' (exact match): " + tree.getValueForExactKey("TOAST")); System.out.println(); System.out.println("Keys ending with 'ST': " + Iterables.toString(tree.getKeysEndingWith("ST"))); System.out.println("Keys ending with 'M': " + Iterables.toString(tree.getKeysEndingWith("M"))); System.out.println("Values for keys ending with 'ST': " + Iterables.toString(tree.getValuesForKeysEndingWith("ST"))); System.out.println("Key-Value pairs for keys ending with 'ST': " + Iterables.toString(tree.getKeyValuePairsForKeysEndingWith("ST"))); System.out.println(); System.out.println("Keys containing 'TE': " + Iterables.toString(tree.getKeysContaining("TE"))); System.out.println("Keys containing 'A': " + Iterables.toString(tree.getKeysContaining("A"))); System.out.println("Values for keys containing 'A': " + Iterables.toString(tree.getValuesForKeysContaining("A"))); System.out.println("Key-Value pairs for keys containing 'A': " + Iterables.toString(tree.getKeyValuePairsForKeysContaining("A"))); }
Example #15
Source File: NodeUtilTest.java From concurrent-trees with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings({"NullableProblems"}) public void testEnsureNoDuplicateEdges_Positive() throws Exception { NodeFactory nodeFactory = new DefaultCharArrayNodeFactory(); List<Node> nodes = Arrays.asList( nodeFactory.createNode("A", null, Collections.<Node>emptyList(), false), nodeFactory.createNode("B", null, Collections.<Node>emptyList(), false), nodeFactory.createNode("C", null, Collections.<Node>emptyList(), false) ); }
Example #16
Source File: NodeUtilTest.java From concurrent-trees with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings({"NullableProblems"}) public void testBinarySearchForEdge() throws Exception { NodeFactory nodeFactory = new DefaultCharArrayNodeFactory(); Node[] nodes = new Node[] { nodeFactory.createNode("A", null, Collections.<Node>emptyList(), false), nodeFactory.createNode("B", null, Collections.<Node>emptyList(), false), nodeFactory.createNode("C", null, Collections.<Node>emptyList(), false) }; AtomicReferenceArray<Node> atomicReferenceArray = new AtomicReferenceArray<Node>(nodes); Assert.assertEquals(0, NodeUtil.binarySearchForEdge(atomicReferenceArray, 'A')); Assert.assertEquals(1, NodeUtil.binarySearchForEdge(atomicReferenceArray, 'B')); Assert.assertEquals(2, NodeUtil.binarySearchForEdge(atomicReferenceArray, 'C')); Assert.assertTrue(NodeUtil.binarySearchForEdge(atomicReferenceArray, 'D') < 0); }
Example #17
Source File: BuildShakespeareWordSuffixTree.java From concurrent-trees with Apache License 2.0 | 5 votes |
public static void main(String[] args) { ConcurrentSuffixTree<WordValue> tree = new ConcurrentSuffixTree<WordValue>(new DefaultCharArrayNodeFactory()); for (String file : files) { Set<String> wordsInFile = IOUtil.loadWordsFromTextFileOnClasspath(file, true); // true = convert to lowercase for (String word : wordsInFile) { WordValue wordValue = tree.getValueForExactKey(word); if (wordValue == null) { wordValue = new WordValue(word); tree.put(word, wordValue); // not using concurrency support here } wordValue.manuscriptsContainingWord.add(file.replaceAll("/.*/.*/", "").replace(".txt", "")); } } final String radixTreePrinted = PrettyPrinter.prettyPrint(tree); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JTextArea textArea = new JTextArea(); textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); textArea.setText(radixTreePrinted); JScrollPane scrollPane = new JScrollPane(textArea); textArea.setEditable(false); JFrame frame = new JFrame("Shakespeare Suffix Tree"); frame.add(scrollPane); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setSize(640, 480); frame.setVisible(true); } }); }
Example #18
Source File: IterablesUsage.java From concurrent-trees with Apache License 2.0 | 5 votes |
public static void main(String[] args) { RadixTree<Integer> tree = new ConcurrentRadixTree<Integer>(new DefaultCharArrayNodeFactory()); tree.put("TEST", 1); tree.put("TOAST", 2); tree.put("TEAM", 3); Iterable<CharSequence> keysStartingWithT = tree.getKeysStartingWith("T"); List<CharSequence> listOfKeysStartingWithT = Iterables.toList (keysStartingWithT); Set<CharSequence> setOfKeysStartingWithT = Iterables.toSet (keysStartingWithT); String toStringOfKeysStartingWithT = Iterables.toString(keysStartingWithT); System.out.println("Keys starting with 'T': " + toStringOfKeysStartingWithT); }
Example #19
Source File: SuffixTreeIndex.java From cqengine with Apache License 2.0 | 4 votes |
/** * Package-private constructor, used by static factory methods. */ protected SuffixTreeIndex(Attribute<O, A> attribute) { this(attribute, new DefaultCharArrayNodeFactory()); }
Example #20
Source File: SuffixTreeIndex.java From cqengine with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void clear(QueryOptions queryOptions) { this.tree = new ConcurrentSuffixTree<StoredResultSet<O>>(new DefaultCharArrayNodeFactory()); }
Example #21
Source File: InvertedRadixTreeIndex.java From cqengine with Apache License 2.0 | 4 votes |
/** * Package-private constructor, used by static factory methods. */ protected InvertedRadixTreeIndex(Attribute<O, A> attribute) { this(attribute, new DefaultCharArrayNodeFactory()); }
Example #22
Source File: InvertedRadixTreeIndex.java From cqengine with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void clear(QueryOptions queryOptions) { this.tree = new ConcurrentInvertedRadixTree<StoredResultSet<O>>(new DefaultCharArrayNodeFactory()); }
Example #23
Source File: ReversedRadixTreeIndex.java From cqengine with Apache License 2.0 | 4 votes |
/** * Package-private constructor, used by static factory methods. */ protected ReversedRadixTreeIndex(Attribute<O, A> attribute) { this(attribute, new DefaultCharArrayNodeFactory()); }
Example #24
Source File: ReversedRadixTreeIndex.java From cqengine with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void clear(QueryOptions queryOptions) { this.tree = new ConcurrentReversedRadixTree<StoredResultSet<O>>(new DefaultCharArrayNodeFactory()); }
Example #25
Source File: RadixTreeIndex.java From cqengine with Apache License 2.0 | 4 votes |
/** * Package-private constructor, used by static factory methods. */ protected RadixTreeIndex(Attribute<O, A> attribute) { this(attribute, new DefaultCharArrayNodeFactory()); }