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.

45 lines
818 B

4 years ago
  1. package bptree
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. type nodeStoreMapImpl struct {
  7. m map[int64]*ProtoNode
  8. }
  9. func (n *nodeStoreMapImpl) PersistFunc(node *BpNode) error {
  10. println("saving node", node.protoNodeId)
  11. n.m[node.protoNodeId] = node.protoNode
  12. return nil
  13. }
  14. func (n *nodeStoreMapImpl) DestroyFunc(node *BpNode) error {
  15. println("delete node", node.protoNodeId)
  16. delete(n.m, node.protoNodeId)
  17. return nil
  18. }
  19. func TestSerDe(t *testing.T) {
  20. nodeStore := &nodeStoreMapImpl{
  21. m: make(map[int64]*ProtoNode),
  22. }
  23. tree := NewBpTree(3, nodeStore)
  24. for i:=0;i<32;i++{
  25. println("add", i)
  26. tree.Add(String(fmt.Sprintf("%02d", i)), nil)
  27. }
  28. for i:=5;i<9;i++{
  29. println("----------", i)
  30. tree.RemoveWhere(String(fmt.Sprintf("%02d", i)), func(value ItemValue) bool {
  31. return true
  32. })
  33. printTree(tree.root, "")
  34. }
  35. }