FSTReferenceSet.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #include "Firestore/core/src/firebase/firestore/model/document_key_set.h"
  19. NS_ASSUME_NONNULL_BEGIN
  20. /**
  21. * A collection of references to a document from some kind of numbered entity (either a targetID or
  22. * batchID). As references are added to or removed from the set corresponding events are emitted to
  23. * a registered garbage collector.
  24. *
  25. * Each reference is represented by a FSTDocumentReference object. Each of them contains enough
  26. * information to uniquely identify the reference. They are all stored primarily in a set sorted
  27. * by key. A document is considered garbage if there's no references in that set (this can be
  28. * efficiently checked thanks to sorting by key).
  29. *
  30. * FSTReferenceSet also keeps a secondary set that contains references sorted by IDs. This one is
  31. * used to efficiently implement removal of all references by some target ID.
  32. */
  33. @interface FSTReferenceSet : NSObject
  34. /** Returns YES if the reference set contains no references. */
  35. - (BOOL)isEmpty;
  36. /** Adds a reference to the given document key for the given ID. */
  37. - (void)addReferenceToKey:(const firebase::firestore::model::DocumentKey &)key forID:(int)ID;
  38. /** Add references to the given document keys for the given ID. */
  39. - (void)addReferencesToKeys:(const firebase::firestore::model::DocumentKeySet &)keys forID:(int)ID;
  40. /** Removes a reference to the given document key for the given ID. */
  41. - (void)removeReferenceToKey:(const firebase::firestore::model::DocumentKey &)key forID:(int)ID;
  42. /** Removes references to the given document keys for the given ID. */
  43. - (void)removeReferencesToKeys:(const firebase::firestore::model::DocumentKeySet &)keys
  44. forID:(int)ID;
  45. /** Clears all references with a given ID. Calls -removeReferenceToKey: for each key removed. */
  46. - (void)removeReferencesForID:(int)ID;
  47. /** Clears all references for all IDs. */
  48. - (void)removeAllReferences;
  49. /** Returns all of the document keys that have had references added for the given ID. */
  50. - (firebase::firestore::model::DocumentKeySet)referencedKeysForID:(int)ID;
  51. /**
  52. * Checks to see if there are any references to a document with the given key.
  53. */
  54. - (BOOL)containsKey:(const firebase::firestore::model::DocumentKey &)key;
  55. @end
  56. NS_ASSUME_NONNULL_END