Mercurial > hg > Members > tatsuki > bench > jungle-core
comparison src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/PutIndexEditor.java @ 143:afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
bag
author | one |
---|---|
date | Sat, 15 Nov 2014 17:48:07 +0900 |
parents | 99bda30ea72c |
children |
comparison
equal
deleted
inserted
replaced
142:ef183969bf31 | 143:afbe19c98f53 |
---|---|
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; | 13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; |
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TransactionManager; | 14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TransactionManager; |
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; | 15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; |
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | 16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; |
17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | 17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; |
18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; | |
19 | 18 |
20 import java.nio.ByteBuffer; | 19 import java.nio.ByteBuffer; |
21 | 20 |
22 public class PutIndexEditor implements IndexEditor { | 21 public class PutIndexEditor implements IndexEditor { |
23 | 22 |
34 this.attribute = new String(attribute.array()); | 33 this.attribute = new String(attribute.array()); |
35 this.path = path; | 34 this.path = path; |
36 } | 35 } |
37 | 36 |
38 @Override | 37 @Override |
39 public Either<Error, IndexJungleTreeEditor> edit(TreeNode root,TransactionManager txManager,TreeEditor editor,TreeOperationLog log,TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) { | 38 public Either<Error, IndexJungleTreeEditor> edit(TreeNode root,TransactionManager txManager,TreeEditor editor,TreeOperationLog log,TreeMap<String, TreeMap<String, List<NodePath>>> index) { |
40 NodePath newPath = path.pop().right(); | 39 TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = editIndex(path, key, attribute,index); |
41 TreeNode target = getTarget(root, newPath); | |
42 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = editIndex(target, path, key, attribute,index); | |
43 IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(root,txManager,editor,log, newIndex); | 40 IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(root,txManager,editor,log, newIndex); |
44 Either<Error, IndexJungleTreeEditor> either = DefaultEither.newB(newEditor); | 41 Either<Error, IndexJungleTreeEditor> either = DefaultEither.newB(newEditor); |
45 return either; | 42 return either; |
46 } | 43 } |
47 | 44 |
48 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> editIndex(TreeNode target, NodePath path, String key, String attribute,TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index){ | 45 public TreeMap<String, TreeMap<String, List<NodePath>>> editIndex(NodePath path, String key, String attribute,TreeMap<String, TreeMap<String, List<NodePath>>> index){ |
49 | 46 |
50 Option<TreeMap<String, List<Pair<TreeNode, NodePath>>>> innerIndexOp = index.get(key); | 47 Option<TreeMap<String, List<NodePath>>> innerIndexOp = index.get(key); |
51 Pair<TreeNode, NodePath> pathNode = new Pair<TreeNode, NodePath>(target,path); | |
52 | 48 |
53 if (attribute != null) { | 49 if (attribute != null) { |
54 if (innerIndexOp.isNone()) { | 50 if (innerIndexOp.isNone()) { |
55 | 51 |
56 TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = TreeMap.empty(Ord.stringOrd); | 52 TreeMap<String, List<NodePath>> innerIndex = TreeMap.empty(Ord.stringOrd); |
57 List<Pair<TreeNode, NodePath>> list = List.nil(); | 53 List<NodePath> list = List.nil(); |
58 list = list.cons(pathNode); | 54 list = list.cons(path); |
59 innerIndex = innerIndex.set(attribute, list); | 55 innerIndex = innerIndex.set(attribute, list); |
60 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = index.set(key, innerIndex); | 56 TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = index.set(key, innerIndex); |
61 return newIndex; | 57 return newIndex; |
62 } else { | 58 } else { |
63 | 59 |
64 TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = innerIndexOp.some(); | 60 TreeMap<String, List<NodePath>> innerIndex = innerIndexOp.some(); |
65 | 61 |
66 Option<List<Pair<TreeNode, NodePath>>> opList = innerIndex.get(attribute); | 62 Option<List<NodePath>> opList = innerIndex.get(attribute); |
67 | 63 |
68 if (opList.isNone()) { | 64 if (opList.isNone()) { |
69 | 65 |
70 List<Pair<TreeNode, NodePath>> list = List.nil(); | 66 List<NodePath> list = List.nil(); |
71 list = list.cons(pathNode); | 67 list = list.cons(path); |
72 innerIndex = innerIndex.set(attribute, list); | 68 innerIndex = innerIndex.set(attribute, list); |
73 | 69 |
74 } else { | 70 } else { |
75 | 71 |
76 List<Pair<TreeNode, NodePath>> list = opList.some(); | 72 List<NodePath> list = opList.some(); |
77 list = list.cons(pathNode); | 73 list = list.cons(path); |
78 innerIndex = innerIndex.set(attribute, list); | 74 innerIndex = innerIndex.set(attribute, list); |
79 | 75 |
80 } | 76 } |
81 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = index.set(key, innerIndex); | 77 TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = index.set(key, innerIndex); |
82 return newIndex; | 78 return newIndex; |
83 } | 79 } |
84 } | 80 } |
85 return index; | 81 return index; |
86 } | 82 } |
87 | 83 |
88 public TreeNode getTarget(TreeNode node , NodePath path){ | 84 // public TreeNode getTarget(TreeNode node , NodePath path){ |
89 Pair<Integer, NodePath> pathNode = path.pop(); | 85 // Pair<Integer, NodePath> path = path.pop(); |
90 Either<Error, TreeNode> either = node.getChildren().at(pathNode.left()); | 86 // Either<Error, TreeNode> either = node.getChildren().at(path.left()); |
91 if (either.isA()) | 87 // if (either.isA()) |
92 return node; | 88 // return node; |
93 | 89 // |
94 TreeNode child = either.b(); | 90 // TreeNode child = either.b(); |
95 if (pathNode.right().size() == 0) | 91 // if (path.right().size() == 0) |
96 return child; | 92 // return child; |
97 | 93 // |
98 TreeNode target = getTarget(child,pathNode.right()); | 94 // TreeNode target = getTarget(child,path.right()); |
99 return target; | 95 // return target; |
100 } | 96 // } |
101 | 97 |
102 } | 98 } |