Esempio n. 1
0
    def setUp(self):
        super(SkiplistTestCase, self).setUp()
        self.skip = pyskip.Skiplist()

        # Fake a list.
        layer_3 = pyskip.SortedLinkedList()
        layer_3.insert(pyskip.SkiplistNode(value=3))
        layer_3.insert(pyskip.SkiplistNode(value=4))
        layer_3.insert(pyskip.SkiplistNode(value=7))
        layer_3.insert(pyskip.SkiplistNode(value=12))
        layer_3.insert(pyskip.SkiplistNode(value=13))
        layer_3.insert(pyskip.SkiplistNode(value=14))
        layer_3.insert(pyskip.SkiplistNode(value=17))

        layer_2 = pyskip.SortedLinkedList()
        layer_2.insert(pyskip.SkiplistNode(value=3, down=layer_3[0]))
        layer_2.insert(pyskip.SkiplistNode(value=7, down=layer_3[2]))
        layer_2.insert(pyskip.SkiplistNode(value=14, down=layer_3[5]))
        layer_2.insert(pyskip.SkiplistNode(value=17, down=layer_3[6]))

        layer_1 = pyskip.SortedLinkedList()
        # First element must always be full-height.
        layer_1.insert(pyskip.SkiplistNode(value=7, down=layer_2[1]))
        layer_1.insert(pyskip.SkiplistNode(value=17, down=layer_2[3]))

        # Cheat a little.
        # But this ensures the ``find`` tests can run correctly without
        # ``insert`` & friends.
        self.skip.layers = [
            layer_1,
            layer_2,
            layer_3,
        ]
Esempio n. 2
0
def load_skiplist():
    skip = pyskip.Skiplist()

    for i in range(MAX_LOAD):
        print(i, end='\r')
        skip.insert(i)

    print()
    return skip
Esempio n. 3
0
    def test_contains(self):
        self.assertTrue(3 in self.skip)
        self.assertTrue(4 in self.skip)
        self.assertTrue(7 in self.skip)
        self.assertTrue(13 in self.skip)

        # Reached the end.
        self.assertFalse(25 in self.skip)
        # Before the head.
        self.assertFalse(-1 in self.skip)

        # An empty skiplist shouldn't fail either.
        empty = pyskip.Skiplist()
        self.assertFalse(6 in empty)
Esempio n. 4
0
    def test_find(self):
        self.assertEqual(self.skip.find(3).value, 3)
        self.assertEqual(self.skip.find(4).value, 4)
        self.assertEqual(self.skip.find(7).value, 7)
        self.assertEqual(self.skip.find(13).value, 13)

        # Reached the end.
        self.assertEqual(self.skip.find(25), None)
        # Before the head.
        self.assertEqual(self.skip.find(-1), None)

        # An empty skiplist shouldn't fail either.
        empty = pyskip.Skiplist()
        self.assertEqual(empty.find(6), None)
Esempio n. 5
0
    def test_len(self):
        self.assertEqual(len(self.skip), 7)

        empty = pyskip.Skiplist()
        self.assertEqual(len(empty), 0)
Esempio n. 6
0
# pyskip test

import sys
import bisect
import pyskip
#import skiplist 
import numpy as np


ignoredVertices = pyskip.Skiplist()

ignoredVertices.insert("50")
ignoredVertices.insert("51")
ignoredVertices.insert("56")
ignoredVertices.insert("49")
ignoredVertices.insert("14")
ignoredVertices.insert("55")
ignoredVertices.insert("1")
ignoredVertices.insert("0")
ignoredVertices.insert("2")
ignoredVertices.remove("0")

print(ignoredVertices.find("1"))
for item in ignoredVertices:
    print(item.value)