Skip to content

Commit 8f76c28

Browse files
authored
Remove SortedMap.getPredecessorKey (#477)
This is dead code. I think it was probably useful in the RTDB because of the way it notified of changes, but we give changes with indexes in Firestore so I think we don't need it. This parallels firebase/firebase-ios-sdk#735
1 parent bcc8983 commit 8f76c28

File tree

4 files changed

+0
-67
lines changed

4 files changed

+0
-67
lines changed

packages/firestore/src/model/document_set.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,6 @@ export class DocumentSet {
7878
return this.sortedSet.isEmpty();
7979
}
8080

81-
/**
82-
* Returns previous document or null if it's a first doc.
83-
*
84-
* @param key A key that MUST be present in the DocumentSet.
85-
*/
86-
prevDoc(key: DocumentKey): Document | null {
87-
assert(
88-
this.has(key),
89-
'Trying to get a previous document to non-existing key: ' + key
90-
);
91-
const doc = this.keyedMap.get(key);
92-
return this.sortedSet.getPredecessorKey(doc!);
93-
}
94-
9581
/**
9682
* Returns the index of the provided key in the document set, or -1 if the
9783
* document key is not present in the set;

packages/firestore/src/util/sorted_map.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -87,37 +87,6 @@ export class SortedMap<K, V> {
8787
return null;
8888
}
8989

90-
// Returns the key of the item *before* the specified key, or null if key is
91-
// the first item.
92-
getPredecessorKey(key: K): K | null {
93-
let node = this.root;
94-
let rightParent: LLRBNode<K, V> | LLRBEmptyNode<K, V> | null = null;
95-
while (!node.isEmpty()) {
96-
const cmp = this.comparator(key, node.key);
97-
if (cmp === 0) {
98-
if (!node.left.isEmpty()) {
99-
node = node.left;
100-
while (!node.right.isEmpty()) node = node.right;
101-
return node.key;
102-
} else if (rightParent) {
103-
return rightParent.key;
104-
} else {
105-
return null; // first item.
106-
}
107-
} else if (cmp < 0) {
108-
node = node.left;
109-
} else if (cmp > 0) {
110-
rightParent = node;
111-
node = node.right;
112-
}
113-
}
114-
115-
throw fail(
116-
'Attempted to find predecessor key for a nonexistent key.' +
117-
' What gives?'
118-
);
119-
}
120-
12190
// Returns the index of the element in this sorted map, or -1 if it doesn't
12291
// exist.
12392
indexOf(key: K): number {

packages/firestore/test/unit/model/document_set.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ describe('DocumentSet', () => {
5050
const results: Document[] = [];
5151
set.forEach((d: Document) => results.push(d));
5252
expect(results).to.deep.equal([d3, d1, d2]);
53-
54-
expect(set.prevDoc(d3.key)).to.deep.equal(null);
55-
expect(set.prevDoc(d1.key)).to.deep.equal(d3);
56-
expect(set.prevDoc(d2.key)).to.deep.equal(d1);
5753
});
5854

5955
it('adds and deletes elements', () => {
@@ -90,7 +86,6 @@ describe('DocumentSet', () => {
9086
const set = documentSet(comp, doc1, doc2);
9187
expect(set.has(doc1.key)).to.equal(true);
9288
expect(set.has(doc2.key)).to.equal(true);
93-
expect(set.prevDoc(doc2.key)).to.equal(doc1);
9489
});
9590

9691
it('equals to other document set with the same elements and order', () => {

packages/firestore/test/unit/util/sorted_map.test.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -412,23 +412,6 @@ describe('SortedMap Tests', () => {
412412
expect(expected).to.equal(10);
413413
});
414414

415-
it('SortedMap.getPredecessorKey works.', () => {
416-
const map = new SortedMap(primitiveComparator)
417-
.insert(1, 1)
418-
.insert(50, 50)
419-
.insert(3, 3)
420-
.insert(4, 4)
421-
.insert(7, 7)
422-
.insert(9, 9);
423-
424-
expect(map.getPredecessorKey(1)).to.equal(null);
425-
expect(map.getPredecessorKey(3)).to.equal(1);
426-
expect(map.getPredecessorKey(4)).to.equal(3);
427-
expect(map.getPredecessorKey(7)).to.equal(4);
428-
expect(map.getPredecessorKey(9)).to.equal(7);
429-
expect(map.getPredecessorKey(50)).to.equal(9);
430-
});
431-
432415
it('SortedMap.indexOf returns index.', () => {
433416
const map = new SortedMap(primitiveComparator)
434417
.insert(1, 1)

0 commit comments

Comments
 (0)