class Set:
	def __init__(self,n=16):
		self.st = LinearProbeHT(n)

	def put(self,key):
		self.st.put(key,bool(True))

	def contains(self,key):
		return self.st.contains(key)

	def size(self):
		return self.st.size()

	def isEmpty(self):
		return self.size > 0

	def delete(self,key):
		self.st.delete(key)

	def show(self):
		self.st.show()
Example #2
0
class SparseVector:
    def __init__(self):
        self.st = LinearProbeHT()

    def size(self):
        return self.st.size()

    def put(self, i, x):
        self.st.put(i, x)

    def get(self, i):
        if not self.st.contains(i):
            return 0.0
        else:
            return self.st.get(i)

    def dot(self, that):
        assert isinstance(that, list)
        sm = 0.0

        for x in self.st.keys():
            sm += that[x] * self.get(x)

        return sm
Example #3
0
 def __init__(self):
     self.st = LinearProbeHT()
	def __init__(self,n=16):
		self.st = LinearProbeHT(n)