Ai
1 Star 0 Fork 0

WSRer/simple-hashtable-storage

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
skiplist_index.go 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
WSRer 提交于 2024-10-16 19:14 +08:00 . chore: remove mmap
package shs
import (
"iter"
"github.com/liyue201/gostl/ds/skiplist"
"github.com/liyue201/gostl/utils/comparator"
)
var _ Index = (*SkipListIndex)(nil)
type SkipListIndex skiplist.Skiplist[string, uint64]
func NewSkipListIndex() *SkipListIndex {
return (*SkipListIndex)(skiplist.New[string, uint64](comparator.StringComparator, skiplist.WithMaxLevel(15)))
}
func (s *SkipListIndex) Get(key []byte) (uint64, error) {
list := (*skiplist.Skiplist[string, uint64])(s)
return list.Get(bytesToString(key))
}
func (s *SkipListIndex) Set(key []byte, value uint64) error {
list := (*skiplist.Skiplist[string, uint64])(s)
list.Insert(bytesToString(key), value)
return nil
}
func (s *SkipListIndex) Delete(key []byte) error {
list := (*skiplist.Skiplist[string, uint64])(s)
exists := list.Remove(bytesToString(key))
if !exists {
return ErrKeyNotFound
}
return nil
}
func (s *SkipListIndex) Iterator() iter.Seq2[[]byte, uint64] {
return func(yield func([]byte, uint64) bool) {
list := (*skiplist.Skiplist[string, uint64])(s)
list.Traversal(func(key string, value uint64) bool {
if !yield(stringToBytes(key), value) {
return false
}
return true
})
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/asphodelus_dev/simple-hashtable-storage.git
git@gitee.com:asphodelus_dev/simple-hashtable-storage.git
asphodelus_dev
simple-hashtable-storage
simple-hashtable-storage
v0.1.0

搜索帮助