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.

54 lines
1.0 KiB

  1. package skiplist
  2. import "bytes"
  3. func compareElement(a *SkipListElement, key []byte) int {
  4. if len(a.Values) == 0 {
  5. return -1
  6. }
  7. if bytes.Compare(a.Values[0], key) < 0 {
  8. return -1
  9. }
  10. if bytes.Compare(a.Values[len(a.Values)-1], key) > 0 {
  11. return 1
  12. }
  13. return 0
  14. }
  15. var (
  16. memStore = make(map[int64]*SkipListElement)
  17. )
  18. func (node *SkipListElement) Reference() *SkipListElementReference {
  19. if node == nil {
  20. return nil
  21. }
  22. return &SkipListElementReference{
  23. ElementPointer: node.Id,
  24. Key: node.Values[0],
  25. }
  26. }
  27. func (node *SkipListElement) Save() {
  28. if node == nil {
  29. return
  30. }
  31. memStore[node.Id] = node
  32. //println("++ node", node.Id, string(node.Values[0]))
  33. }
  34. func (node *SkipListElement) DeleteSelf() {
  35. if node == nil {
  36. return
  37. }
  38. delete(memStore, node.Id)
  39. //println("++ node", node.Id, string(node.Values[0]))
  40. }
  41. func (ref *SkipListElementReference) Load() *SkipListElement {
  42. if ref == nil {
  43. return nil
  44. }
  45. //println("~ node", ref.ElementPointer, string(ref.Key))
  46. return memStore[ref.ElementPointer]
  47. }