예제 #1
0
class TestSkipList:

    def setup(self):
        self.skip_list = SkipList()

    def test_root(self):
        self.skip_list.append(3)
        eq_(self.skip_list.root.val(), 3)
        eq_(len(self.skip_list), 1)
        eq_(self.skip_list.root, self.skip_list.last)


    def test_append(self):
        self.skip_list.append(1)
        self.skip_list.append(2)
        self.skip_list.append(3)
        self.skip_list.append(4)
        eq_(self.skip_list.root.val(), 1)
        eq_(len(self.skip_list), 4)
        eq_(self.skip_list.last.val(), 4)


    def test_generate_skips(self):
        for i in range(30):
            self.skip_list.append(i)
        skip_pairs = [(a, b) for (a, b) in self.skip_list.generate_skips()]
        eq_(skip_pairs, [(1, 6), (6, 11), (11, 16), (16, 21), (21, 26)])
예제 #2
0
def build_dictionary(terms, dictionary, doc_id, postings):
    """Build a dictionary and respective postings list from the terms"""
    global pointer
    for term in terms:
        if term not in dictionary:
            skip_list = SkipList()
            skip_list.append(doc_id)
            dictionary[term] = [len(skip_list), pointer]
            postings.insert(pointer, skip_list)
        else:
            pointer = dictionary[term][1]
            postings[dictionary[term][1]].append(doc_id)
            dictionary[term][0] += 1
        pointer += 1
예제 #3
0
파일: index.py 프로젝트: kaiserahmed/CS3245
def build_dictionary(terms, dictionary, doc_id, postings):
    """Build a dictionary and respective postings list from the terms"""
    global pointer
    for term in terms:
        if term not in dictionary:
            skip_list = SkipList()
            skip_list.append(doc_id)
            dictionary[term] = [len(skip_list), pointer]
            postings.insert(pointer, skip_list)
        else:
            pointer = dictionary[term][1]
            postings[dictionary[term][1]].append(doc_id)
            dictionary[term][0] += 1
        pointer += 1