FSTReferenceSet.h 2.8 KB

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