mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
51 lines
1,002 B
Go
51 lines
1,002 B
Go
package skiplist
|
|
|
|
import "bytes"
|
|
|
|
func compareElement(a *SkipListElement, key []byte) int {
|
|
if len(a.Key) == 0 {
|
|
return -1
|
|
}
|
|
return bytes.Compare(a.Key, key)
|
|
}
|
|
|
|
func (node *SkipListElement) Reference() *SkipListElementReference {
|
|
if node == nil {
|
|
return nil
|
|
}
|
|
return &SkipListElementReference{
|
|
ElementPointer: node.Id,
|
|
Key: node.Key,
|
|
}
|
|
}
|
|
|
|
func (t *SkipList) saveElement(element *SkipListElement) error {
|
|
if element == nil {
|
|
return nil
|
|
}
|
|
return t.listStore.SaveElement(element.Id, element)
|
|
}
|
|
|
|
func (t *SkipList) deleteElement(element *SkipListElement) error {
|
|
if element == nil {
|
|
return nil
|
|
}
|
|
return t.listStore.DeleteElement(element.Id)
|
|
}
|
|
|
|
func (t *SkipList) loadElement(ref *SkipListElementReference) (*SkipListElement, error) {
|
|
if ref.IsNil() {
|
|
return nil, nil
|
|
}
|
|
return t.listStore.LoadElement(ref.ElementPointer)
|
|
}
|
|
|
|
func (ref *SkipListElementReference) IsNil() bool {
|
|
if ref == nil {
|
|
return true
|
|
}
|
|
if len(ref.Key) == 0 {
|
|
return true
|
|
}
|
|
return false
|
|
} |