Example #1
0
func (self *_varchar_kv) Bytes() []byte {
	bytes := make([]byte, 8+self.keysize+self.valsize)
	copy(bytes[0:4], bs.ByteSlice32(self.keysize))
	copy(bytes[4:8], bs.ByteSlice32(self.valsize))
	copy(bytes[8:8+self.keysize], self.key)
	copy(bytes[8+self.keysize:8+self.keysize+self.valsize], self.val)
	return bytes
}
Example #2
0
func (self *list_header) Bytes() []byte {
	bytes := make(bs.ByteSlice, LIST_HEADER_LEN)
	copy(bytes[0:8], bs.ByteSlice64(uint64(self.next)))
	copy(bytes[8:16], bs.ByteSlice64(uint64(self.head)))
	copy(bytes[16:24], bs.ByteSlice64(uint64(self.tail)))
	copy(bytes[24:32], bs.ByteSlice64(uint64(self.insert_point)))
	copy(bytes[32:36], bs.ByteSlice32(self.block_count))
	copy(bytes[36:40], bs.ByteSlice32(self.list_length))
	return bytes
}
Example #3
0
func (self *ctrlblk) Bytes() []byte {
	bytes := make([]byte, CONTROLSIZE)
	copy(bytes[0:8], bs.ByteSlice64(uint64(self.end)))
	copy(bytes[8:16], bs.ByteSlice64(uint64(self.free_head)))
	copy(bytes[16:20], bs.ByteSlice32(uint32(self.free_len)))
	return bytes
}
Example #4
0
func NewLinearHash(file file.BlockDevice, kv bucket.KVStore) (self *LinearHash, err error) {
	const NUMBUCKETS = 16
	const I = 5
	table, err := bucket.NewBlockTable(file, 4, 8)
	if err != nil {
		return nil, err
	}
	for n := uint32(0); n < NUMBUCKETS; n++ {
		bkt, err := bucket.NewHashBucket(file, HASHSIZE, kv)
		if err != nil {
			return nil, err
		}
		err = table.Put(bs.ByteSlice32(n), bs.ByteSlice64(uint64(bkt.Key())))
		if err != nil {
			return nil, err
		}
	}
	self = &LinearHash{
		file:  file,
		kv:    kv,
		table: table,
		ctrl: ctrlblk{
			buckets: NUMBUCKETS,
			records: 0,
			table:   table.Key(),
			i:       I,
		},
	}
	return self, self.write_ctrlblk()
}
Example #5
0
func (self *ctrlblk) Bytes() []byte {
	bytes := make([]byte, CONTROLSIZE)
	copy(bytes[0:4], bs.ByteSlice32(self.buckets))
	copy(bytes[4:12], bs.ByteSlice64(self.records))
	copy(bytes[12:20], bs.ByteSlice64(uint64(self.table)))
	bytes[20] = self.i
	return bytes
}
Example #6
0
func (self *header) Bytes() (bytes []byte) {
	bytes = make([]byte, HEADER_SIZE)
	bytes[0] = self.flag
	bytes[1] = self.keysize
	bytes[2] = self.valsize
	copy(bytes[4:8], bs.ByteSlice32(self.records))
	copy(bytes[8:16], bs.ByteSlice64(uint64(self.next)))
	copy(bytes[16:18], bs.ByteSlice16(self.blocks))
	return bytes
}
Example #7
0
func new_element(data bs.ByteSlice) *list_element {
	bytes := make(bs.ByteSlice, len(data)+4)
	copy(bytes[0:4], bs.ByteSlice32(uint32(len(data))))
	copy(bytes[4:], data)
	return &list_element{
		bytes:   bytes,
		_length: bytes[:4],
		data:    bytes[4:],
	}
}
Example #8
0
func (self *LinearHash) get_bucket(bkt_idx uint32) (*bucket.HashBucket, error) {
	bkt_key, err := self.table.Get(bs.ByteSlice32(bkt_idx))
	if err != nil {
		fmt.Println("Couldn't get bkt_idx out of table", bkt_idx)
		return nil, err
	}
	bkt, err := bucket.ReadHashBucket(self.file, int64(bkt_key.Int64()), self.kv)
	if err != nil {
		fmt.Println("Couldn't read bucket", bkt_key.Int64())
		return nil, err
	}
	return bkt, nil
}
Example #9
0
func (self *LinearHash) split() (err error) {
	bkt_idx := self.ctrl.buckets % (1 << (self.ctrl.i - 1))
	bkt, err := self.get_bucket(bkt_idx)
	if err != nil {
		return err
	}
	keys := bkt.Keys()
	self.ctrl.buckets += 1
	if self.ctrl.buckets > (1 << self.ctrl.i) {
		self.ctrl.i += 1
	}
	newbkt, err := bkt.Split(func(key bs.ByteSlice) bool {
		this_idx := self.bucket(key.Int64())
		return this_idx == bkt_idx
	})
	err = self.table.Put(bs.ByteSlice32(self.ctrl.buckets-1), bs.ByteSlice64(uint64(newbkt.Key())))
	if err != nil {
		return err
	}
	err = self.write_ctrlblk()
	if err != nil {
		return err
	}
	for _, key := range keys {
		if has, err := self.Has(key); err != nil {
			return err
		} else if !has {
			hash := bs.ByteSlice64(hash(key))
			in_first := bkt.Has(hash, key)
			in_second := newbkt.Has(hash, key)
			fmt.Println()
			fmt.Println("i", self.ctrl.i, "records", self.ctrl.records, "buckets", self.ctrl.buckets)
			fmt.Println("key", key, "hash", hash)
			fmt.Println("in_first", in_first, bkt_idx)
			fmt.Println("in_second", in_second, self.ctrl.buckets-1)
			return fmt.Errorf("Key went missing during split")
		}
	}
	return nil
}