| | |
| | | * The IDs are stored here in an array in ascending order. |
| | | * A null array implies not defined, rather than zero IDs. |
| | | */ |
| | | private long[] values = null; |
| | | private long[] values; |
| | | |
| | | /** |
| | | * The size of the set when it is not defined. This value is only maintained |
| | |
| | | * The database key containing this set, if the set was constructed |
| | | * directly from the database. |
| | | */ |
| | | private ByteString keyBytes; |
| | | private final ByteString keyBytes; |
| | | |
| | | /** |
| | | * Create a new undefined set. |
| | | */ |
| | | /** Create a new undefined set. */ |
| | | public EntryIDSet() |
| | | { |
| | | values = null; |
| | | undefinedSize = Long.MAX_VALUE; |
| | | this.keyBytes = null; |
| | | this.undefinedSize = Long.MAX_VALUE; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public EntryIDSet(long size) |
| | | { |
| | | values = null; |
| | | undefinedSize = size; |
| | | this.keyBytes = null; |
| | | this.undefinedSize = size; |
| | | } |
| | | |
| | | /** |
| | |
| | | if (bytes.length() == 0) |
| | | { |
| | | // Entry limit has exceeded and there is no encoded undefined set size. |
| | | values = null; |
| | | undefinedSize = Long.MAX_VALUE; |
| | | } |
| | | else if ((bytes.byteAt(0) & 0x80) == 0x80) |
| | | { |
| | | // Entry limit has exceeded and there is an encoded undefined set size. |
| | | values = null; |
| | | undefinedSize = |
| | | JebFormat.entryIDUndefinedSizeFromDatabase(bytes.toByteArray()); |
| | | } |
| | |
| | | */ |
| | | EntryIDSet(long[] values, int pos, int len) |
| | | { |
| | | this.keyBytes = null; |
| | | this.values = new long[len]; |
| | | System.arraycopy(values, pos, this.values, 0, len); |
| | | } |
| | |
| | | return true; |
| | | } |
| | | |
| | | long id = entryID.longValue(); |
| | | if (values.length == 0 || id > values[values.length - 1]) |
| | | { |
| | | return false; |
| | | } |
| | | return Arrays.binarySearch(values, id) >= 0; |
| | | final long id = entryID.longValue(); |
| | | return values.length != 0 |
| | | && id <= values[values.length - 1] |
| | | && Arrays.binarySearch(values, id) >= 0; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public void retainAll(EntryIDSet that) |
| | | { |
| | | if (!this.isDefined()) |
| | | if (!isDefined()) |
| | | { |
| | | this.values = that.values; |
| | | this.undefinedSize = that.undefinedSize; |
| | |
| | | return; |
| | | } |
| | | |
| | | if (!this.isDefined()) |
| | | if (!isDefined()) |
| | | { |
| | | // Assume there are no overlap between IDs in that set with this set |
| | | if(undefinedSize != Long.MAX_VALUE) |
| | |
| | | return; |
| | | } |
| | | |
| | | if (!this.isDefined()) |
| | | if (!isDefined()) |
| | | { |
| | | // Assume all IDs in the given set exists in this set. |
| | | if(undefinedSize != Long.MAX_VALUE) |
| | |
| | | @Override |
| | | public Iterator<EntryID> iterator() |
| | | { |
| | | if (values == null) |
| | | { |
| | | // The set is not defined. |
| | | return new IDSetIterator(new long[0]); |
| | | } |
| | | else |
| | | if (values != null) |
| | | { |
| | | // The set is defined. |
| | | return new IDSetIterator(values); |
| | | } |
| | | else |
| | | { |
| | | // The set is not defined. |
| | | return new IDSetIterator(new long[0]); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public Iterator<EntryID> iterator(EntryID begin) |
| | | { |
| | | if (values == null) |
| | | { |
| | | // The set is not defined. |
| | | return new IDSetIterator(new long[0]); |
| | | } |
| | | else |
| | | if (values != null) |
| | | { |
| | | // The set is defined. |
| | | return new IDSetIterator(values, begin); |
| | | } |
| | | else |
| | | { |
| | | // The set is not defined. |
| | | return new IDSetIterator(new long[0]); |
| | | } |
| | | } |
| | | |
| | | } |