asclass ConceptFieldIndexBase implements IConceptIndex, IFieldIndex, IConceptCounter {
Concepts concepts;
Class cc;
S field;
new HashMap objectToValue;
MultiSetMap valueToObject; // initialized in subclass
*() { init(); }
*(Class cc, S field) { this(db_mainConcepts(), cc, field); }
*(Concepts *concepts, Class *cc, S *field) {
this();
concepts.addConceptIndex(this);
for (A c : list(concepts, cc))
updateImpl(c);
register();
}
abstract void init();
abstract void register();
public void update(Concept c) {
if (!isInstance(cc, c)) ret;
updateImpl(c);
}
synchronized void updateImpl(Concept c) {
Val newValue = cast cget(c, field);
Val oldValue = objectToValue.get(c);
if (newValue == null || newValue != oldValue) {
valueToObject.remove(oldValue, (A) c);
valueToObject.put(newValue, (A) c);
syncPut(objectToValue, (A) c, newValue);
}
}
public synchronized void remove(Concept c) {
if (!isInstance(cc, c)) ret;
Val value = cast cget(c, field);
syncRemove(objectToValue, (A) c);
valueToObject.remove(value, (A) c);
}
synchronized A get(Val value) {
ret valueToObject.getFirst(value);
}
public synchronized Cl getAll(Val value) {
ret valueToObject.get(value);
}
public synchronized L allValues() { ret cloneKeys_noSync(valueToObject.data); }
IterableIterator objectIterator() {
ret navigableMultiSetMapValuesIterator_concurrent(valueToObject, this);
}
public synchronized MultiSet allValues_multiSet() {
ret multiSetMapToMultiSet(valueToObject);
}
public Class extends Concept> conceptClass() { ret cc; }
public int countConcepts() { ret l(objectToValue); }
public Cl allConcepts() { ret (Cl) keys(objectToValue); }
O mutex() { this; }
}