예제 #1
0
def idToPoint(id):
    """
    Converts a hashkey into some point

    Keyword Arguments:
    id -- the multihash id/key of a node/value
    """
    idLong = multihash.parseHash(id)
    return idLong
예제 #2
0
def idToPoint(id):
    """
    Converts a hashkey into some point

    Keyword Arguments:
    id -- the multihash id/key of a node/value
    """
    idLong = multihash.parseHash(id)
    return idLong
예제 #3
0
def idToPoint(dim, id):
    """
    We're using a unit space for the position of our nodes.
    The mapping we use is to use the hash ID as the seed to an RNG.
    We should switch to either
    1) A universal RNG
    2) The mapping done by Symphony
    """
    idLong = MultiHash.parseHash(id)
    return tuple([idLong, 0])
예제 #4
0
def idToPoint(dim, id):
    """
    We're using a unit space for the position of our nodes.
    The mapping we use is to use the hash ID as the seed to an RNG.
    We should switch to either
    1) A universal RNG
    2) The mapping done by Symphony
    """
    idLong = MultiHash.parseHash(id)
    return tuple([idLong,0])
예제 #5
0
def idToPoint(dim,id):
    assert(dim == 2)
    """
    We're using a unit space for the position of our nodes.
    The mapping we use is to use the hash ID as the seed to an RNG.
    We should switch to either
    1) A universal RNG
    2) The mapping done by Symphony
    """
    idLong = MultiHash.parseHash(id)
    random.seed(idLong)
    r = random.random()**0.5
    theta = random.random()*math.pi*2
    x = math.cos(theta)*r
    y = math.sin(theta)*r
    return (x, y)
예제 #6
0
def idToPoint(dim, id):
    assert (dim == 2)
    """
    We're using a unit space for the position of our nodes.
    The mapping we use is to use the hash ID as the seed to an RNG.
    We should switch to either
    1) A universal RNG
    2) The mapping done by Symphony
    """
    idLong = MultiHash.parseHash(id)
    random.seed(idLong)
    r = random.random()**0.5
    theta = random.random() * math.pi * 2
    x = math.cos(theta) * r
    y = math.sin(theta) * r
    return (x, y)
예제 #7
0
def generateBloomFilter(wordlist):
    f = 0
    j = 0
    for w in wordlist:
        hashInt = 0
        hashVal = pmh.genHash(w, 0x12)
        for i in range(0, 10):
            try:
                tmpInt = 2**256-1
                for j in range(0,10):
                    tmpInt &= pmh.parseHash(hashVal)
                    hashVal = pmh.genHash(hashVal, 0x12)
                hashInt = (hashInt << 256) | tmpInt

            except Exception as e:
                print("error ",e)
                print(hashVal, w, i, j, len(wordlist))
            hashVal = pmh.genHash(hashVal, 0x12)
        f |= hashInt

        j += 1
    return f
예제 #8
0
def generateBloomFilter(wordlist):
    f = 0
    j = 0
    for w in wordlist:
        hashInt = 0
        hashVal = pmh.genHash(w, 0x12)
        for i in range(0, 10):
            try:
                tmpInt = 2**256 - 1
                for j in range(0, 10):
                    tmpInt &= pmh.parseHash(hashVal)
                    hashVal = pmh.genHash(hashVal, 0x12)
                hashInt = (hashInt << 256) | tmpInt

            except Exception as e:
                print("error ", e)
                print(hashVal, w, i, j, len(wordlist))
            hashVal = pmh.genHash(hashVal, 0x12)
        f |= hashInt

        j += 1
    return f
예제 #9
0
def wordInFilter(bloomInt, testWord):
    hashVal = pmh.genHash(testWord, 0x12)
    hashInt = pmh.parseHash(hashVal)
    return (bloomInt & hashInt) == hashInt
예제 #10
0
def wordInFilter(bloomInt, testWord):
    hashVal = pmh.genHash(testWord, 0x12)
    hashInt = pmh.parseHash(hashVal)
    return (bloomInt & hashInt) == hashInt