Dart Documentationclean_dataHashIndex<E>

HashIndex<E> class

Really simple inverted index implementation.

class HashIndex<E> {
 HashIndex();

 /**
  * Holds the mapping of values to data objects.
  */
 Map<dynamic, Set<E>> _index = new Map<dynamic, Set<E>>();

 /**
  * Returns a set of objects that have this value. If no such
  * object exists, empty Set is returned.
  */
 Set<E> operator[](dynamic value) => _index.containsKey(value) ?
                                     _index[value] :
                                     new Set<E>();

 /**
  * Adds a [value] to [object] mapping to the index.
  */
 void add(dynamic value, E object) {
   if (!_index.containsKey(value)) {
     _index[value] = new Set<E>();
   }

   _index[value].add(object);
 }

 /**
  * Removes a [value] to [object] mapping from the index.
  */
 void remove(dynamic value, E object) {
   if (_index.containsKey(value)) {
     _index[value].remove(object);
   }
 }
}

Constructors

new HashIndex() #

Creates a new Object instance.

Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.

docs inherited from Object
HashIndex();

Operators

Set<E> operator [](value) #

Returns a set of objects that have this value. If no such object exists, empty Set is returned.

Set<E> operator[](dynamic value) => _index.containsKey(value) ?
                                   _index[value] :
                                   new Set<E>();

Methods

void add(value, E object) #

Adds a value to object mapping to the index.

void add(dynamic value, E object) {
 if (!_index.containsKey(value)) {
   _index[value] = new Set<E>();
 }

 _index[value].add(object);
}

void remove(value, E object) #

Removes a value to object mapping from the index.

void remove(dynamic value, E object) {
 if (_index.containsKey(value)) {
   _index[value].remove(object);
 }
}