Mercurial > hg > Members > tatsuki > bench > jungle-core
changeset 120:f783a27eed24
add IndexTest and FjTreeMapTest
author | one |
---|---|
date | Thu, 02 Oct 2014 17:24:25 +0900 |
parents | 70228f5e081f |
children | 790a73e0c8ec b006861cb795 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/LoggingNode.java src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/functionaljava/FjTreeMapTest.java src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/functionaljava/IndexTest.java |
diffstat | 3 files changed, 154 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/LoggingNode.java Thu Oct 02 17:24:25 2014 +0900 @@ -0,0 +1,19 @@ +package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; + +import fj.data.List; +import fj.data.TreeMap; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; + +public interface LoggingNode { + + public LoggingAttributes getAttributes(); + public LoggingChildren getChildren(); + public OperationLog getOperationLog(); + public TreeNode getWrap(); + public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/functionaljava/FjTreeMapTest.java Thu Oct 02 17:24:25 2014 +0900 @@ -0,0 +1,31 @@ +package jp.ac.u_ryukyu.ie.cr.tatsuki.functionaljava; + +import java.nio.ByteBuffer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; + +import org.junit.Assert; +import org.junit.Test; + +import fj.Ord; +import fj.data.TreeMap; + +public class FjTreeMapTest { + + @Test + public void testTreeMap() { + TreeMap<String,String> map = TreeMap.empty(Ord.stringOrd); + TreeMap<String, String> newMap = map.set("name","tatsuki"); + TreeMap<String, String> newMap2 = map.set("name","kanagawa"); + String str = newMap.get("name").some(); + String str2 = newMap2.get("name").some(); + Assert.assertEquals(str,"tatsuki"); + Assert.assertEquals(str2,"kanagawa"); + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/functionaljava/IndexTest.java Thu Oct 02 17:24:25 2014 +0900 @@ -0,0 +1,104 @@ +package jp.ac.u_ryukyu.ie.cr.tatsuki.functionaljava; + +import java.nio.ByteBuffer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; + +import org.junit.Assert; +import org.junit.Test; + +import fj.Ord; +import fj.data.List; +import fj.data.Option; +import fj.data.TreeMap; + +public class IndexTest { + + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index = TreeMap + .empty(Ord.stringOrd); + + @Test + public void IndexTest() { + + NodePath path = new DefaultNodePath(); + TreeNode node = createTree(3, 0, 3, path); + TreeMap<String, List<Pair<TreeNode, NodePath>>> map = index.get(key).some(); + Option<List<Pair<TreeNode, NodePath>>> opList = map.get("<-1,0,0,2>"); + List<Pair<TreeNode, NodePath>> list = opList.some(); + Pair<TreeNode, NodePath> Pair = list.head(); + NodePath newPath = Pair.right(); + String pathStr = newPath.toString(); + Assert.assertEquals(pathStr,"<-1,0,0,2>"); + System.out.println("aaa"); + } + + public static String key = "KEY"; + public static ByteBuffer value = ByteBuffer.wrap(key.getBytes()); + public static DefaultTreeNode factory = new DefaultTreeNode(); + + public TreeNode createTree(int _curX, int _curY, int _maxHeight, + NodePath _address) { + TreeNode parent = factory.createNewNode(); + Either<Error, TreeNode> either = parent.getAttributes().put(key,ByteBuffer.wrap(_address.toString().getBytes())); + if (either.isA()) { + Assert.fail(); + } + editIndex(parent, _address, _address.toString(), key); + parent = either.b(); + + if (_curY == _maxHeight) { + return parent; + } + + for (int i = 0; i < _curY + 1; i++) { + TreeNode ch = createTree(i, _curY + 1, _maxHeight, _address.add(i)); + either = parent.getChildren().addNewChildAt(i, ch); + if (either.isA()) { + Assert.fail(); + } + + parent = either.b(); + } + + return parent; + } + + public void editIndex(TreeNode node, NodePath path, String attribute,String key) { + + Pair<TreeNode, NodePath> pair = new Pair<TreeNode, NodePath>(node, path); + Option<TreeMap<String, List<Pair<TreeNode, NodePath>>>> opAttributeList = index.get(key); + + if (opAttributeList.isNone()) { + TreeMap<String, List<Pair<TreeNode, NodePath>>> nodeIndex = TreeMap.empty(Ord.stringOrd); + List<Pair<TreeNode, NodePath>> list = List.nil(); + list = list.cons(pair); + nodeIndex = nodeIndex.set(attribute, list); + index = index.set(key, nodeIndex); + } else { + TreeMap<String, List<Pair<TreeNode, NodePath>>> indexMap = opAttributeList.some(); + Option<List<Pair<TreeNode, NodePath>>> opNodeIndex = indexMap.get(attribute); + + if (opNodeIndex.isNone()) { + List<Pair<TreeNode, NodePath>> pairList = List.nil(); + pairList = pairList.cons(pair); + indexMap = indexMap.set(attribute, pairList); + + } else { + List<Pair<TreeNode, NodePath>> pairList = opNodeIndex.some(); + pairList = pairList.cons(pair); + indexMap = indexMap.set(attribute, pairList); + } + index = index.set(key, indexMap); + } + System.out.println(attribute); + + } + +}