You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1003 B

3 years ago
  1. package skiplist
  2. import "bytes"
  3. func compareElement(a *SkipListElement, key []byte) int {
  4. if len(a.Key) == 0 {
  5. return -1
  6. }
  7. return bytes.Compare(a.Key, key)
  8. }
  9. func (node *SkipListElement) Reference() *SkipListElementReference {
  10. if node == nil {
  11. return nil
  12. }
  13. return &SkipListElementReference{
  14. ElementPointer: node.Id,
  15. Key: node.Key,
  16. }
  17. }
  18. func (t *SkipList) SaveElement(element *SkipListElement) error {
  19. if element == nil {
  20. return nil
  21. }
  22. return t.ListStore.SaveElement(element.Id, element)
  23. }
  24. func (t *SkipList) DeleteElement(element *SkipListElement) error {
  25. if element == nil {
  26. return nil
  27. }
  28. return t.ListStore.DeleteElement(element.Id)
  29. }
  30. func (t *SkipList) LoadElement(ref *SkipListElementReference) (*SkipListElement, error) {
  31. if ref.IsNil() {
  32. return nil, nil
  33. }
  34. return t.ListStore.LoadElement(ref.ElementPointer)
  35. }
  36. func (ref *SkipListElementReference) IsNil() bool {
  37. if ref == nil {
  38. return true
  39. }
  40. if len(ref.Key) == 0 {
  41. return true
  42. }
  43. return false
  44. }