Mercurial > hg > Members > tatsuki > bench > jungle-core
annotate src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/DeleteChildIndexEditor.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 | 6e9a8d26e0cf |
children | a2c374a2686b |
rev | line source |
---|---|
128 | 1 package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; |
2 | |
134 | 3 import java.util.Iterator; |
4 | |
5 import fj.F; | |
6 import fj.Ord; | |
7 import fj.P2; | |
129 | 8 import fj.data.List; |
134 | 9 import fj.data.Option; |
129 | 10 import fj.data.TreeMap; |
128 | 11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; |
129 | 12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; |
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; | |
134 | 14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; |
129 | 15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; |
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; | |
128 | 17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; |
129 | 18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TransactionManager; |
134 | 19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; |
128 | 20 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; |
21 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | |
129 | 22 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; |
128 | 23 |
24 public class DeleteChildIndexEditor implements IndexEditor { | |
25 | |
134 | 26 NodePath editNodePath; |
27 | |
28 public DeleteChildIndexEditor(int pos, NodePath path) { | |
29 this.editNodePath = path.add(pos); | |
30 } | |
31 | |
128 | 32 @Override |
130 | 33 public Either<Error, IndexJungleTreeEditor> edit( |
129 | 34 TreeNode root, |
35 TransactionManager txManager, | |
36 TreeEditor editor, | |
37 TreeOperationLog log, | |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
135
diff
changeset
|
38 TreeMap<String, TreeMap<String, List<NodePath>>> index) { |
134 | 39 |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
135
diff
changeset
|
40 TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = editIndex(index); |
134 | 41 IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(root, txManager, editor, newIndex); |
42 return DefaultEither.newB(newEditor); | |
43 } | |
44 | |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
135
diff
changeset
|
45 public TreeMap<String, TreeMap<String, List<NodePath>>> editIndex( |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
135
diff
changeset
|
46 TreeMap<String, TreeMap<String, List<NodePath>>> index) { |
134 | 47 |
48 if (!index.isEmpty()) { | |
49 List<String> keyList = index.keys(); | |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
135
diff
changeset
|
50 TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = TreeMap.empty(Ord.stringOrd); |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
135
diff
changeset
|
51 TreeMap<String, List<NodePath>> newInnerIndex = TreeMap.empty(Ord.stringOrd); |
134 | 52 |
53 for (String indexKey : keyList) { | |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
135
diff
changeset
|
54 TreeMap<String, List<NodePath>> innerIndex = index.get(indexKey).some(); |
134 | 55 List<String> innerIndexKeyList = innerIndex.keys(); |
56 | |
57 for (String innerIndexKey : innerIndexKeyList) { | |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
135
diff
changeset
|
58 List<NodePath> pairList = innerIndex.get(innerIndexKey).some(); |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
135
diff
changeset
|
59 List<NodePath> list = checkPath(pairList); |
134 | 60 if (!list.isEmpty()){ |
61 newInnerIndex = newInnerIndex.set(innerIndexKey, list); | |
62 } | |
63 } | |
64 newIndex = newIndex.set(indexKey, newInnerIndex); | |
65 } | |
66 return newIndex; | |
67 } else { | |
68 return index; | |
69 } | |
128 | 70 } |
71 | |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
135
diff
changeset
|
72 public List<NodePath> checkPath(List<NodePath> pairList){ |
129 | 73 |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
135
diff
changeset
|
74 List<NodePath> list = List.nil(); |
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
135
diff
changeset
|
75 for (NodePath path : pairList) { |
134 | 76 |
77 System.out.println("oldPath = " + path.toString()); | |
78 NodePath newPath = new DefaultNodePath(); | |
79 | |
80 if (path.toString().equals(editNodePath.toString())) { | |
81 continue; | |
82 } | |
83 | |
84 if (editNodePath.size() > path.size()) { | |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
135
diff
changeset
|
85 list = list.cons(path); |
134 | 86 continue; |
87 } | |
88 | |
89 Pair<Integer, NodePath> editNodePathCopy = editNodePath.pop(); | |
90 int loopCount = 0; | |
91 | |
92 for (Integer pathInt : path) { | |
93 loopCount++; | |
94 | |
95 if (pathInt == -1) | |
96 continue; | |
97 if (editNodePathCopy.right().size() > 0) { | |
135 | 98 |
134 | 99 editNodePathCopy = editNodePathCopy.right().pop(); |
135 | 100 if (loopCount == editNodePath.size() && editNodePathCopy.left() < pathInt) { |
134 | 101 newPath = newPath.add(pathInt - 1); |
102 continue; | |
103 } | |
104 | |
105 if (!(editNodePathCopy.left() == pathInt)) { | |
106 newPath = path; | |
107 break; | |
108 } | |
109 } | |
110 | |
111 newPath = newPath.add(pathInt); | |
112 | |
113 } | |
114 | |
115 System.out.println("newPath = " + newPath.toString()); | |
143
afbe19c98f53
change Index form TreeMap<String,TreeMap<String<List<Pair<TreeNode,NodePath>>>> → TreeMap<String,TreeMap<String<List<NodePath>>>
one
parents:
135
diff
changeset
|
116 list = list.cons(path); |
134 | 117 } |
118 | |
119 return list; | |
120 } | |
129 | 121 |
128 | 122 } |