示例#1
0
文件: graycurve.py 项目: todda/scurve
 def index(self, p):
     idx = 0
     iwidth = self.bits * self.dimension
     for i in range(iwidth):
         bitoff = self.bits-(i/self.dimension)-1
         poff = self.dimension-(i%self.dimension)-1
         b = utils.bitrange(p[poff], self.bits, bitoff, bitoff+1) << i
         idx |= b
     return utils.igraycode(idx)
示例#2
0
文件: hilbert.py 项目: crabl/knn-algo
def hilbert_index(dimension, order, p):
    h, e, d = 0, 0, 0
    for i in range(order):
        l = 0
        for x in range(dimension):
            b = utils.bitrange(p[dimension - x - 1], order, i, i + 1)
            l |= b << x
        l = transform(e, d, dimension, l)
        w = utils.igraycode(l)
        e = e ^ utils.lrot(entry(w), d + 1, dimension)
        d = (d + direction(w, dimension) + 1) % dimension
        h = (h << dimension) | w
    return h
示例#3
0
def hilbert_index(dimension, order, p):
    h, e, d = 0, 0, 0
    for i in range(order):
        l = 0
        for x in range(dimension):
            b = utils.bitrange(p[dimension - x - 1], order, i, i + 1)
            l |= b << x
        l = transform(e, d, dimension, l)
        w = utils.igraycode(l)
        e = e ^ utils.lrot(entry(w), d + 1, dimension)
        d = (d + direction(w, dimension) + 1) % dimension
        h = (h << dimension) | w
    return h
示例#4
0
文件: hilbert.py 项目: quag/scurve
def hilbert_index(dimension, order, p):
    # Hamilton's paper initialises d to 0, which appears to be an error.
    h, e, d = 0, 0, 1
    for i in range(order):
        l = 0
        for x in range(dimension):
            b = utils.bitrange(p[x], order, i, i+1)
            l |= b<<x
        l = transform(e, d, dimension, l)
        w = utils.igraycode(l)
        e = e ^ utils.lrot(entry(w), d+1, dimension)
        d = (d + direction(w, dimension) + 1)%dimension
        h = (h<<dimension)|w
    return h
示例#5
0
 def test_igraycode(self):
     for i in range(10):
         assert utils.igraycode(utils.graycode(i)) == i
         assert utils.graycode(utils.igraycode(i)) == i
示例#6
0
 def test_igraycode(self):
     for i in range(10):
         assert utils.igraycode(utils.graycode(i)) == i
         assert utils.graycode(utils.igraycode(i)) == i