本文整理汇总了Golang中encoding/binary.Uvarint函数的典型用法代码### 示例。如果您正苦于以下问题:Golang Uvarint函数的具体用法?Golang Uvarint怎么用?Golang Uvarint使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。

在下文中一共展示了Uvarint函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: Get

// Get key-value pairs.
func (ht *HashTable) Get(key, limit uint64) (keys, vals []uint64) {
    // This function is partially inlined in chunkcol.go
    var count, entry, bucket uint64 = 0, 0, ht.HashKey(key)
    if limit == 0 {
        keys = make([]uint64, 0, 10)
        vals = make([]uint64, 0, 10)
    } else {
        keys = make([]uint64, 0, limit)
        vals = make([]uint64, 0, limit)
    }
    for {
        entryAddr := bucket*BUCKET_SIZE + BUCKET_HEADER_SIZE + entry*ENTRY_SIZE
        entryKey, _ := binary.Uvarint(ht.File.Buf[entryAddr+1 : entryAddr+11])
        entryVal, _ := binary.Uvarint(ht.File.Buf[entryAddr+11 : entryAddr+21])
        if ht.File.Buf[entryAddr] == ENTRY_VALID {
            if entryKey == key {
                keys = append(keys, entryKey)
                vals = append(vals, entryVal)
                if count++; count == limit {
                    return
                }
            }
        } else if entryKey == 0 && entryVal == 0 {
            return
        }
        if entry++; entry == PER_BUCKET {
            entry = 0
            if bucket = ht.NextBucket(bucket); bucket == 0 {
                return
            }
        }
    }
}

开发者ID:jbenet,项目名称:tiedot,代码行数:34,代码来源:hashtable.go

示例2: GetAll

// Return all entries in the hash table.
func (ht *HashTable) GetAll(limit uint64) (keys, vals []uint64) {
    prealloc := limit
    if prealloc == 0 {
        prealloc = INITIAL_BUCKETS * PER_BUCKET / 2
    }
    keys = make([]uint64, 0, prealloc)
    vals = make([]uint64, 0, prealloc)
    counter := uint64(0)
    for head := uint64(0); head < uint64(math.Pow(2, float64(HASH_BITS))); head++ {
        var entry, bucket uint64 = 0, head
        for {
            entryAddr := bucket*BUCKET_SIZE + BUCKET_HEADER_SIZE + entry*ENTRY_SIZE
            entryKey, _ := binary.Uvarint(ht.File.Buf[entryAddr+1 : entryAddr+11])
            entryVal, _ := binary.Uvarint(ht.File.Buf[entryAddr+11 : entryAddr+21])
            if ht.File.Buf[entryAddr] == ENTRY_VALID {
                counter++
                keys = append(keys, entryKey)
                vals = append(vals, entryVal)
                if counter == limit {
                    return
                }
            } else if entryKey == 0 && entryVal == 0 {
                break
            }
            if entry++; entry == PER_BUCKET {
                entry = 0
                if bucket = ht.NextBucket(bucket); bucket == 0 {
                    return
                }
            }
        }
    }
    return
}

开发者ID:jbenet,项目名称:tiedot,代码行数:35,代码来源:hashtable.go

示例3: Uint64

//  Uint64 decodes a uint64 from buffer
func (d *Dec) Uint64() uint64 {
    if d.err != nil {
        return 0
    }
    if d.i >= len(d.decbuf) || d.i < 0 /*overflow*/ {
        d.err = errNoDecData
        return 0
    }
    d.lng = int(d.decbuf[d.i])
    // if d.lng <= 0 {
    //  d.err = errDecode
    //  return 0
    // }
    d.i++
    d.lst = d.i + d.lng
    if d.lst > len(d.decbuf) {
        d.err = errDecodeNotEnoughtData
        return 0
    }
    var x uint64
    var i int
    if d.lst == len(d.decbuf) {
        x, i = binary.Uvarint(d.decbuf[d.i:])
    } else {
        x, i = binary.Uvarint(d.decbuf[d.i:d.lst])
    }
    if i <= 0 {
        d.err = errDecode
        return 0
    }
    d.i = d.lst
    return x
}

开发者ID:mrkovec,项目名称:encdec,代码行数:34,代码来源:encdec.go

示例4: decodeRLE

func (d *int64Decoder) decodeRLE() {
    if len(d.bytes) == 0 {
        return
    }

    var i, n int

    // Next 8 bytes is the starting value
    first := binary.BigEndian.Uint64(d.bytes[i : i+8])
    i += 8

    // Next 1-10 bytes is the delta value
    value, n := binary.Uvarint(d.bytes[i:])

    i += n

    // Last 1-10 bytes is how many times the value repeats
    count, n := binary.Uvarint(d.bytes[i:])

    // Store the first value and delta value so we do not need to allocate
    // a large values slice.  We can compute the value at position d.i on
    // demand.
    d.rleFirst = first
    d.rleDelta = value
    d.n = int(count) + 1
    d.i = 0

    // We've process all the bytes
    d.bytes = nil
}

开发者ID:nrshrivatsan,项目名称:influxdb,代码行数:30,代码来源:int.go

示例5: dec

// dec decodes the encoding s into z.
func (z *nstate) dec(s string) {
    b := []byte(s)
    i, n := binary.Uvarint(b)
    if n <= 0 {
        bug()
    }
    b = b[n:]
    z.partial = rune(i)
    i, n = binary.Uvarint(b)
    if n <= 0 {
        bug()
    }
    b = b[n:]
    z.flag = flags(i)
    z.q.Reset()
    last := ^uint32(0)
    for len(b) > 0 {
        i, n = binary.Uvarint(b)
        if n <= 0 {
            bug()
        }
        b = b[n:]
        last += uint32(i)
        z.q.Add(last)
    }
}

开发者ID:ChanglinZhou,项目名称:codesearch,代码行数:27,代码来源:match.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng