# Interface IndexBag

All Known Implementing Classes:
  `BitSetBag, IntegerBag, LongBag, MultiBitSetBag`

public interface IndexBag
Interface for an object capable of storing a set of distinct integer values. Depending on the implementation, there may be restrictions on the range of indices that can be accommodated.

Since:
  28 Jan 2025
Author:
  Mark Taylor

## Method Summary

Modifier and Type
Method
Description
`void`
`addIndex(long index)`
Adds an index to this bag.
`long`
`getCount()`
Returns the number of distinct indices in this bag.
`boolean`
`hasIndex(long index)`
Indicates whether the given index has previously been added to this bag.
`PrimitiveIterator.OfLong`
`sortedLongIterator()`
Returns an iterator over all the integers added to this bag, supplied in ascending order.

## Method Details

### addIndex

void addIndex(long index)
Adds an index to this bag. If the index is already present, there is no effect.

If the index is outside of the range permitted by this bag, behaviour is undefined.

Parameters:
  `index` - integer to add

### hasIndex

boolean hasIndex(long index)
Indicates whether the given index has previously been added to this bag.

If the index is outside of the range permitted by this bag, behaviour is undefined.

Parameters:
  `index` - integer to check
Returns:
  true iff the given index has previously been added

### sortedLongIterator

PrimitiveIterator.OfLong sortedLongIterator()
Returns an iterator over all the integers added to this bag, supplied in ascending order.

Returns:
  sorted iterator over indices

### getCount

long getCount()
Returns the number of distinct indices in this bag.

Returns:
  count of added integers