mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 19:43:49 +08:00
fix: make linter happy in internal/btree
This commit is contained in:
parent
f767213681
commit
4625c785dd
@ -138,7 +138,7 @@ func Create(name string) (*Btree, error) {
|
||||
|
||||
// Close closes the database
|
||||
func (bt *Btree) Close() error {
|
||||
err := bt.Close()
|
||||
err := bt.fd.Close()
|
||||
for i := 0; i < cacheSlots; i++ {
|
||||
bt.cache[i] = cache{}
|
||||
}
|
||||
@ -271,7 +271,7 @@ func (bt *Btree) remove(t *table, i int, sha1 *byte) int64 {
|
||||
return offset
|
||||
}
|
||||
|
||||
func (bt *Btree) insert(toff int64, sha1 *byte, data []byte, len int) int64 {
|
||||
func (bt *Btree) insert(toff int64, sha1 *byte, data []byte, size int) int64 {
|
||||
table := bt.get(toff)
|
||||
assert(table.size < tableSize-1)
|
||||
|
||||
@ -296,7 +296,7 @@ func (bt *Btree) insert(toff int64, sha1 *byte, data []byte, len int) int64 {
|
||||
lc := table.items[i].child
|
||||
if lc != 0 {
|
||||
/* recursion */
|
||||
ret = bt.insert(lc, sha1, data, len)
|
||||
ret = bt.insert(lc, sha1, data, size)
|
||||
|
||||
/* check if we need to split */
|
||||
child := bt.get(lc)
|
||||
@ -314,7 +314,7 @@ func (bt *Btree) insert(toff int64, sha1 *byte, data []byte, len int) int64 {
|
||||
// make sure data is written before a reference is added to it
|
||||
_ = bt.fd.Sync()
|
||||
} else {
|
||||
off = bt.insertData(data, len)
|
||||
off = bt.insertData(data, size)
|
||||
ret = off
|
||||
}
|
||||
|
||||
@ -399,10 +399,10 @@ func (bt *Btree) delete(offset int64, hash *byte) int64 {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (bt *Btree) insertTopLevel(toff *int64, sha1 *byte, data []byte, len int) int64 {
|
||||
func (bt *Btree) insertTopLevel(toff *int64, sha1 *byte, data []byte, size int) int64 {
|
||||
var off, ret, rc int64
|
||||
if *toff != 0 {
|
||||
ret = bt.insert(*toff, sha1, data, len)
|
||||
ret = bt.insert(*toff, sha1, data, size)
|
||||
|
||||
/* check if we need to split */
|
||||
table := bt.get(*toff)
|
||||
@ -414,7 +414,7 @@ func (bt *Btree) insertTopLevel(toff *int64, sha1 *byte, data []byte, len int) i
|
||||
rc = bt.split(table, sha1, &off)
|
||||
bt.flush(table, *toff)
|
||||
} else {
|
||||
off = bt.insertData(data, len)
|
||||
off = bt.insertData(data, size)
|
||||
ret = off
|
||||
}
|
||||
|
||||
@ -471,7 +471,7 @@ func (bt *Btree) Insert(csha1 *byte, data []byte) {
|
||||
var sha1 [sha1Size]byte
|
||||
copysha1(&sha1[0], csha1)
|
||||
|
||||
bt.insertTopLevel(&bt.top, &sha1[0], data, len(data))
|
||||
_ = bt.insertTopLevel(&bt.top, &sha1[0], data, len(data))
|
||||
freeQueued(bt)
|
||||
bt.flushSuper()
|
||||
}
|
||||
|
@ -26,10 +26,10 @@ func freeQueued(bt *Btree) {
|
||||
fqueueLen = 0
|
||||
}
|
||||
|
||||
func (bt *Btree) allocChunk(len int) int64 {
|
||||
assert(len > 0)
|
||||
func (bt *Btree) allocChunk(size int) int64 {
|
||||
assert(size > 0)
|
||||
|
||||
len = power2(len)
|
||||
size = power2(size)
|
||||
|
||||
var offset int64
|
||||
if bt.inAllocator {
|
||||
@ -38,10 +38,10 @@ func (bt *Btree) allocChunk(len int) int64 {
|
||||
/* create fake size SHA-1 */
|
||||
var sha1 [sha1Size]byte
|
||||
p := unsafe.Pointer(&sha1[0])
|
||||
*(*int32)(p) = -1 // *(uint32_t *) sha1 = -1;
|
||||
*(*uint32)(unsafe.Add(p, i32s)) = uint32(len) // ((__be32 *) sha1)[1] = to_be32(len);
|
||||
*(*int32)(p) = -1 // *(uint32_t *) sha1 = -1;
|
||||
*(*uint32)(unsafe.Add(p, i32s)) = uint32(size) // ((__be32 *) sha1)[1] = to_be32(size);
|
||||
|
||||
/* find free chunk with the larger or the same len/SHA-1 */
|
||||
/* find free chunk with the larger or the same size/SHA-1 */
|
||||
bt.inAllocator = true
|
||||
bt.deleteLarger = true
|
||||
offset = bt.delete(bt.freeTop, &sha1[0])
|
||||
@ -50,20 +50,20 @@ func (bt *Btree) allocChunk(len int) int64 {
|
||||
assert(*(*int32)(p) == -1) // assert(*(uint32_t *) sha1 == (uint32_t) -1)
|
||||
flen := int(*(*uint32)(unsafe.Add(p, i32s))) // size_t free_len = from_be32(((__be32 *) sha1)[1])
|
||||
assert(power2(flen) == flen)
|
||||
assert(flen >= len)
|
||||
assert(flen >= size)
|
||||
|
||||
/* delete buddy information */
|
||||
resetsha1(&sha1[0])
|
||||
*(*int64)(p) = offset
|
||||
buddyLen := bt.delete(bt.freeTop, &sha1[0])
|
||||
assert(buddyLen == int64(len))
|
||||
assert(buddyLen == int64(size))
|
||||
|
||||
bt.freeTop = collapse(bt, bt.freeTop)
|
||||
|
||||
bt.inAllocator = false
|
||||
|
||||
/* free extra space at the end of the chunk */
|
||||
for flen > len {
|
||||
for flen > size {
|
||||
flen >>= 1
|
||||
bt.freeChunk(offset+int64(flen), flen)
|
||||
}
|
||||
@ -75,10 +75,10 @@ func (bt *Btree) allocChunk(len int) int64 {
|
||||
/* not found, allocate from the end of the file */
|
||||
offset = bt.alloc
|
||||
/* TODO: this wastes memory.. */
|
||||
if offset&int64(len-1) != 0 {
|
||||
offset += int64(len) - (offset & (int64(len) - 1))
|
||||
if offset&int64(size-1) != 0 {
|
||||
offset += int64(size) - (offset & (int64(size) - 1))
|
||||
}
|
||||
bt.alloc = offset + int64(len)
|
||||
bt.alloc = offset + int64(size)
|
||||
}
|
||||
bt.flushSuper()
|
||||
|
||||
@ -88,17 +88,17 @@ func (bt *Btree) allocChunk(len int) int64 {
|
||||
}
|
||||
|
||||
/* Mark a chunk as unused in the database file */
|
||||
func (bt *Btree) freeChunk(offset int64, len int) {
|
||||
assert(len > 0)
|
||||
func (bt *Btree) freeChunk(offset int64, size int) {
|
||||
assert(size > 0)
|
||||
assert(offset != 0)
|
||||
len = power2(len)
|
||||
assert(offset&int64(len-1) == 0)
|
||||
size = power2(size)
|
||||
assert(offset&int64(size-1) == 0)
|
||||
|
||||
if bt.inAllocator {
|
||||
chunk := &fqueue[fqueueLen]
|
||||
fqueueLen++
|
||||
chunk.offset = offset
|
||||
chunk.len = len
|
||||
chunk.len = size
|
||||
return
|
||||
}
|
||||
|
||||
@ -112,12 +112,12 @@ func (bt *Btree) freeChunk(offset int64, len int) {
|
||||
/* add buddy information */
|
||||
resetsha1(&sha1[0])
|
||||
*(*int32)(p) = -1 // *(uint32_t *) sha1 = -1;
|
||||
*(*uint32)(unsafe.Add(p, i32s)) = uint32(len) // ((__be32 *) sha1)[1] = to_be32(len);
|
||||
*(*uint32)(unsafe.Add(p, i32s)) = uint32(size) // ((__be32 *) sha1)[1] = to_be32(size);
|
||||
*(*uint32)(unsafe.Add(p, i32s*2)) = rand.Uint32() /* to make SHA-1 unique */
|
||||
*(*uint32)(unsafe.Add(p, i32s*3)) = rand.Uint32()
|
||||
|
||||
// insert_toplevel(btree, &btree->free_top, sha1, NULL, offset);
|
||||
bt.insertTopLevel(&bt.freeTop, &sha1[0], nil, int(offset))
|
||||
_ = bt.insertTopLevel(&bt.freeTop, &sha1[0], nil, int(offset))
|
||||
bt.inAllocator = false
|
||||
|
||||
bt.flushSuper()
|
||||
|
Loading…
x
Reference in New Issue
Block a user