F
- the concrete factory type which extends this interfacepublic interface ByteHashFactory<F extends ByteHashFactory<F>> extends HashContainerFactory<F>
byte
keys.
Currently ByteHashFactory
allows to specify consecutive range of keys which could be
inserted into hash container - keys domain. This is a performance hint:
hash containers might, but aren't required to throw IllegalArgumentException
on inserting a key out of the keys domain.
By default, all keys are allowed (keys domain is a whole range of byte
s, from
Byte.MIN_VALUE
to Byte.MAX_VALUE
.
For example, map keys or elements of the set could be unique IDs, counting from 1, thus it's guaranteed that these keys are positive. Or one specific key has a special meaning in the logic of your application. When you are sure that some keys range could never be put into hash container, it is recommended to configure corresponding factory, which extends this interface, with complement of that range as keys domain (or, alternatively, with that range as keys domain complement).
It's OK to specify keys domain which include some actually impossible keys, but you shouldn't leave a single valid key out of the domain. If the set of possible (impossible) keys consist of several ranges, and/or standalone keys, it is still recommended to specify the domain to "forbid" some impossible keys. For example, if possible keys are odd numbers, you should exclude one even number, zero:
factory = factory.withKeysDomainComplement((byte) 0, (byte) 0);
Modifier and Type | Method and Description |
---|---|
byte |
getLowerKeyDomainBound()
Returns lower (inclusive) bound of keys domain.
|
byte |
getUpperKeyDomainBound()
Returns upper (inclusive) bound of keys domain.
|
F |
withKeysDomain(byte minPossibleKey,
byte maxPossibleKey)
Returns a copy of this factory with keys domain set to the specified range.
|
F |
withKeysDomainComplement(byte minImpossibleKey,
byte maxImpossibleKey)
Returns a copy of this factory with keys domain set to the complement of the specified range.
|
getHashConfig, withHashConfig
getDefaultExpectedSize, withDefaultExpectedSize
byte getLowerKeyDomainBound()
Default: Byte.MIN_VALUE
.
byte getUpperKeyDomainBound()
Default: Byte.MAX_VALUE
.
F withKeysDomain(byte minPossibleKey, byte maxPossibleKey)
This is a performance hint: hash containers might, but aren't required to throw
IllegalArgumentException
on putting key out of the keys domain.
Example:
// only positive keys
factory = factory.withKeysDomain((byte) 1, Byte.MAX_VALUE);
minPossibleKey
- lower (inclusive) bound of the target keys domainmaxPossibleKey
- upper (inclusive) bound of the target keys domainIllegalArgumentException
- if minPossibleKey
is greater
than maxPossibleKey
F withKeysDomainComplement(byte minImpossibleKey, byte maxImpossibleKey)
This is a performance hint: hash containers might, but aren't required to throw
IllegalArgumentException
on putting key out of the keys domain.
This method is needed to specify keys domain that include both Byte.MIN_VALUE
and Byte.MAX_VALUE
, but with a "hole" somewhere in between. Providing a single
withKeysDomain(byte, byte)
method for this and "ordinary" keys domain application
is error-prone, because there is no way to distinguish intention (domain with a "hole")
and mistakenly reordered arguments while attempting to specify "ordinary" domain.
Example:
// any keys except 0
factory = factory.withKeysDomainComplement((byte) 0, (byte) 0);
minImpossibleKey
- upper (exclusive) bound of the target keys domainmaxImpossibleKey
- lower (exclusive) bound of the target keys domainIllegalArgumentException
- if minImpossibleKey
is greater
than maxImpossibleKey