Package es.uam.eps.ir.relison.index
Class GenericIndex<T>
java.lang.Object
es.uam.eps.ir.relison.index.GenericIndex<T>
- Type Parameters:
T- Type of the element.
- All Implemented Interfaces:
java.io.Serializable
public class GenericIndex<T>
extends java.lang.Object
implements java.io.Serializable
Bi-map-like structure to back fast version of indexes. It keeps to maps: id-to-index and index-to-id.
Value of indexes go from 0 (included) to the number of elements (excluded).
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
Constructors Constructor Description GenericIndex()Constructor. -
Method Summary
Modifier and Type Method Description intadd(T t)Adds an element to the structure, if it is not in thebooleancontainsId(T t)Checks if the corresponding object is included in the index.java.util.stream.Stream<T>getIds()Gets a stream of objects in the indexintgetIdx(T t)Gets the index of the object.TgetObject(int idx)Gets the object corresponding to the given index.intsize()Gets the size of the index,
-
Field Details
-
Constructor Details
-
GenericIndex
public GenericIndex()Constructor.
-
-
Method Details
-
add
Adds an element to the structure, if it is not in the- Parameters:
t- The element to add.- Returns:
- the index for the corresponding element.
-
getIdx
Gets the index of the object.- Parameters:
t- The object.- Returns:
- the index of the object if it exists, -1 if not.
-
getObject
Gets the object corresponding to the given index.- Parameters:
idx- The index.- Returns:
- the object in that index.
-
containsId
Checks if the corresponding object is included in the index.- Parameters:
t- The object.- Returns:
- true if it exists, false if not.
-
size
public int size()Gets the size of the index,- Returns:
- the size of the index.
-
getIds
Gets a stream of objects in the index- Returns:
- the stream.
-