FSTLLRBEmptyNode.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #import "Firestore/third_party/Immutable/FSTLLRBEmptyNode.h"
  2. #import "Firestore/third_party/Immutable/FSTLLRBValueNode.h"
  3. NS_ASSUME_NONNULL_BEGIN
  4. @implementation FSTLLRBEmptyNode
  5. - (NSString *)description {
  6. return @"[empty node]";
  7. }
  8. + (instancetype)emptyNode {
  9. static dispatch_once_t pred = 0;
  10. __strong static id _sharedObject = nil;
  11. dispatch_once(&pred, ^{
  12. _sharedObject = [[self alloc] init]; // or some other init method
  13. });
  14. return _sharedObject;
  15. }
  16. - (nullable id)key {
  17. return nil;
  18. }
  19. - (nullable id)value {
  20. return nil;
  21. }
  22. - (FSTLLRBColor)color {
  23. return FSTLLRBColorUnspecified;
  24. }
  25. - (nullable id<FSTLLRBNode>)left {
  26. return nil;
  27. }
  28. - (nullable id<FSTLLRBNode>)right {
  29. return nil;
  30. }
  31. - (instancetype)copyWith:(id _Nullable)aKey
  32. withValue:(id _Nullable)aValue
  33. withColor:(FSTLLRBColor)aColor
  34. withLeft:(id<FSTLLRBNode> _Nullable)aLeft
  35. withRight:(id<FSTLLRBNode> _Nullable)aRight {
  36. // This class is a singleton anyway, so this is more efficient than calling the constructor again.
  37. return self;
  38. }
  39. - (id<FSTLLRBNode>)insertKey:(id)aKey forValue:(id)aValue withComparator:(NSComparator)aComparator {
  40. FSTLLRBValueNode *result = [[FSTLLRBValueNode alloc] initWithKey:aKey
  41. withValue:aValue
  42. withColor:FSTLLRBColorUnspecified
  43. withLeft:nil
  44. withRight:nil];
  45. return result;
  46. }
  47. - (id<FSTLLRBNode>)remove:(id)key withComparator:(NSComparator)aComparator {
  48. return self;
  49. }
  50. - (NSUInteger)count {
  51. return 0;
  52. }
  53. - (BOOL)isEmpty {
  54. return YES;
  55. }
  56. - (BOOL)inorderTraversal:(BOOL (^)(id key, id value))action {
  57. return NO;
  58. }
  59. - (BOOL)reverseTraversal:(BOOL (^)(id key, id value))action {
  60. return NO;
  61. }
  62. - (id<FSTLLRBNode>)min {
  63. return self;
  64. }
  65. - (nullable id)minKey {
  66. return nil;
  67. }
  68. - (nullable id)maxKey {
  69. return nil;
  70. }
  71. - (BOOL)isRed {
  72. return NO;
  73. }
  74. - (int)check {
  75. return 0;
  76. }
  77. @end
  78. NS_ASSUME_NONNULL_END