2021-10-02 21:02:56 +00:00
|
|
|
package skiplist
|
|
|
|
|
|
|
|
import "bytes"
|
|
|
|
|
|
|
|
func compareElement(a *SkipListElement, key []byte) int {
|
2021-10-03 08:07:35 +00:00
|
|
|
if len(a.Key) == 0 {
|
2021-10-02 21:02:56 +00:00
|
|
|
return -1
|
|
|
|
}
|
2021-10-03 08:07:35 +00:00
|
|
|
return bytes.Compare(a.Key, key)
|
2021-10-02 21:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
memStore = make(map[int64]*SkipListElement)
|
|
|
|
)
|
|
|
|
|
|
|
|
func (node *SkipListElement) Reference() *SkipListElementReference {
|
|
|
|
if node == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &SkipListElementReference{
|
|
|
|
ElementPointer: node.Id,
|
2021-10-03 08:07:35 +00:00
|
|
|
Key: node.Key,
|
2021-10-02 21:02:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
func (node *SkipListElement) Save() {
|
|
|
|
if node == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
memStore[node.Id] = node
|
|
|
|
//println("++ node", node.Id, string(node.Values[0]))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (node *SkipListElement) DeleteSelf() {
|
|
|
|
if node == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
delete(memStore, node.Id)
|
|
|
|
//println("++ node", node.Id, string(node.Values[0]))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ref *SkipListElementReference) Load() *SkipListElement {
|
|
|
|
if ref == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
//println("~ node", ref.ElementPointer, string(ref.Key))
|
|
|
|
return memStore[ref.ElementPointer]
|
|
|
|
}
|
|
|
|
|