@@ -0,0 +1,1266 @@
+import numpy%0A%0Aclass HLLRegister(list):%0A    def __init__(self, registerIndexSize):%0A        list.__init__(self)%0A        self.registerIndexSize = registerIndexSize%0A        self.mask = int('1' * registerIndexSize, 2)%0A        for i in xrange(0, 2**registerIndexSize):%0A            self.append(0)%0A        %0A    def update(self, hashValue):%0A        index = self._calcindex(hashValue)%0A        value = self._calcvalue(hashValue)%0A        if value %3E self%5Bindex%5D:%0A            self%5Bindex%5D = value%0A%0A    def _calcindex(self, hashValue):%0A        return self.mask & hashValue%0A%0A    def _calcvalue(self, hashValue):%0A        value = hashValue %3E%3E self.registerIndexSize%0A        print format(value, 'b')%0A        print format(value, 'b')%5B::-1%5D%0A        return format(value, 'b')%5B::-1%5D.index('1') + 1%0A%0Aclass BaseHyperLogLog(object):%0A    def __init__(self, constant, registerIndexSize, hashFunc):%0A        self.constant = constant%0A        self.registerIndexSize = registerIndexSize%0A        self.hashFunc = hashFunc%0A        self.register = HLLRegister(registerIndexSize)%0A%0A    def cals_cardinality(self):%0A        invs = map(lambda x: 2**(-x), self.register)%0A        return self.constant * len(self.register)**2 * sum(invs)%0A%0A    def update(data):%0A        self.register.update(self.hashFunc(data))%0A%0A

add hyperloglog base class