sclass ConceptFieldIndex implements IConceptIndex, IFieldIndex, IConceptCounter {
Class cc;
S field;
new HashMap objectToValue;
new MultiSetMap valueToObject;
*() {}
*(Class cc, S field) { this(mainConcepts, cc, field); }
*(Concepts concepts, Class *cc, S *field) {
concepts.addConceptIndex(this);
for (A c : list(concepts, cc))
updateImpl(c);
concepts.addFieldIndex(cc, field, this);
}
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);
objectToValue.put((A) c, newValue);
}
}
public synchronized void remove(Concept c) {
if (!isInstance(cc, c)) ret;
Val value = cast cget(c, field);
objectToValue.remove(c);
valueToObject.remove(value, (A) c);
}
synchronized A get(Val value) {
ret valueToObject.getFirst(value);
}
public synchronized L getAll(Val value) {
ifdef ConceptFieldIndex_debug
L l = valueToObject.get(value);
print("index getAll " + value + " => " + l(l));
ret l;
endifdef
ifndef ConceptFieldIndex_debug
ret valueToObject.get(value);
endifndef
}
public synchronized L allValues() { ret cloneKeys_noSync(valueToObject.data); }
public synchronized MultiSet allValues_multiSet() {
ret multiSetMapToMultiSet(valueToObject);
}
public Class extends Concept> conceptClass() { ret cc; }
public int countConcepts() { ret l(objectToValue); }
public Collection allConcepts() { ret (Collection) keys(objectToValue); }
}