Beispiel #1
0
 def __init__(self):
     self.bookCatalog = ArrayList.ArrayList()
     self.shoppingCart = ArrayQueue.ArrayQueue()
     self.indexKey = ChainedHashTable.ChainedHashTable()
     self.indexSortedPrefix = BinarySearchTree.BinarySearchTree()
     self.bookSortedCatalog = ArrayList.ArrayList()
     self.similaGraph = AdjacencyList.AdjacencyList(0)
Beispiel #2
0
    def test_hashtable(self):
        points = 0.5
        q = ChainedHashTable.ChainedHashTable()
        try:
            self.assertIsNone(q.find(2))
        except:
            print("ChainedHashTable find is not correct")
        finally:
            points += 0.5

        try:
            q.add(1, "first")
            q.add(2, "second")
            q.add(3, "fourth")
            self.assertAlmostEqual(q.size(), 3)
            self.assertAlmostEqual(q.find(3), "fourth")
            q.remove(3)
            self.assertIsNone(q.find(3))
            self.assertAlmostEqual(q.size(), 2)
            q.add(3, "third")
            q.add(4, "fourth")
            q.add(5, "Fifth")
            q.add(6, "sixth")
            self.assertAlmostEqual(q.size(), 6)
            self.assertAlmostEqual(q.find(3), "third")
            points += 1
        except:
            print("ChainedHashTable is not correct")
        finally:
            print(f"ChainedHashTable: {points} Points")
    def testRemove(self):
        table = ChainedHashTable(3)
        table.insert(0)
        table.insert(5)
        table.insert(2)

        self.assertEquals(table.remove(5), 5)
        self.assertEquals(table.remove(4), None)
        self.assertEquals(table.buckets[0], [0])
        self.assertEquals(table.buckets[1], [])
        self.assertEquals(table.buckets[2], [2])
  def testHasElement(self):
      table = ChainedHashTable(3)
      table.insert(0)
      table.insert(5)
 
      self.assertTrue(table.hasElement(0))
      self.assertTrue(table.hasElement(5))
      self.assertFalse(table.hasElement(4))
    def testInsert(self):
        table = ChainedHashTable(3)
        table.insert(0)
        table.insert(5)
        table.insert(2)

        self.assertEqual(table.buckets[0], [0])
        self.assertEqual(table.buckets[1], [])
        self.assertEqual(table.buckets[2], [2, 5])
Beispiel #6
0
    def loadCatalog(self, fileName: str):
        #Graphs
        self.indexKeys = ChainedHashTable.ChainedHashTable()
        self.bookCatalog = DLList.DLList()  #or arraylist

        with open(fileName, encoding='utf-8') as f:
            start_time = time.time()
            count = 0  #line number
            for line in f:
                (key, title, group, rank, similar) = line.split("^")
                b = Book.Book(key, title, group, rank, similar)
                self.bookCatalog.append(b)

                self.indexKeys.add(b.key, count)
                #self.indexKeys.add(key, line)
                count += 1
            elapsed_time = time.time() - start_time
            print(
                f"Loaded {self.bookCatalog.size()} books into bookCatalog in {elapsed_time} seconds"
            )
        #self.similar_graph()

    #def similar_graph(self,k : int):
        self.similarGraph = AdjacencyList.AdjacencyList(
            self.bookCatalog.size())

        with open(fileName, encoding='utf-8') as f:
            start_time = time.time()
            count = 0
            for line in f:
                (key, title, group, rank, similar) = line.split("^")
                l = similar.split()
                for k in range(1, len(l)):
                    j = self.indexKeys.find(l[k])
                    #print(j)
                    if j != None:  #is not
                        self.similarGraph.add_edge(count, j)
                count += 1
            elapsed_time = time.time() - start_time
            print(
                f"Loaded {self.similarGraph.n} books into Graph in {elapsed_time} seconds"
            )
Beispiel #7
0
 def __init__(self):
     self.dict = ChainedHashTable.ChainedHashTable(DLList.DLList)
 def __init__(self):
     self.chainHashTable = ChainedHashTable.ChainedHashTable()
     self.n = 0