Exemple #1
0
 def query(self, elem):
     for i in range(self.k):
         hashv = (mmh3.murmur(elem, i) % self.m) // self.k + (self.m //
                                                              self.k) * i
         hashv1 = mmh3.murmur(elem, i) % 4
         if self.c1[hashv] == 0:
             return False
         if self.c1[hashv] >= 4:
             return True
         if self.c1[hashv] == 3:
             t = self.distinct_sum3.index(self.c2[hashv])
             for j in self.dis_elem3[t]:
                 if j == self.BH[hashv1]:
                     return True
             return False
         if self.c1[hashv] == 1:
             if self.c2[hashv] == self.BH[hashv1]:
                 return True
             return False
         if self.c1[hashv] == 2:
             t = self.distinct_sum2.index(self.c2[hashv])
             for j in self.dis_elem2[t]:
                 if j == self.BH[hashv1]:
                     return True
             return False
Exemple #2
0
 def insert(self, elem):
     for i in range(self.k):
         hashv = (mmh3.murmur(elem, i) % self.m) // self.k + (self.m //
                                                              self.k) * i
         #print(hashv)
         self.c1[hashv] = self.c1[hashv] + 1
         hashv1 = mmh3.murmur(elem, i) % 4
         self.c2[hashv] = self.c2[hashv] + self.BH[hashv1]
Exemple #3
0
 def delelem(self, elem):
     if not self.query(elem):
         return
     for i in range(self.k):
         hashv = mmh3.murmur(elem,
                             i) % self.m // self.k + (self.m // self.k) * i
         self.c1[hashv] = self.c1[hashv] - 1
         hashv1 = mmh3.murmur(elem, i) % 4
         self.c2[hashv] = self.c2[hashv] - self.BH[hashv1]
 def delelem(self, elem):
     if self.curr == 0:
         print("Error : Query unsuccessful, Bloom filter empty")
         return
     for i in range(int(self.k) - 2):
         hashv = mmh3.murmur(elem, i) % self.m
         if self.bit_vector.arr[hashv] == 0:
             print(elem, "Not found")
             return
         else:
             self.bit_vector.arr[hashv] = self.bit_vector.arr[hashv] - 1
             self.curr = self.curr - 1
     hashv = (int(fnv.fnv(elem)) % self.m)
     if (self.bit_vector.arr[hashv] == 0):
         print(elem, "Not found")
         return
     else:
         self.bit_vector.arr[hashv] = self.bit_vector.arr[hashv] - 1
         self.curr = self.curr - 1
     hashv = (int(fibo.hash(elem)) % self.m)
     if (self.bit_vector.arr[hashv] == 0):
         print(elem, "Not found")
         return
     else:
         self.bit_vector.arr[hashv] = self.bit_vector.arr[hashv] - 1
         self.curr = self.curr - 1
 def insert(self, elem):
     for i in range(int(self.k) - 2):
         hashv = mmh3.murmur(elem,
                             i) % (self.m // self.k) + i * self.m // self.k
         self.bit_vector.arr[hashv] = self.bit_vector.arr[hashv] + 1
     hashv = (int(fibo.hash(elem)) % self.m)
     self.bit_vector.arr[hashv] = self.bit_vector.arr[hashv] + 1
     hashv = (int(fnv.fnv(elem)) % self.m)
     self.bit_vector.arr[hashv] = self.bit_vector.arr[hashv] + 1
     self.curr = self.curr + 1
 def query(self, elem):
     for i in range(int(self.k) - 2):
         hashv = mmh3.murmur(elem,
                             i) % (self.m // self.k) + i * self.m // self.k
         if self.bit_vector.arr[hashv] == 0:
             return False
     hashv = (int(fibo.hash(elem)) % self.m)
     if (self.bit_vector.arr[hashv] == 0):
         return False
     hashv = (int(fnv.fnv(elem)) % self.m)
     if (self.bit_vector.arr[hashv] == 0):
         return False
     return True
Exemple #7
0
    def search():
        t = 0
        e = 0
        for i in range(len(dict1)):
            x = dict1[i]
            q = x
            b = mmh3.murmur(q.lower())
            b = b % LENNY
            w = fnv.fnv(q.lower())
            w = w % LENNY
            g = horner.hash3(q.lower())
            g = g % LENNY

            if m[b] == 1 and m[w] == 1 and m[g] == 1:
                t = t + 1
            elif m[b] == None or m[w] == None or m[g] == None:
                e = e + 1
        print("Number of common elements are(approx)", t)
Exemple #8
0
import sys
sys.path.insert(0, '../../../hash_funtions')
import fnv
import mmh3
name = input("Enter Your Name :")
dat = input("Enter Your Date Of Birth(ddmmyyyy) :")
LENNY = 35677
a = mmh3.murmur(name)
b = fnv.fnv(name)
c = mmh3.murmur(dat)
d = fnv.fnv(dat)

a = a % LENNY
b = b % LENNY
c = c % LENNY
d = d % LENNY

m = [None for i in range(LENNY)]
m[a] = m[b] = m[c] = m[d] = 1
with open("../../../../data/10k.txt") as dict:
    dict1 = dict.read().split('\n')

for i in range(len(dict1)):
    a = []
    a = dict1[i]
    n = mmh3.murmur(a)
    f = fnv.fnv(a)
    n = n % LENNY
    f = f % LENNY
    m[n] = 1
    m[f] = 1
Exemple #9
0
if len(dict1) < len(dict2):
    n = len(dict2)
else:
    n = len(dict1)
p = 0.18
m1 = ((float(n) * float(math.log(p))) /
      float(math.log(1.0 / (math.pow(2, float(math.log(2)))))))
k = (float(math.log(2)) * float(m1) / float(n))
#print (math.floor(m),math.floor(k))
LENNY = prime.prime(math.ceil(m1))
m = [None for i in range(LENNY)]
if len(dict1) > len(dict2):
    for i in range(len(dict1)):
        a = []
        a = dict1[i]
        n = mmh3.murmur(a.lower())
        n = n % LENNY
        f = fnv.fnv(a.lower())
        f = f % LENNY
        q = horner.hash3(a.lower())
        q = q % LENNY
        m[n] = 1
        m[f] = 1
        m[q] = 1

    def search():
        t = 0
        e = 0
        for i in range(len(dict2)):
            x = dict2[i]
            q = x