Gigamap custom type indexers? #442
Answered
by
fh-ms
hrstoyanov
asked this question in
Q&A
|
Gigamap provides built-in indexers for: UUID , Long , etc. But how do I implement a custom indexer for a type like TSID (compact replacement of UUID)? |
Answered by
fh-ms
Jul 30, 2025
Replies: 3 comments
|
The quick version would be this one. The Tsid consists of a single long and is probably of high cardinality, so a binary indexer would be the optimal solution. final static BinaryIndexer<MyEntity> tsidIndex = new BinaryIndexer.Abstract<>()
{
@Override
public long indexBinary(final MyEntity entity)
{
return entity.getTsid().toLong();
}
}; |
0 replies
|
If you want a nice reusable, typed indexer for Tsids, this is the implementation: public abstract class TsidIndexer<E> extends BinaryIndexer.Abstract<E>
{
@Override
public final long indexBinary(final E entity)
{
return this.getTsid(entity).toLong();
}
protected abstract Tsid getTsid(E entity);
public <S extends E> Condition<S> is(final Tsid id)
{
return super.is(id.toLong());
}
}and this the usage final static TsidIndexer<MyEntity> tsidIndex = new TsidIndexer<>()
{
@Override
protected Tsid getTsid(final MyEntity entity)
{
return entity.getTsid();
}
}; |
0 replies
Answer selected by
hrstoyanov
|
@fh-ms what if I have a value of NULL? A binary indexer will not be able to handle this? If I map the NULL Tsid to 0L (long value), the indexer will throw an exception as it expects long values>0 ? My current workaround is to map it to Long.MAX_VALUE, but would prefer 0L. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want a nice reusable, typed indexer for Tsids, this is the implementation:
and this the usage