当前位置: 首页>>代码示例>>Golang>>正文


Golang ByteSlice.Eq方法代码示例

本文整理汇总了Golang中file-structures/block/byteslice.ByteSlice.Eq方法的典型用法代码示例。如果您正苦于以下问题:Golang ByteSlice.Eq方法的具体用法?Golang ByteSlice.Eq怎么用?Golang ByteSlice.Eq使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在file-structures/block/byteslice.ByteSlice的用法示例。


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

示例1: Put

func (self *HashBucket) Put(hash, key, value bs.ByteSlice) (updated bool, err error) {
	defer func() {
		if e := recover(); e != nil {
			err = e.(error)
		}
	}()
	bytes, err := self.kv.Put(key, value)
	if err != nil {
		return false, err
	}
	updated = false
	err = self.bt.put(hash, bytes, func(rec *record) (bool, bs.ByteSlice) {
		k2, _, err := self.kv.Get(rec.value)
		if err != nil {
			panic(err)
		}
		if key.Eq(k2) {
			newbytes, err := self.kv.Update(bytes, key, value)
			if err != nil {
				panic(err)
			}
			updated = true
			return true, newbytes
		} else {
			return false, nil
		}
	})
	if err != nil {
		return false, err
	}
	return updated, self.bt.save()
}
开发者ID:timtadh,项目名称:file-structures,代码行数:32,代码来源:bucket.go

示例2: put

func (self *BlockTable) put(key, value bs.ByteSlice, doreplace func(*record) (bool, bs.ByteSlice)) (err error) {
	if len(key) != int(self.header.keysize) {
		return fmt.Errorf(
			"Key size is wrong, %d != %d", self.header.keysize, len(key))
	}
	if len(value) > int(self.header.valsize) {
		return fmt.Errorf(
			"Value size is wrong, %d >= %d", self.header.valsize, len(value))
	}
	all_records := self.records
	if len(all_records) <= int(self.header.records)+1 {
		// alloc another block
		err := self.add_block()
		if err != nil {
			return err
		}
		all_records = self.records
	}
	records := record_slice(all_records[:self.header.records])
	i, found := records.find(key)
	replace := false
	bytes := value
	if found {
		for j := i; j < len(records); j++ {
			if key.Eq(records[j].key) {
				var tmp bs.ByteSlice
				replace, tmp = doreplace(records[j])
				if replace {
					i = j
					bytes = tmp
					break
				}
			} else {
				break
			}
		}
	}
	if !found || (found && !replace) {
		j := len(all_records)
		j -= 1
		for ; j > int(i); j-- {
			cur := all_records[j-1]
			next := all_records[j]
			copy(next.key, cur.key)
			copy(next.value, cur.value)
		}
		self.header.records += 1
	}
	spot := all_records[i]
	copy(spot.key, key)
	copy(spot.value, bytes)
	return self.save()
}
开发者ID:timtadh,项目名称:file-structures,代码行数:53,代码来源:bucket.go

示例3: Get

func (self *HashBucket) Get(hash, key bs.ByteSlice) (value bs.ByteSlice, err error) {
	all_records := self.bt.records
	records := record_slice(all_records[:self.bt.header.records])
	found := records.find_all(hash)
	for _, rec := range found {
		k2, value, err := self.kv.Get(rec.value)
		if err != nil {
			return nil, err
		}
		if key.Eq(k2) {
			return value, nil
		}
	}
	return nil, fmt.Errorf("Key not found")
}
开发者ID:timtadh,项目名称:file-structures,代码行数:15,代码来源:bucket.go

示例4: Has

func (self *HashBucket) Has(hash, key bs.ByteSlice) bool {
	all_records := self.bt.records
	records := record_slice(all_records[:self.bt.header.records])
	found := records.find_all(hash)
	for _, rec := range found {
		k2, _, err := self.kv.Get(rec.value)
		if err != nil {
			panic(err)
		}
		if key.Eq(k2) {
			return true
		}
	}
	return false
}
开发者ID:timtadh,项目名称:file-structures,代码行数:15,代码来源:bucket.go

示例5: find_all

func (self record_slice) find_all(key bs.ByteSlice) (found record_slice) {
	found = make(record_slice, 0, 5)
	i, ok := self.find(key)
	if !ok {
		return found
	}
	for ; i < len(self); i++ {
		if key.Eq(self[i].key) {
			found = append(found, self[i])
		} else {
			break
		}
	}
	return found
}
开发者ID:timtadh,项目名称:file-structures,代码行数:15,代码来源:bucket.go

示例6: find

func (self record_slice) find(key bs.ByteSlice) (int, bool) {
	var l int = 0
	var r int = len(self) - 1
	var m int
	for l <= r {
		m = ((r - l) >> 1) + l
		if key.Lt(self[m].key) {
			r = m - 1
		} else if key.Eq(self[m].key) {
			for j := m; j >= 0; j-- {
				if j == 0 || !key.Eq(self[j-1].key) {
					return j, true
				}
			}
		} else {
			l = m + 1
		}
	}
	return l, false
}
开发者ID:timtadh,项目名称:file-structures,代码行数:20,代码来源:bucket.go

示例7: Remove

func (self *HashBucket) Remove(hash, key bs.ByteSlice) (err error) {
	all_records := self.bt.records
	records := record_slice(all_records[:self.bt.header.records])
	i, found := records.find(hash)
	if found {
		for j := i; j < len(records); j++ {
			if hash.Eq(records[j].key) {
				k2, _, err := self.kv.Get(records[j].value)
				if err != nil {
					return err
				}
				if key.Eq(k2) {
					if err := self.kv.Remove(records[j].value); err != nil {
						return err
					}
					return self.bt.remove_index(j)
				}
			} else {
				break
			}
		}
	}
	return fmt.Errorf("Key not found")
}
开发者ID:timtadh,项目名称:file-structures,代码行数:24,代码来源:bucket.go


注:本文中的file-structures/block/byteslice.ByteSlice.Eq方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。