Esempio n. 1
0
    def test_is_left_of_edge(self):
        trie = Trie.Tree(8)
        trie.extend([9, 12, 44, 108, 110, 111])

        #
        ## test edge 44
        current = trie.root.left.left.right
        self.assertEqual(current.edge, word(0b101100, 6))
        self.assertEqual(current.key, word(0b00101100, 8))

        # 00000000 is left of 00101100
        q = word(0b00000000, 8)
        result = current.is_left_of_edge(q)
        self.assertTrue(result)

        # 00101011 is left of 00101100
        q = word(0b00101011, 8)
        result = current.is_left_of_edge(q)
        self.assertTrue(result)

        # 00101100 is left of 00101100
        q = word(0b0000101100, 8)
        result = current.is_left_of_edge(q)
        self.assertFalse(result)

        # 00101111 is left of 00101100
        q = word(0b00101111, 8)
        result = current.is_left_of_edge(q)
        self.assertFalse(result)

        #
        ## test edge 0-11011-00 of 108
        current = trie.root.left.right
        self.assertEqual(current.edge, word(0b11011, 5))
        self.assertEqual(current.key, word(0b011011, 6))

        # 00000000 is left of 011011
        q = word(0b00000000, 8)
        result = current.is_left_of_edge(q)
        self.assertTrue(result)

        # 01101000 is left of 011011
        q = word(0b01101000, 8)
        result = current.is_left_of_edge(q)
        self.assertTrue(result)

        # 01101100 is not left of 011011
        q = word(0b01101100, 8)
        result = current.is_left_of_edge(q)
        self.assertFalse(result)

        # 01110111 is not left of 011011
        q = word(0b01110111, 8)
        result = current.is_left_of_edge(q)
        self.assertFalse(result)
Esempio n. 2
0
    def construct(self, items):
        trie = Trie.Tree(self.w)
        trie.extend(items)

        self.root = trie.root

        self._add_branch_node(self.root, self.root)

        # start at next_depth = self.sqrt_log_u, because epsilon was already added
        self._construct_hash_table(self.root,
                                   self.root.left,
                                   next_depth=self.sqrt_log_u)
        self._construct_hash_table(self.root,
                                   self.root.right,
                                   next_depth=self.sqrt_log_u)
Esempio n. 3
0
    def test_elements(self):
        with self.random() as rand:
            trie = Trie.Tree(8)

            xs = rand.sample(range(30), 20)
            xs = self.data_words(xs, 8)
            expect = []

            for x in xs:
                trie.insert(x)
                expect.append(x)

                expect.sort()
                result = trie.elements()

                self.assertEqual(expect, result)
Esempio n. 4
0
    def construct_zfast(self, word_size, elements=[]):
        """
        Utility method, for the case, that the z-fast trie can't be constructed
        with zfast.insert().
        """
        trie = Trie.Tree(word_size)

        # use trie methods to create the trie, but use zfast nodes instead
        trie.root = Static.Node(word.epsilon, None)
        trie.extend(elements)

        # reinject zfast root and rebuild index
        zfast = Static.Tree(word_size)
        zfast.root = trie.root
        self.rebuild_structure(zfast)
        return zfast
Esempio n. 5
0
child[%(left_options)s] {
%(left_child)s
}
child[%(right_options)s] {
%(right_child)s
}
edge from parent
node[above] {\\tiny %(edge)s}
""" % d

        return str_.strip()


if __name__ == '__main__':
    import Trie
    trie = Trie.Tree(5)

    trie.extend([
        # 0b0000,
        # 0b0001,
        # 0b0010,
        # 0b0011,
        # 0b0100,
        # 0b1000,
        # 0b1010,
        # 0b1011
        11 + 0,
        11 + 1,
        11 + 2,
        11 + 3,
        11 + 4,
Esempio n. 6
0
 def new_reference_trie(self, word_size, elements=[]):
     trie = Trie.Tree(word_size)
     trie.extend(elements)
     return trie