def prefix_coin_test(self):
        for n in self.sizes:
            for iters in range(self.num_iters):

                bc = BaseCoin()
                elems = [bc.flip() for i in range(n)]

                pc = PrefixCoin(elems)
                prefix_elems = [pc.flip() for i in range(n)]

                self.assertEqual(elems, prefix_elems)
    def seeded_coin_test(self):
        for n in self.sizes:
            for iters in range(self.num_iters):
                rand = random.randint(0,1000)
                random.seed(rand)

                bc = BaseCoin()
                elems = [bc.flip() for i in range(n)]

                sc = SeededCoin(rand)
                seeded_elems = [sc.flip() for i in range(n)]

                self.assertEqual(elems, seeded_elems)
    def base_coin_test(self):
        for n in self.sizes:
            for iters in range(self.num_iters):
                rand = random.randint(0,1000)
                random.seed(rand)

                elems = [random.randint(0,1) == 1 for i in range(n)]

                random.seed(rand)
                bc = BaseCoin()
                flipped_elems = [bc.flip() for i in range(n)]

                self.assertEqual(elems, flipped_elems)
    def record_prefix_coin_test(self):
        for n in self.sizes:
            for iters in range(self.num_iters):
                rand = random.randint(0,1000)
                random.seed(rand)

                bc = BaseCoin()
                elems = [bc.flip() for i in range(n)]

                random.seed(rand)
                rpc = RecordedPrefixCoin(elems)
                more_elems = [rpc.flip() for i in range(n)]
                rec_elems = rpc.record

                self.assertEqual(elems, rec_elems)
                self.assertEqual(elems, more_elems)
    def skiplist_test(self):
        """ Make sure the different coins can be used to guarantee the same
            skiplist.
        """
        for n in self.sizes[:-1]:
            for iters in range(self.num_iters):
                max_elem = n * 100
                min_elem = -1 * max_elem

                lower = IntElem(min_elem-1)
                upper = IntElem(max_elem+1)
                
                elems = [IntElem(random.randint(min_elem, max_elem))
                         for i in range(n)]

                rand = random.randint(0,1000)
                random.seed(rand)

                prefix = [random.randint(0,1) == 1 for i in range(10 * n)]

                random.seed(rand)
                sl_base = AuthSkipList.new(
                    elems, lower, upper, BaseCoin())

                random.seed(rand)
                sl_recd = AuthSkipList.new(
                    elems, lower, upper, RecordedCoin())

                sl_pref = AuthSkipList.new(
                    elems, lower, upper, PrefixCoin(prefix))

                sl_rpre = AuthSkipList.new(
                    elems, lower, upper, RecordedPrefixCoin(prefix))

                sl_seed = AuthSkipList.new(
                    elems, lower, upper, SeededCoin(rand))

                self.assertEqual(sl_seed.to_list_of_lists(),
                                 sl_rpre.to_list_of_lists())
                self.assertEqual(sl_rpre.to_list_of_lists(),
                                 sl_pref.to_list_of_lists())
                self.assertEqual(sl_pref.to_list_of_lists(),
                                 sl_recd.to_list_of_lists())
                self.assertEqual(sl_recd.to_list_of_lists(),
                                 sl_base.to_list_of_lists())

                self.assertEqual(sl_seed.root.label,
                                 sl_rpre.root.label)
                self.assertEqual(sl_rpre.root.label,
                                 sl_pref.root.label)
                self.assertEqual(sl_pref.root.label,
                                 sl_recd.root.label)
                self.assertEqual(sl_recd.root.label,
                                 sl_base.root.label)
예제 #6
0
    def new(cls, auth_skiplist, lbound, rbound, coin=BaseCoin()):
        """ Create a new VO from an AuthSkipList for a given range.
            
            The new VO has a tree-like structure. Notably, it does NOT have
            the usual grid-like structure of a skiplist; that is, there is
            not a horizontal connection between each element of each row.
        """

        vo = cls(None, lbound, rbound, coin)
        vo_root = vo.build_node(auth_skiplist.root)
        vo.root = vo_root
        return vo
예제 #7
0
    def new(cls,
            elems,
            lbound,
            rbound,
            coin=BaseCoin(),
            conn_info=ConnInfo('localhost', 42424, 'root', 'secret'),
            table='__ADS_metadata___',
            elemclass=IntElem):
        """ Create a new skiplist that stores all of its data inside an
            Accumulo instance.

            Arguments:

            cls - the class implementing this class method
            elems - the elements to create the skiplist over
            lbound, rbound - the left and right boundary elements of the list
            coin - the source of randomness to use
                   (see pace.ads.skiplist.coin)
            conn_info - how to connect to the Accumulo instance being used
            table - the name of the table to store the ADS in
            elemclass - the class to use to store the elements in the skiplist
        """

        sl = cls(None, lbound, rbound, coin)

        if conn_info is not None:
            # For connecting to a live Accumulo instance
            host, port, user, password = conn_info
            conn = Accumulo(host=conn_info.host,
                            port=conn_info.port,
                            user=conn_info.user,
                            password=conn_info.password)
        else:
            # For testing/debug
            conn = FakeConnection()

        sl.conn = conn
        sl.table = table
        sl.elemclass = elemclass

        if not conn.table_exists(table):
            conn.create_table(table)

        right = cls.nodeclass.newnode(sl, None, None, rbound, True)
        left = cls.nodeclass.newnode(sl, None, right, lbound, True)

        sl.root = left

        for elem in elems:
            sl.insert(elem)

        return sl
    def new(cls, elems, lbound, rbound, coin=BaseCoin()):
        """ Build a new SkipList
            
            Arguments:
            elems - the list of elements to put into the SkipList
            lbound - the leftmost element in the SkipList (acts like -infty)
            rbound - the rightmost element in the Skiplist (acts like +infty)
        """

        sl = cls(None, lbound, rbound, coin)
        right = cls.nodeclass.newnode(sl, None, None, rbound, True)
        left = cls.nodeclass.newnode(sl, None, right, lbound, True)
        sl.root = left

        for elem in elems:
            sl.insert(elem)

        return sl
예제 #9
0
    def range_query(cls, auth_skiplist, lbound, rbound, coin=BaseCoin()):
        """ Do a range query on a skiplist with a given range. Same as new()
        """

        return cls.new(auth_skiplist, lbound, rbound, coin)