Skip to content

Commit

Permalink
Document introduced changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mstyura committed Sep 12, 2024
1 parent 5fc3252 commit 81d7e02
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,23 @@ public final class Tags implements Iterable<Tag> {

private static final Tags EMPTY = new Tags(new Tag[] {}, 0);

/**
* A private array of {@code Tag} objects containing the sorted and deduplicated tags.
*/
private final Tag[] sortedSet;

/**
* The number of valid tags present in the {@link #sortedSet} array.
*/
private final int length;

/**
* A private constructor that initializes a {@code Tags} object with a sorted set of
* tags and its length.
*
* @param sortedSet an ordered set of unique tags by key
* @param length the number of valid tags in the {@code sortedSet}
*/
private Tags(Tag[] sortedSet, int length) {
assert isSortedSet(sortedSet, length) : "bug on caller side: construction invariant violated";
this.sortedSet = sortedSet;
Expand All @@ -59,6 +72,12 @@ private static boolean isSortedSet(Tag[] sortedSet, int length) {
return true;
}

/**
* Constructs a {@code Tags} collection from the provided array of tags.
*
* @param tags an array of {@code Tag} objects, possibly unordered and/or containing duplicates.
* @return a {@code Tags} instance with a deduplicated and ordered set of tags.
*/
private static Tags make(Tag[] tags) {
int len = tags.length;
if (!isSortedSet(tags, len)) {
Expand All @@ -68,6 +87,12 @@ private static Tags make(Tag[] tags) {
return new Tags(tags, len);
}

/**
* Removes duplicate tags from an ordered array of tags.
*
* @param tags an ordered array of {@code Tag} objects.
* @return the number of unique tags in the {@code tags} array after removing duplicates.
*/
private static int dedup(Tag[] tags) {
int n = tags.length;

Expand All @@ -86,6 +111,13 @@ private static int dedup(Tag[] tags) {
return j;
}

/**
* Constructs a {@code Tags} instance by merging two sets of tags in time
* proportional to the sum of their sizes.
*
* @param other the set of tags to merge with this one.
* @return a {@code Tags} instance with the merged sets of tags.
*/
private Tags merged(Tags other) {
if (other.length == 0) {
return this;
Expand Down

0 comments on commit 81d7e02

Please sign in to comment.