use of gnu.trove.TIntHashSet in project intellij-community by JetBrains.
the class IntToIntSetMap method addOccurence.
public void addOccurence(int key, int value) {
if (mySingle.containsKey(key)) {
int old = mySingle.get(key);
TIntHashSet items = new TIntHashSet(3);
items.add(old);
items.add(value);
mySingle.remove(key);
myMulti.put(key, items);
return;
}
final TIntHashSet items = myMulti.get(key);
if (items != null) {
items.add(value);
return;
}
mySingle.put(key, value);
}
use of gnu.trove.TIntHashSet in project intellij-community by JetBrains.
the class IntToIntSetMap method removeOccurence.
public void removeOccurence(int key, int value) {
if (mySingle.containsKey(key)) {
mySingle.remove(key);
return;
}
TIntHashSet items = myMulti.get(key);
if (items != null) {
items.remove(value);
if (items.size() == 1) {
mySingle.put(key, items.toArray()[0]);
myMulti.remove(key);
}
}
}
use of gnu.trove.TIntHashSet in project intellij-community by JetBrains.
the class DefinitionMap method registerDef.
public void registerDef(Instruction varInsn, int varId) {
TIntHashSet defs = myMap.get(varId);
if (defs == null) {
myMap.put(varId, defs = new TIntHashSet());
} else {
defs.clear();
}
defs.add(varInsn.num());
}
use of gnu.trove.TIntHashSet in project intellij-community by JetBrains.
the class ChangeList method iterChanges.
// todo synchronization issue: changeset may me modified while being iterated
public synchronized Iterable<ChangeSet> iterChanges() {
return new Iterable<ChangeSet>() {
public Iterator<ChangeSet> iterator() {
return new Iterator<ChangeSet>() {
private final TIntHashSet recursionGuard = new TIntHashSet(1000);
private ChangeSetHolder currentBlock;
private ChangeSet next = fetchNext();
public boolean hasNext() {
return next != null;
}
public ChangeSet next() {
ChangeSet result = next;
next = fetchNext();
return result;
}
private ChangeSet fetchNext() {
if (currentBlock == null) {
synchronized (ChangeList.this) {
if (myCurrentChangeSet != null) {
currentBlock = new ChangeSetHolder(-1, myCurrentChangeSet);
} else {
currentBlock = myStorage.readPrevious(-1, recursionGuard);
}
}
} else {
synchronized (ChangeList.this) {
currentBlock = myStorage.readPrevious(currentBlock.id, recursionGuard);
}
}
if (currentBlock == null)
return null;
return currentBlock.changeSet;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
}
use of gnu.trove.TIntHashSet in project intellij-community by JetBrains.
the class ChangeListStorageImpl method purge.
public synchronized void purge(long period, int intervalBetweenActivities, Consumer<ChangeSet> processor) {
if (isCompletelyBroken)
return;
TIntHashSet recursionGuard = new TIntHashSet(1000);
try {
int firstObsoleteId = findFirstObsoleteBlock(period, intervalBetweenActivities, recursionGuard);
if (firstObsoleteId == 0)
return;
int eachBlockId = firstObsoleteId;
while (eachBlockId != 0) {
processor.consume(doReadBlock(eachBlockId).changeSet);
eachBlockId = doReadPrevSafely(eachBlockId, recursionGuard);
}
myStorage.deleteRecordsUpTo(firstObsoleteId);
myStorage.force();
} catch (IOException e) {
handleError(e, null);
}
}
Aggregations