FSTReferenceSet.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #import "Firestore/Source/Core/FSTTypes.h"
  18. #import "Firestore/Source/Local/FSTGarbageCollector.h"
  19. #include "Firestore/core/src/firebase/firestore/model/document_key_set.h"
  20. NS_ASSUME_NONNULL_BEGIN
  21. /**
  22. * A collection of references to a document from some kind of numbered entity (either a targetID or
  23. * batchID). As references are added to or removed from the set corresponding events are emitted to
  24. * a registered garbage collector.
  25. *
  26. * Each reference is represented by a FSTDocumentReference object. Each of them contains enough
  27. * information to uniquely identify the reference. They are all stored primarily in a set sorted
  28. * by key. A document is considered garbage if there's no references in that set (this can be
  29. * efficiently checked thanks to sorting by key).
  30. *
  31. * FSTReferenceSet also keeps a secondary set that contains references sorted by IDs. This one is
  32. * used to efficiently implement removal of all references by some target ID.
  33. */
  34. @interface FSTReferenceSet : NSObject <FSTGarbageSource>
  35. /** Keeps track of keys that have references. */
  36. @property(nonatomic, weak, readwrite, nullable) id<FSTGarbageCollector> garbageCollector;
  37. /** Returns YES if the reference set contains no references. */
  38. - (BOOL)isEmpty;
  39. /** Adds a reference to the given document key for the given ID. */
  40. - (void)addReferenceToKey:(const firebase::firestore::model::DocumentKey &)key forID:(int)ID;
  41. /** Add references to the given document keys for the given ID. */
  42. - (void)addReferencesToKeys:(const firebase::firestore::model::DocumentKeySet &)keys forID:(int)ID;
  43. /** Removes a reference to the given document key for the given ID. */
  44. - (void)removeReferenceToKey:(const firebase::firestore::model::DocumentKey &)key forID:(int)ID;
  45. /** Removes references to the given document keys for the given ID. */
  46. - (void)removeReferencesToKeys:(const firebase::firestore::model::DocumentKeySet &)keys
  47. forID:(int)ID;
  48. /** Clears all references with a given ID. Calls -removeReferenceToKey: for each key removed. */
  49. - (void)removeReferencesForID:(int)ID;
  50. /** Clears all references for all IDs. */
  51. - (void)removeAllReferences;
  52. /** Returns all of the document keys that have had references added for the given ID. */
  53. - (firebase::firestore::model::DocumentKeySet)referencedKeysForID:(int)ID;
  54. @end
  55. NS_ASSUME_NONNULL_END