Search in sources :

Example 1 with IntHashSet

use of jetbrains.exodus.core.dataStructures.hash.IntHashSet in project xodus by JetBrains.

the class PersistentEntityStoreImpl method deleteLinks.

/**
 * Deletes all outgoing links of specified entity.
 *
 * @param entity the entity.
 */
private void deleteLinks(@NotNull final PersistentStoreTransaction txn, @NotNull final PersistentEntity entity) {
    final PersistentEntityId id = entity.getId();
    final int entityTypeId = id.getTypeId();
    final long entityLocalId = id.getLocalId();
    final Transaction envTxn = txn.getEnvironmentTransaction();
    final LinksTable links = getLinksTable(txn, entityTypeId);
    final IntHashSet deletedLinks = new IntHashSet();
    try (Cursor cursor = links.getFirstIndexCursor(envTxn)) {
        for (boolean success = cursor.getSearchKeyRange(PropertyKey.propertyKeyToEntry(new PropertyKey(entityLocalId, 0))) != null; success; success = cursor.getNext()) {
            final ByteIterable keyEntry = cursor.getKey();
            final PropertyKey key = PropertyKey.entryToPropertyKey(keyEntry);
            if (key.getEntityLocalId() != entityLocalId) {
                break;
            }
            final ByteIterable valueEntry = cursor.getValue();
            if (links.delete(envTxn, keyEntry, valueEntry)) {
                int linkId = key.getPropertyId();
                if (getLinkName(txn, linkId) != null) {
                    deletedLinks.add(linkId);
                    final LinkValue linkValue = LinkValue.entryToLinkValue(valueEntry);
                    txn.linkDeleted(entity.getId(), (PersistentEntityId) linkValue.getEntityId(), linkValue.getLinkId());
                }
            }
        }
    }
    for (Integer linkId : deletedLinks) {
        links.deleteAllIndex(envTxn, linkId, entityLocalId);
    }
}
Also used : IntHashSet(jetbrains.exodus.core.dataStructures.hash.IntHashSet) CompressedUnsignedLongByteIterable(jetbrains.exodus.log.CompressedUnsignedLongByteIterable)

Example 2 with IntHashSet

use of jetbrains.exodus.core.dataStructures.hash.IntHashSet in project xodus by JetBrains.

the class TreePutTest method createHugeTree.

@Test
@TestFor(issue = "XD-539")
public void createHugeTree() {
    if (Runtime.getRuntime().maxMemory() < 4000000000L) {
        return;
    }
    tm = createMutableTree(false, 1);
    final IntHashSet set = new IntHashSet();
    final int count = 20000;
    final StringBuilder builder = new StringBuilder("value");
    TestUtil.time("put()", () -> {
        for (int i = 0; i < count; ++i) {
            tm.put(key(Integer.toString(i)), value(builder.toString()));
            set.add(i);
            builder.append(i);
        }
    });
    final long address = saveTree();
    System.out.println("Log size: " + tm.getLog().getHighAddress());
    reopen();
    t = openTree(address, false);
    Assert.assertEquals(set.size(), t.getSize());
    TestUtil.time("get()", () -> {
        for (Integer i : set) {
            assertTrue(t.hasKey(key(Integer.toString(i))));
        }
    });
}
Also used : IntHashSet(jetbrains.exodus.core.dataStructures.hash.IntHashSet) Test(org.junit.Test) TestFor(jetbrains.exodus.TestFor)

Example 3 with IntHashSet

use of jetbrains.exodus.core.dataStructures.hash.IntHashSet in project xodus by JetBrains.

the class PriorityQueueTest method concurrentBenchmark.

@SuppressWarnings("ObjectAllocationInLoop")
@Test
public void concurrentBenchmark() {
    final AtomicInteger counter = new AtomicInteger();
    final PriorityQueue<Priority, TestObject> queue = createQueue();
    final Runnable threadFunction = () -> {
        try {
            // noinspection InfiniteLoopStatement
            while (true) {
                try (Guard ignored = queue.lock()) {
                    final TestObject value = new TestObject(counter);
                    final Priority p;
                    switch(value.number % 5) {
                        case 0:
                            p = Priority.lowest;
                            break;
                        case 1:
                            p = Priority.below_normal;
                            break;
                        case 2:
                            p = Priority.normal;
                            break;
                        case 3:
                            p = Priority.above_normal;
                            break;
                        default:
                            p = Priority.highest;
                            break;
                    }
                    queue.push(p, value);
                }
            }
        } catch (RuntimeException e) {
        // ignore
        }
    };
    TestUtil.time("concurrentBenchmark", () -> {
        final int numberOfThreads = 4;
        final Thread[] threads = new Thread[numberOfThreads];
        for (int i = 0; i < numberOfThreads; ++i) {
            threads[i] = new Thread(threadFunction);
        }
        for (int i = 0; i < numberOfThreads; ++i) {
            threads[i].start();
        }
        for (int i = 0; i < numberOfThreads; ++i) {
            try {
                threads[i].join();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            // ignore
            }
        }
    });
    final IntHashSet numbers = new IntHashSet();
    TestObject to;
    while ((to = queue.pop()) != null) {
        numbers.add(to.number);
    }
    assertEquals(TestObject.MAX_TEST_OBJECTS, numbers.size());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntHashSet(jetbrains.exodus.core.dataStructures.hash.IntHashSet) Guard(jetbrains.exodus.core.execution.locks.Guard) Test(org.junit.Test)

Aggregations

IntHashSet (jetbrains.exodus.core.dataStructures.hash.IntHashSet)3 Test (org.junit.Test)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 TestFor (jetbrains.exodus.TestFor)1 Guard (jetbrains.exodus.core.execution.locks.Guard)1 CompressedUnsignedLongByteIterable (jetbrains.exodus.log.CompressedUnsignedLongByteIterable)1