use of jetbrains.exodus.entitystore.Entity in project xodus by JetBrains.
the class InMemoryQuickSortTwoSidesIterable method iterator.
@Override
public Iterator<Entity> iterator() {
return new Iterator<Entity>() {
private List<Entity> src;
private Entity[] tmp;
private int current;
@Override
public boolean hasNext() {
if (src == null) {
init();
}
return current < src.size();
}
@Override
public Entity next() {
if (src == null) {
init();
}
if (current >= src.size()) {
throw new NoSuchElementException();
}
return src.get(current++);
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
public void init() {
src = new ArrayList<>();
for (final Entity entity : source) {
src.add(entity);
}
tmp = new Entity[src.size()];
qsort(0, tmp.length - 1);
}
/**
* sort src[left..right]
* @param left left
* @param right right
*/
public void qsort(int left, int right) {
if (left >= right) {
return;
}
Entity median = src.get((left + right) / 2);
int i = left;
int j = right;
int toRight = 0;
int toLeft = 0;
List<Entity> leftMedians = new ArrayList<>();
List<Entity> rightMedians = new ArrayList<>();
do {
while (i <= j && comparator.compare(src.get(i), median) < 0) {
if (toRight + leftMedians.size() > 0) {
src.set(i - toRight - leftMedians.size(), src.get(i));
}
i++;
}
while (i <= j && comparator.compare(median, src.get(j)) < 0) {
if (toLeft + rightMedians.size() > 0) {
src.set(j + toLeft + rightMedians.size(), src.get(j));
}
j--;
}
// src[i] >= median and src[j] <= median
if (i <= j) {
Entity leftEntity = src.get(i);
if (comparator.compare(leftEntity, median) == 0) {
leftMedians.add(leftEntity);
} else {
tmp[toRight++] = leftEntity;
}
i++;
}
if (i <= j) {
Entity rightEntity = src.get(j);
if (comparator.compare(rightEntity, median) == 0) {
rightMedians.add(rightEntity);
} else {
tmp[right - toLeft++] = src.get(j);
}
j--;
}
} while (i <= j);
// i == j + 1
int current = i - toRight - leftMedians.size();
for (int k = right - toLeft + 1; k <= right; k++) {
src.set(current++, tmp[k]);
}
for (Entity e : leftMedians) {
src.set(current++, e);
}
for (int k = rightMedians.size() - 1; k >= 0; k--) {
src.set(current++, rightMedians.get(k));
}
for (int k = 0; k < toRight; k++) {
src.set(current++, tmp[k]);
}
qsort(left, i - toRight - leftMedians.size() + toLeft);
qsort(current - toRight, right);
}
};
}
use of jetbrains.exodus.entitystore.Entity in project xodus by JetBrains.
the class InMemoryMergeSortOnInitIterable method iterator.
@Override
public Iterator<Entity> iterator() {
return new Iterator<Entity>() {
private List<Entity>[] src;
private int current;
@Override
public boolean hasNext() {
if (src == null) {
init();
}
return current < src[0].size();
}
@Override
public Entity next() {
if (src == null) {
init();
}
if (current >= src[0].size()) {
throw new NoSuchElementException();
}
return src[0].get(current++);
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
public void init() {
src = new ArrayList[] { new ArrayList<>(), null };
for (final Entity entity : source) {
src[0].add(entity);
}
src[1] = new ArrayList<>(src[0]);
msort(0, src[0].size() - 1, 0);
}
/**
* sort interval left..right to src[c][left..right]
* @param left left
* @param right right
* @param c c
*/
public void msort(int left, int right, int c) {
if (left >= right) {
for (int i = left; i <= right; i++) {
src[c].set(i, src[1 - c].get(i));
}
return;
}
int rStart = (left + right + 1) / 2;
msort(left, rStart - 1, 1 - c);
msort(rStart, right, 1 - c);
int i = left;
int j = rStart;
for (int k = left; k <= right; k++) {
if ((j > right) || ((i < rStart) && (comparator.compare(src[1 - c].get(i), src[1 - c].get(j)) <= 0))) {
src[c].set(k, src[1 - c].get(i++));
} else {
src[c].set(k, src[1 - c].get(j++));
}
}
}
};
}
use of jetbrains.exodus.entitystore.Entity in project xodus by JetBrains.
the class InMemoryQuickSortOnInitIterable method iterator.
@Override
public Iterator<Entity> iterator() {
return new Iterator<Entity>() {
private List<Entity> src;
private Entity[] tmp;
private int current;
@Override
public boolean hasNext() {
if (src == null) {
init();
}
return current < src.size();
}
@Override
public Entity next() {
if (src == null) {
init();
}
if (current >= src.size()) {
throw new NoSuchElementException();
}
return src.get(current++);
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
public void init() {
src = new ArrayList<>();
for (final Entity entity : source) {
src.add(entity);
}
tmp = new Entity[src.size()];
qsort(0, tmp.length - 1);
}
/**
* sort src[left..right]
* @param left left
* @param right right
*/
public void qsort(int left, int right) {
if (left >= right) {
return;
}
Entity median = src.get((left + right) / 2);
int i = left;
int toRight = 0;
List<Entity> medians = new ArrayList<>();
do {
while (i <= right && comparator.compare(src.get(i), median) < 0) {
if (toRight + medians.size() > 0) {
src.set(i - toRight - medians.size(), src.get(i));
}
i++;
}
// src[i] >= median
if (i <= right) {
Entity entity = src.get(i);
if (comparator.compare(entity, median) == 0) {
medians.add(entity);
} else {
tmp[toRight++] = entity;
}
i++;
}
} while (i <= right);
// i == right + 1
int current = i - toRight - medians.size();
for (Entity e : medians) {
src.set(current++, e);
}
for (int k = 0; k < toRight; k++) {
src.set(current++, tmp[k]);
}
qsort(left, right - toRight - medians.size());
qsort(right - toRight + 1, right);
}
};
}
use of jetbrains.exodus.entitystore.Entity in project meghanada-server by mopemope.
the class ProjectDatabase method deleteObject.
public boolean deleteObject(String entityType, String id) throws Exception {
return this.entityStore.computeInTransaction(txn -> {
EntityIterable it = txn.find(entityType, ID, id);
Entity entity = it.getFirst();
if (isNull(entity)) {
return false;
}
return entity.delete();
});
}
use of jetbrains.exodus.entitystore.Entity in project meghanada-server by mopemope.
the class ProjectDatabase method findAllObject.
public <T> void findAllObject(String entityType, Class<T> clazz, Consumer<T> consumer) throws Exception {
this.entityStore.executeInReadonlyTransaction(txn -> {
EntityIterable all = txn.getAll(entityType);
for (Entity entity : all) {
try (InputStream in = entity.getBlob(SERIALIZE_KEY)) {
T t = Serializer.readObject(in, clazz);
consumer.accept(t);
} catch (Exception e) {
log.warn(e.getMessage());
}
}
});
}
Aggregations