https://github.com/q191201771/skiplist
跳表
https://github.com/q191201771/skiplist
Last synced: 5 months ago
JSON representation
跳表
- Host: GitHub
- URL: https://github.com/q191201771/skiplist
- Owner: q191201771
- License: mit
- Created: 2016-06-03T13:43:43.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-06-24T05:26:33.000Z (over 9 years ago)
- Last Synced: 2024-12-29T13:02:03.009Z (10 months ago)
- Language: Go
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## skiplist(跳表)
### 接口
```golang
func Default() SkipList
func New(c Compare, maxHeight int) SkipList
/// skip_list.go
type SkipList interface {
Insert(k, v interface{}) error /// nil | `ErrKeyAlreadyExist`.
InsertForce(k, v interface{}) /// if exist already,update its `v`.
Erase(k interface{}) error /// nil | `ErrKeyNotExist`,most of scenario you can ignore it.
Find(k interface{}) (v interface{}, exist bool)
Clear()
Size() int
Empty() bool
Min() (k, v interface{}) /// if Empty(),return nil,nil
Max() (k, v interface{}) /// if Empty(),return nil,nil
SkipListIterator
}
type SkipListIterator interface {
Begin() Iterator /// minimum,or nil if Empty()
End() Iterator /// same as nil
}
/// iterator.go
type Iterator interface {
Next() Iterator /// return's key is bigger than caller's,or nil if not exist
Key() interface{}
Value() interface{}
}
```
简单示例看eg/basic.go,详细请看源码以及对应test。
### 注意
* 迭代器按C++ STL设计,插入/删除后迭代器失效。
### TODO
* vargrind
* benchmark