Skip to content

Add unionWith to SortedSet. #1241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ public ImmutableSortedSet<T> insert(T entry) {
return new ImmutableSortedSet<T>(map.insert(entry, null));
}

public ImmutableSortedSet<T> unionWith(ImmutableSortedSet<T> other) {
ImmutableSortedSet<T> result = this;

// Make sure `result` always refers to the larger one of the two sets.
if (result.size() < other.size()) {
result = other;
other = this;
}

for(T elem : other) {
result = result.insert(elem);
}

return result;
}

public T getMinEntry() {
return this.map.getMinKey();
}
Expand Down
2 changes: 2 additions & 0 deletions firebase-firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Unreleased
- [fixed] Fixed a performance regression introduced by the addition of
`Query.limitToLast(n: long)` in Firestore 23.3.1.
- [changed] Changed the in-memory representation of Firestore documents to
reduce memory allocations and improve performance. Calls to
`DocumentSnapshot.getData()` and `DocumentSnapshot.toObject()` will see
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,17 @@ public ImmutableSortedSet<DocumentKey> getRemoteKeysForTarget(int targetId) {
if (limboResolution != null && limboResolution.receivedDocument) {
return DocumentKey.emptyKeySet().insert(limboResolution.key);
} else {
List<DocumentKey> remoteKeys = Lists.newArrayList();
ImmutableSortedSet<DocumentKey> remoteKeys = DocumentKey.emptyKeySet();
if (queriesByTarget.containsKey(targetId)) {
for (Query query : queriesByTarget.get(targetId)) {
if (queryViewsByQuery.containsKey(query)) {
remoteKeys.addAll(
Lists.newArrayList(queryViewsByQuery.get(query).getView().getSyncedDocuments()));
remoteKeys =
remoteKeys.unionWith(queryViewsByQuery.get(query).getView().getSyncedDocuments());
}
}
}

return new ImmutableSortedSet(remoteKeys, DocumentKey.comparator());
return remoteKeys;
}
}

Expand Down