Search in sources :

Example 1 with Index

use of com.tvd12.dahlia.core.entity.Index in project ezyfox-server by youngmonkeys.

the class EzyAccessAppControllerTest method newRequest.

protected EzySimpleAccessAppRequest newRequest(int index) {
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("user" + index);
    user.setZoneId(1);
    EzyArray params = EzyEntityFactory.newArrayBuilder().append("test").build();
    EzySimpleAccessAppRequest request = new EzySimpleAccessAppRequest();
    request.setUser(user);
    request.setSession(session);
    request.deserializeParams(params);
    return request;
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleAccessAppRequest(com.tvd12.ezyfoxserver.request.EzySimpleAccessAppRequest)

Example 2 with Index

use of com.tvd12.dahlia.core.entity.Index in project dahlia by youngmonkeys.

the class BTreeSequentialAccessTest method test.

@Test
public void test() {
    BTree<Integer, Integer> tree = new BTree<>(4);
    System.out.println("sequential access 1st:\n");
    tree.walk(e -> {
        System.out.print(e + " ");
    });
    tree.walkReverse(e -> {
        System.out.print(e + " ");
    });
    for (int i = 1; i <= 100; ++i) tree.insert(i, i);
    System.out.println("\nsequential access 2nd:\n");
    tree.walk(e -> {
        System.out.print(e + " ");
    });
    System.out.println("\nsequential access 3rd:\n");
    for (int i = 1; i <= 100; ++i) {
        final int index = i;
        tree.walk(new TreeWalker<Integer, Integer>() {

            AtomicInteger count = new AtomicInteger();

            @Override
            public void accept(Tree.Entry<Integer, Integer> e) {
                System.out.print(e + " ");
                count.incrementAndGet();
            }

            @Override
            public boolean next() {
                return count.get() < index;
            }
        });
        System.out.println();
    }
    System.out.println("\n\n========================================\n\n");
    for (int i = 1; i <= 100; ++i) {
        final int index = i;
        tree.walkReverse(new TreeWalker<Integer, Integer>() {

            AtomicInteger count = new AtomicInteger();

            @Override
            public void accept(Tree.Entry<Integer, Integer> e) {
                System.out.print(e + " ");
                count.incrementAndGet();
            }

            @Override
            public boolean next() {
                return count.get() < index;
            }
        });
        System.out.println();
    }
    System.out.println("\n\n========================================\n\n");
    tree.walkReverse(new TreeWalker<Integer, Integer>() {

        @Override
        public void accept(Tree.Entry<Integer, Integer> e) {
            System.out.print(e + " ");
        }

        @Override
        public boolean next() {
            return true;
        }
    });
    tree.delete(20);
    tree.delete(21);
    tree.delete(22);
    System.out.println("\n\n========================================\n\n");
    tree.walkReverse(new TreeWalker<Integer, Integer>() {

        @Override
        public void accept(Tree.Entry<Integer, Integer> e) {
            System.out.print(e + " ");
        }

        @Override
        public boolean next() {
            return true;
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BTree(com.tvd12.dahlia.core.btree.BTree) Tree(com.tvd12.dahlia.core.tree.Tree) BTree(com.tvd12.dahlia.core.btree.BTree) Test(org.testng.annotations.Test)

Example 3 with Index

use of com.tvd12.dahlia.core.entity.Index in project dahlia by youngmonkeys.

the class BTreePrinter method visitNode.

private void visitNode(BTreeProxy.NodeProxy node, List<List<BTreeProxy.NodeProxy>> treeTiers, int index) {
    List<NodeProxy> children = node.getChildren();
    if (children.isEmpty())
        return;
    List<BTreeProxy.NodeProxy> current = null;
    if (treeTiers.size() > index)
        current = treeTiers.get(index);
    else
        treeTiers.add((current = new ArrayList<>()));
    current.addAll(children);
    for (BTreeProxy.NodeProxy child : children) visitNode(child, treeTiers, index + 1);
}
Also used : ArrayList(java.util.ArrayList) NodeProxy(com.tvd12.dahlia.core.btree.BTreeProxy.NodeProxy) NodeProxy(com.tvd12.dahlia.core.btree.BTreeProxy.NodeProxy)

Example 4 with Index

use of com.tvd12.dahlia.core.entity.Index in project dahlia by youngmonkeys.

the class CollectionFactory method createCollection.

public Collection createCollection(CollectionSetting setting) {
    Collection collection = new Collection(setting);
    Map<String, IndexSetting> indexes = setting.getIndexes();
    for (String indexName : indexes.keySet()) {
        IndexSetting indexSetting = indexes.get(indexName);
        Index index = new Index(indexSetting);
        collection.addIndex(index);
    }
    return collection;
}
Also used : Collection(com.tvd12.dahlia.core.entity.Collection) Index(com.tvd12.dahlia.core.entity.Index) IndexSetting(com.tvd12.dahlia.core.setting.IndexSetting)

Example 5 with Index

use of com.tvd12.dahlia.core.entity.Index in project dahlia by youngmonkeys.

the class Indexes method addIndex.

public void addIndex(Index index) {
    IndexSetting setting = index.getSetting();
    String indexName = setting.getIndexName();
    Map<String, Boolean> fields = setting.getFields();
    this.indexesByName.put(indexName, index);
    this.indexBySetting.put(setting, index);
    for (String fieldName : fields.keySet()) {
        this.indexesByFieldName.computeIfAbsent(fieldName, k -> new HashSet<>()).add(index);
    }
}
Also used : HashSet(java.util.HashSet) IndexSetting(com.tvd12.dahlia.core.setting.IndexSetting) Map(java.util.Map) Set(java.util.Set) HashMap(java.util.HashMap) IndexSetting(com.tvd12.dahlia.core.setting.IndexSetting) HashSet(java.util.HashSet)

Aggregations

IndexSetting (com.tvd12.dahlia.core.setting.IndexSetting)2 BTree (com.tvd12.dahlia.core.btree.BTree)1 NodeProxy (com.tvd12.dahlia.core.btree.BTreeProxy.NodeProxy)1 Collection (com.tvd12.dahlia.core.entity.Collection)1 Index (com.tvd12.dahlia.core.entity.Index)1 Tree (com.tvd12.dahlia.core.tree.Tree)1 EzyArray (com.tvd12.ezyfox.entity.EzyArray)1 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)1 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)1 EzySimpleAccessAppRequest (com.tvd12.ezyfoxserver.request.EzySimpleAccessAppRequest)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.testng.annotations.Test)1