motion-yapper 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (294) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +3 -1
  4. data/lib/yapper.rb +3 -3
  5. data/lib/yapper/db.rb +61 -4
  6. data/lib/yapper/document/persistence.rb +4 -0
  7. data/lib/yapper/document/selection.rb +13 -0
  8. data/lib/yapper/version.rb +1 -1
  9. data/motion-yapper.gemspec +1 -1
  10. data/spec/integration/search_spec.rb +111 -0
  11. data/vendor/Podfile.lock +11 -7
  12. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.bridgesupport +16 -2
  13. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.h +10 -7
  14. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.m +20 -2
  15. metadata +19 -297
  16. data/vendor/Pods/.build/libPods-CocoaLumberjack.a +0 -0
  17. data/vendor/Pods/.build/libPods-NSData+MD5Digest.a +0 -0
  18. data/vendor/Pods/.build/libPods-YapDatabase.a +0 -0
  19. data/vendor/Pods/.build/libPods.a +0 -0
  20. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDASLLogger.h +0 -41
  21. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDAbstractDatabaseLogger.h +0 -102
  22. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDContextFilterLogFormatter.h +0 -63
  23. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDDispatchQueueLogFormatter.h +0 -128
  24. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDFileLogger.h +0 -369
  25. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDLog+LOGV.h +0 -99
  26. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDLog.h +0 -634
  27. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDMultiFormatter.h +0 -30
  28. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDTTYLogger.h +0 -181
  29. data/vendor/Pods/BuildHeaders/NSData+MD5Digest/NSData+MD5Digest.h +0 -18
  30. data/vendor/Pods/BuildHeaders/YapDatabase/NSDictionary+YapDatabase.h +0 -8
  31. data/vendor/Pods/BuildHeaders/YapDatabase/YapCache.h +0 -91
  32. data/vendor/Pods/BuildHeaders/YapDatabase/YapCollectionKey.h +0 -23
  33. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabase.h +0 -547
  34. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseConnection.h +0 -449
  35. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseConnectionState.h +0 -29
  36. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseDefaults.h +0 -37
  37. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtension.h +0 -15
  38. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionConnection.h +0 -11
  39. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionPrivate.h +0 -444
  40. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionTransaction.h +0 -11
  41. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredView.h +0 -81
  42. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewConnection.h +0 -12
  43. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewPrivate.h +0 -17
  44. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewTransaction.h +0 -39
  45. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewTypes.h +0 -32
  46. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearch.h +0 -89
  47. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchConnection.h +0 -32
  48. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchPrivate.h +0 -77
  49. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchSnippetOptions.h +0 -79
  50. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchTransaction.h +0 -68
  51. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseLogging.h +0 -158
  52. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseManager.h +0 -17
  53. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabasePrivate.h +0 -446
  54. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseQuery.h +0 -42
  55. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationship.h +0 -35
  56. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipConnection.h +0 -29
  57. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipEdge.h +0 -163
  58. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipEdgePrivate.h +0 -79
  59. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipNode.h +0 -99
  60. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipOptions.h +0 -59
  61. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipPrivate.h +0 -125
  62. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipTransaction.h +0 -384
  63. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndex.h +0 -149
  64. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexConnection.h +0 -33
  65. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +0 -83
  66. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexSetup.h +0 -33
  67. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexSetupPrivate.h +0 -18
  68. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexTransaction.h +0 -58
  69. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseStatement.h +0 -13
  70. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseString.h +0 -121
  71. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseTransaction.h +0 -651
  72. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseView.h +0 -127
  73. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewChange.h +0 -272
  74. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewChangePrivate.h +0 -94
  75. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewConnection.h +0 -116
  76. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewMappings.h +0 -842
  77. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewMappingsPrivate.h +0 -72
  78. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewOptions.h +0 -63
  79. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPage.h +0 -36
  80. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPageMetadata.h +0 -27
  81. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPrivate.h +0 -170
  82. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewRangeOptions.h +0 -330
  83. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewRangeOptionsPrivate.h +0 -17
  84. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewTransaction.h +0 -498
  85. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewTypes.h +0 -99
  86. data/vendor/Pods/BuildHeaders/YapDatabase/YapMemoryTable.h +0 -74
  87. data/vendor/Pods/BuildHeaders/YapDatabase/YapNull.h +0 -17
  88. data/vendor/Pods/BuildHeaders/YapDatabase/YapSet.h +0 -41
  89. data/vendor/Pods/BuildHeaders/YapDatabase/YapTouch.h +0 -15
  90. data/vendor/Pods/CocoaLumberjack/LICENSE.txt +0 -18
  91. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.h +0 -41
  92. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.m +0 -100
  93. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.h +0 -102
  94. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.m +0 -727
  95. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.h +0 -369
  96. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.m +0 -1539
  97. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog+LOGV.h +0 -99
  98. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.h +0 -634
  99. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.m +0 -1208
  100. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.h +0 -181
  101. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.m +0 -1520
  102. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DDContextFilterLogFormatter.h +0 -63
  103. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DDContextFilterLogFormatter.m +0 -191
  104. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DDDispatchQueueLogFormatter.h +0 -128
  105. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DDDispatchQueueLogFormatter.m +0 -253
  106. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DDMultiFormatter.h +0 -30
  107. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DDMultiFormatter.m +0 -127
  108. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/README.txt +0 -7
  109. data/vendor/Pods/CocoaLumberjack/README.markdown +0 -74
  110. data/vendor/Pods/Headers/CocoaLumberjack/DDASLLogger.h +0 -41
  111. data/vendor/Pods/Headers/CocoaLumberjack/DDAbstractDatabaseLogger.h +0 -102
  112. data/vendor/Pods/Headers/CocoaLumberjack/DDContextFilterLogFormatter.h +0 -63
  113. data/vendor/Pods/Headers/CocoaLumberjack/DDDispatchQueueLogFormatter.h +0 -128
  114. data/vendor/Pods/Headers/CocoaLumberjack/DDFileLogger.h +0 -369
  115. data/vendor/Pods/Headers/CocoaLumberjack/DDLog+LOGV.h +0 -99
  116. data/vendor/Pods/Headers/CocoaLumberjack/DDLog.h +0 -634
  117. data/vendor/Pods/Headers/CocoaLumberjack/DDMultiFormatter.h +0 -30
  118. data/vendor/Pods/Headers/CocoaLumberjack/DDTTYLogger.h +0 -181
  119. data/vendor/Pods/Headers/NSData+MD5Digest/NSData+MD5Digest.h +0 -18
  120. data/vendor/Pods/Headers/YapDatabase/YapCollectionKey.h +0 -23
  121. data/vendor/Pods/Headers/YapDatabase/YapDatabase.h +0 -547
  122. data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnection.h +0 -449
  123. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtension.h +0 -15
  124. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionConnection.h +0 -11
  125. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionTransaction.h +0 -11
  126. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredView.h +0 -81
  127. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewConnection.h +0 -12
  128. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewTransaction.h +0 -39
  129. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewTypes.h +0 -32
  130. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearch.h +0 -89
  131. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchConnection.h +0 -32
  132. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchSnippetOptions.h +0 -79
  133. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchTransaction.h +0 -68
  134. data/vendor/Pods/Headers/YapDatabase/YapDatabaseQuery.h +0 -42
  135. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationship.h +0 -35
  136. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipConnection.h +0 -29
  137. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipEdge.h +0 -163
  138. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipNode.h +0 -99
  139. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipOptions.h +0 -59
  140. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipTransaction.h +0 -384
  141. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndex.h +0 -149
  142. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexConnection.h +0 -33
  143. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexSetup.h +0 -33
  144. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexTransaction.h +0 -58
  145. data/vendor/Pods/Headers/YapDatabase/YapDatabaseTransaction.h +0 -651
  146. data/vendor/Pods/Headers/YapDatabase/YapDatabaseView.h +0 -127
  147. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChange.h +0 -272
  148. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewConnection.h +0 -116
  149. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappings.h +0 -842
  150. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewOptions.h +0 -63
  151. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewRangeOptions.h +0 -330
  152. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewTransaction.h +0 -498
  153. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewTypes.h +0 -99
  154. data/vendor/Pods/Headers/YapDatabase/YapSet.h +0 -41
  155. data/vendor/Pods/Headers/____Pods-CocoaLumberjack-prefix.h +0 -7
  156. data/vendor/Pods/Headers/____Pods-NSData+MD5Digest-prefix.h +0 -5
  157. data/vendor/Pods/Headers/____Pods-YapDatabase-prefix.h +0 -5
  158. data/vendor/Pods/Headers/____Pods-environment.h +0 -38
  159. data/vendor/Pods/Manifest.lock +0 -22
  160. data/vendor/Pods/NSData+MD5Digest/NSData+MD5Digest/NSData+MD5Digest.h +0 -18
  161. data/vendor/Pods/NSData+MD5Digest/NSData+MD5Digest/NSData+MD5Digest.m +0 -39
  162. data/vendor/Pods/NSData+MD5Digest/README.md +0 -11
  163. data/vendor/Pods/Pods-CocoaLumberjack-Private.xcconfig +0 -5
  164. data/vendor/Pods/Pods-CocoaLumberjack-dummy.m +0 -5
  165. data/vendor/Pods/Pods-CocoaLumberjack-prefix.pch +0 -7
  166. data/vendor/Pods/Pods-CocoaLumberjack.xcconfig +0 -0
  167. data/vendor/Pods/Pods-NSData+MD5Digest-Private.xcconfig +0 -5
  168. data/vendor/Pods/Pods-NSData+MD5Digest-dummy.m +0 -5
  169. data/vendor/Pods/Pods-NSData+MD5Digest-prefix.pch +0 -5
  170. data/vendor/Pods/Pods-NSData+MD5Digest.xcconfig +0 -0
  171. data/vendor/Pods/Pods-YapDatabase-Private.xcconfig +0 -5
  172. data/vendor/Pods/Pods-YapDatabase-dummy.m +0 -5
  173. data/vendor/Pods/Pods-YapDatabase-prefix.pch +0 -5
  174. data/vendor/Pods/Pods-YapDatabase.xcconfig +0 -1
  175. data/vendor/Pods/Pods-acknowledgements.markdown +0 -59
  176. data/vendor/Pods/Pods-acknowledgements.plist +0 -97
  177. data/vendor/Pods/Pods-dummy.m +0 -5
  178. data/vendor/Pods/Pods-environment.h +0 -38
  179. data/vendor/Pods/Pods-resources.sh +0 -68
  180. data/vendor/Pods/Pods.xcconfig +0 -5
  181. data/vendor/Pods/Pods.xcodeproj/project.pbxproj +0 -4807
  182. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/Pods-CocoaLumberjack.xcscheme +0 -59
  183. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/Pods-NSData+MD5Digest.xcscheme +0 -59
  184. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/Pods-YapDatabase.xcscheme +0 -59
  185. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/Pods.xcscheme +0 -59
  186. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/xcschememanagement.plist +0 -31
  187. data/vendor/Pods/YapDatabase/LICENSE.txt +0 -18
  188. data/vendor/Pods/YapDatabase/README.md +0 -32
  189. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/Internal/YapDatabaseFilteredViewPrivate.h +0 -17
  190. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.h +0 -81
  191. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.m +0 -159
  192. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewConnection.h +0 -12
  193. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewConnection.m +0 -41
  194. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.h +0 -39
  195. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.m +0 -1235
  196. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTypes.h +0 -32
  197. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/Internal/YapDatabaseFullTextSearchPrivate.h +0 -77
  198. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearch.h +0 -89
  199. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearch.m +0 -146
  200. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchConnection.h +0 -32
  201. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchConnection.m +0 -298
  202. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchSnippetOptions.h +0 -79
  203. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchSnippetOptions.m +0 -95
  204. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchTransaction.h +0 -68
  205. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchTransaction.m +0 -1403
  206. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/Internal/YapDatabaseExtensionPrivate.h +0 -444
  207. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtension.h +0 -15
  208. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtension.m +0 -83
  209. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionConnection.h +0 -11
  210. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionConnection.m +0 -46
  211. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionTransaction.h +0 -11
  212. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionTransaction.m +0 -204
  213. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/Internal/YapDatabaseRelationshipEdgePrivate.h +0 -79
  214. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/Internal/YapDatabaseRelationshipPrivate.h +0 -125
  215. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationship.h +0 -35
  216. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationship.m +0 -129
  217. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipConnection.h +0 -29
  218. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipConnection.m +0 -802
  219. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipEdge.h +0 -163
  220. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipEdge.m +0 -408
  221. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipNode.h +0 -99
  222. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipOptions.h +0 -59
  223. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipOptions.m +0 -29
  224. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipTransaction.h +0 -384
  225. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipTransaction.m +0 -5254
  226. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/Internal/YapDatabaseSecondaryIndexPrivate.h +0 -83
  227. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/Internal/YapDatabaseSecondaryIndexSetupPrivate.h +0 -18
  228. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.h +0 -149
  229. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.m +0 -161
  230. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexConnection.h +0 -33
  231. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexConnection.m +0 -331
  232. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexSetup.h +0 -33
  233. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexSetup.m +0 -245
  234. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexTransaction.h +0 -58
  235. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexTransaction.m +0 -1269
  236. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewChangePrivate.h +0 -94
  237. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewMappingsPrivate.h +0 -72
  238. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPage.h +0 -36
  239. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPage.mm +0 -296
  240. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPageMetadata.h +0 -27
  241. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPageMetadata.m +0 -28
  242. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPrivate.h +0 -170
  243. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewRangeOptionsPrivate.h +0 -17
  244. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.h +0 -272
  245. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.m +0 -2500
  246. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.h +0 -842
  247. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.m +0 -1714
  248. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewRangeOptions.h +0 -330
  249. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewRangeOptions.m +0 -141
  250. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.h +0 -127
  251. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.m +0 -194
  252. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.h +0 -116
  253. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.m +0 -888
  254. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewOptions.h +0 -63
  255. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewOptions.m +0 -27
  256. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.h +0 -498
  257. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.m +0 -4986
  258. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTypes.h +0 -99
  259. data/vendor/Pods/YapDatabase/YapDatabase/Internal/NSDictionary+YapDatabase.h +0 -8
  260. data/vendor/Pods/YapDatabase/YapDatabase/Internal/NSDictionary+YapDatabase.m +0 -19
  261. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.h +0 -91
  262. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.m +0 -465
  263. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseConnectionState.h +0 -29
  264. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseConnectionState.m +0 -48
  265. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.h +0 -37
  266. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.m +0 -83
  267. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseLogging.h +0 -158
  268. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseLogging.m +0 -73
  269. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseManager.h +0 -17
  270. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseManager.m +0 -56
  271. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabasePrivate.h +0 -446
  272. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseStatement.h +0 -13
  273. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseStatement.m +0 -26
  274. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseString.h +0 -121
  275. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapMemoryTable.h +0 -74
  276. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapMemoryTable.m +0 -603
  277. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapNull.h +0 -17
  278. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapNull.m +0 -35
  279. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapTouch.h +0 -15
  280. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapTouch.m +0 -31
  281. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.h +0 -23
  282. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.m +0 -199
  283. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapDatabaseQuery.h +0 -42
  284. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapDatabaseQuery.m +0 -96
  285. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapSet.h +0 -41
  286. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapSet.m +0 -82
  287. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.h +0 -547
  288. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.m +0 -2013
  289. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.h +0 -449
  290. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.m +0 -4046
  291. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.h +0 -651
  292. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.m +0 -5602
  293. data/vendor/Pods/build-iPhoneSimulator/Pods.bridgesupport +0 -3172
  294. data/vendor/Pods/build-iPhoneSimulator/libPods.a +0 -0
@@ -1,2500 +0,0 @@
1
- #import "YapDatabaseViewChange.h"
2
- #import "YapDatabaseViewChangePrivate.h"
3
- #import "YapDatabaseViewMappingsPrivate.h"
4
-
5
-
6
- @implementation YapDatabaseViewSectionChange {
7
-
8
- /* From YapDatabaseViewChangePrivate.h :
9
-
10
- @public
11
-
12
- NSString *group; // immutable
13
- BOOL isReset; // immutable
14
-
15
- YapDatabaseViewChangeType type; // mutable during consolidation
16
-
17
- NSUInteger originalSection; // mutable during pre-processing
18
- NSUInteger finalSection; // mutable during pre-processing
19
- */
20
- }
21
-
22
- @synthesize type = type;
23
- @synthesize group = group;
24
-
25
- + (YapDatabaseViewSectionChange *)insertGroup:(NSString *)group
26
- {
27
- YapDatabaseViewSectionChange *op = [[YapDatabaseViewSectionChange alloc] init];
28
- op->type = YapDatabaseViewChangeInsert;
29
- op->group = group;
30
- op->isReset = NO;
31
- op->originalSection = op->finalSection = NSNotFound;
32
-
33
- return op;
34
- }
35
-
36
- + (YapDatabaseViewSectionChange *)deleteGroup:(NSString *)group
37
- {
38
- YapDatabaseViewSectionChange *op = [[YapDatabaseViewSectionChange alloc] init];
39
- op->type = YapDatabaseViewChangeDelete;
40
- op->group = group;
41
- op->isReset = NO;
42
- op->originalSection = op->finalSection = NSNotFound;
43
-
44
- return op;
45
- }
46
-
47
- + (YapDatabaseViewSectionChange *)resetGroup:(NSString *)group
48
- {
49
- YapDatabaseViewSectionChange *op = [[YapDatabaseViewSectionChange alloc] init];
50
- op->type = YapDatabaseViewChangeDelete;
51
- op->group = group;
52
- op->isReset = YES;
53
- op->originalSection = op->finalSection = NSNotFound;
54
-
55
- return op;
56
- }
57
-
58
- - (id)copyWithZone:(NSZone *)zone
59
- {
60
- YapDatabaseViewSectionChange *op = [[YapDatabaseViewSectionChange alloc] init];
61
- op->type = type;
62
- op->group = group;
63
- op->isReset = isReset;
64
- op->originalSection = originalSection;
65
- op->finalSection = finalSection;
66
-
67
- return op;
68
- }
69
-
70
- - (NSUInteger)index
71
- {
72
- if (type == YapDatabaseViewChangeInsert)
73
- return finalSection;
74
- else
75
- return originalSection;
76
- }
77
-
78
- - (NSString *)description
79
- {
80
- if (type == YapDatabaseViewChangeInsert)
81
- {
82
- if (finalSection == NSNotFound)
83
- {
84
- // Internal style (for debugging the processAndConsolidateOperations method)
85
- return [NSString stringWithFormat:
86
- @"<YapDatabaseViewSectionChange: Insert group(%@)", group];
87
- }
88
- else
89
- {
90
- // External style (for debugging UITableView & UICollectionView updates)
91
- return [NSString stringWithFormat:
92
- @"<YapDatabaseViewSectionChange: Insert section(%lu) group(%@)>",
93
- (unsigned long)finalSection, group];
94
- }
95
- }
96
- else // if (type == YapDatabaseViewChangeDelete)
97
- {
98
- if (originalSection == NSNotFound)
99
- {
100
- // Internal style (for debugging the processAndConsolidateOperations method)
101
- return [NSString stringWithFormat:
102
- @"<YapDatabaseViewSectionChange: Delete group(%@)", group];
103
- }
104
- else
105
- {
106
- // External style (for debugging UITableView & UICollectionView updates)
107
- return [NSString stringWithFormat:
108
- @"<YapDatabaseViewSectionChange: Delete section(%lu) group(%@)>",
109
- (unsigned long)originalSection, group];
110
- }
111
- }
112
- }
113
-
114
- @end
115
-
116
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
117
- #pragma mark -
118
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
119
-
120
- @implementation YapDatabaseViewRowChange {
121
-
122
- /* From YapDatabaseViewChangePrivate.h :
123
-
124
- @public
125
-
126
- id key; // immutable
127
-
128
- NSString *originalGroup; // immutable
129
- NSString *finalGroup; // mutable during consolidation
130
-
131
- YapDatabaseViewChangeType type; // mutable during consolidation
132
- int columns; // mutable during consolidation
133
-
134
- NSUInteger opOriginalIndex; // immutable
135
- NSUInteger opFinalIndex; // immutable
136
-
137
- NSUInteger originalIndex; // mutable during processing
138
- NSUInteger finalIndex; // mutable during processing
139
-
140
- NSUInteger originalSection; // mutable during pre-processing
141
- NSUInteger finalSection; // mutable during pre-processing
142
- */
143
- }
144
-
145
- @synthesize type = type;
146
- @synthesize changes = changes;
147
- @synthesize originalGroup = originalGroup;
148
- @synthesize finalGroup = finalGroup;
149
- @synthesize originalIndex = originalIndex;
150
- @synthesize finalIndex = finalIndex;
151
- @synthesize originalSection = originalSection;
152
- @synthesize finalSection = finalSection;
153
-
154
- - (NSIndexPath *)indexPath
155
- {
156
- if (type == YapDatabaseViewChangeInsert) {
157
- return nil; // <-- You should be using newIndexPath
158
- }
159
- else
160
- {
161
- #if TARGET_OS_IPHONE
162
- return [NSIndexPath indexPathForRow:originalIndex inSection:originalSection];
163
- #else
164
- NSUInteger indexes[] = {originalSection, originalIndex};
165
- return [NSIndexPath indexPathWithIndexes:indexes length:2];
166
- #endif
167
- }
168
- }
169
-
170
- - (NSIndexPath *)newIndexPath
171
- {
172
- if (type == YapDatabaseViewChangeDelete || type == YapDatabaseViewChangeUpdate) {
173
- return nil; // <-- You should be using indexPath
174
- }
175
- else {
176
- #if TARGET_OS_IPHONE
177
- return [NSIndexPath indexPathForRow:finalIndex inSection:finalSection];
178
- #else
179
- NSUInteger indexes[] = {finalSection, finalIndex};
180
- return [NSIndexPath indexPathWithIndexes:indexes length:2];
181
- #endif
182
- }
183
- }
184
-
185
- - (id)copyWithZone:(NSZone *)zone
186
- {
187
- YapDatabaseViewRowChange *op = [[YapDatabaseViewRowChange alloc] init];
188
- op->key = key;
189
- op->originalGroup = originalGroup;
190
- op->finalGroup = finalGroup;
191
- op->type = type;
192
- op->changes = changes;
193
- op->opOriginalIndex = opOriginalIndex;
194
- op->opFinalIndex = opFinalIndex;
195
- op->originalIndex = originalIndex;
196
- op->finalIndex = finalIndex;
197
- op->originalSection = originalSection;
198
- op->finalSection = finalSection;
199
-
200
- return op;
201
- }
202
-
203
- + (YapDatabaseViewRowChange *)insertKey:(id)key inGroup:(NSString *)group atIndex:(NSUInteger)index
204
- {
205
- YapDatabaseViewRowChange *op = [[YapDatabaseViewRowChange alloc] init];
206
- op->type = YapDatabaseViewChangeInsert;
207
- op->key = key;
208
- op->changes = YapDatabaseViewChangedObject | YapDatabaseViewChangedMetadata;
209
-
210
- op->originalGroup = nil; // invalid in insert type
211
- op->originalIndex = op->opOriginalIndex = NSNotFound; // invalid in insert type
212
-
213
- op->finalGroup = group;
214
- op->finalIndex = op->opFinalIndex = index;
215
-
216
- op->originalSection = op->finalSection = NSNotFound;
217
-
218
- return op;
219
- }
220
-
221
- + (YapDatabaseViewRowChange *)deleteKey:(id)key inGroup:(NSString *)group atIndex:(NSUInteger)index
222
- {
223
- YapDatabaseViewRowChange *op = [[YapDatabaseViewRowChange alloc] init];
224
- op->type = YapDatabaseViewChangeDelete;
225
- op->key = key;
226
- op->changes = YapDatabaseViewChangedObject | YapDatabaseViewChangedMetadata;
227
-
228
- op->originalGroup = group;
229
- op->originalIndex = op->opOriginalIndex = index;
230
-
231
- op->finalGroup = nil; // invalid in delete type
232
- op->finalIndex = op->opFinalIndex = NSNotFound; // invalid in delete type
233
-
234
- op->originalSection = op->finalSection = NSNotFound;
235
-
236
- return op;
237
- }
238
-
239
- + (YapDatabaseViewRowChange *)updateKey:(id)key changes:(int)flags inGroup:(NSString *)group atIndex:(NSUInteger)index
240
- {
241
- YapDatabaseViewRowChange *op = [[YapDatabaseViewRowChange alloc] init];
242
- op->type = YapDatabaseViewChangeUpdate;
243
- op->key = key;
244
- op->changes = flags;
245
-
246
- op->originalGroup = group;
247
- op->originalIndex = op->opOriginalIndex = index;
248
-
249
- op->finalGroup = group;
250
- op->finalIndex = op->opFinalIndex = index;
251
-
252
- op->originalSection = op->finalSection = NSNotFound;
253
-
254
- return op;
255
- }
256
-
257
- - (NSString *)description
258
- {
259
- if (type == YapDatabaseViewChangeInsert)
260
- {
261
- if (finalSection == NSNotFound)
262
- {
263
- // Internal style (for debugging the processAndConsolidateOperations method)
264
- return [NSString stringWithFormat:
265
- @"<YapDatabaseViewRowChange: Insert pre(~ -> %lu) post(~ -> %lu) group(%@) key(%@)",
266
- (unsigned long)opFinalIndex, (unsigned long)finalIndex, finalGroup, key];
267
- }
268
- else
269
- {
270
- // External style (for debugging UITableView & UICollectionView updates)
271
- return [NSString stringWithFormat:
272
- @"<YapDatabaseViewRowChange: Insert indexPath(nil) newIndexPath(%lu, %lu) group(%@) key(%@)>",
273
- (unsigned long)finalSection, (unsigned long)finalIndex, finalGroup, key];
274
- }
275
- }
276
- else if (type == YapDatabaseViewChangeDelete)
277
- {
278
- if (originalSection == NSNotFound)
279
- {
280
- // Internal style (for debugging the processAndConsolidateOperations method)
281
- return [NSString stringWithFormat:
282
- @"<YapDatabaseViewRowChange: Delete pre(%lu -> ~) post(%lu -> ~) group(%@) key(%@)",
283
- (unsigned long)opOriginalIndex, (unsigned long)originalIndex, originalGroup, key];
284
- }
285
- else
286
- {
287
- // External style (for debugging UITableView & UICollectionView updates)
288
- return [NSString stringWithFormat:
289
- @"<YapDatabaseViewRowChange: Delete indexPath(%lu, %lu) newIndexPath(nil) group(%@) key(%@)>",
290
- (unsigned long)originalSection, (unsigned long)originalIndex, originalGroup, key];
291
- }
292
- }
293
- else if (type == YapDatabaseViewChangeMove)
294
- {
295
- if (originalSection == NSNotFound && finalSection == NSNotFound)
296
- {
297
- // Internal style (for debugging the processAndConsolidateOperations method)
298
- return [NSString stringWithFormat:
299
- @"<YapDatabaseViewRowChange: Move pre(%lu -> %lu) post(%lu -> %lu) group(%@ -> %@) key(%@)",
300
- (unsigned long)opOriginalIndex, (unsigned long)opFinalIndex,
301
- (unsigned long)originalIndex, (unsigned long)finalIndex,
302
- originalGroup, finalGroup, key];
303
- }
304
- else
305
- {
306
- // External style (for debugging UITableView & UICollectionView updates)
307
- return [NSString stringWithFormat:
308
- @"<YapDatabaseViewRowChange: Move indexPath(%lu, %lu) newIndexPath(%lu, %lu) group(%@ -> %@) key(%@)",
309
- (unsigned long)originalSection, (unsigned long)originalIndex,
310
- (unsigned long)finalSection, (unsigned long)finalIndex,
311
- originalGroup, finalGroup, key];
312
- }
313
- }
314
- else // if (type == YapDatabaseViewChangeUpdate)
315
- {
316
- if (originalSection == NSNotFound && finalSection == NSNotFound)
317
- {
318
- // Internal style (for debugging the processAndConsolidateOperations method)
319
- return [NSString stringWithFormat:
320
- @"<YapDatabaseViewRowChange: Update pre(%lu) post(%lu -> %lu) group(%@) key(%@)",
321
- (unsigned long)opOriginalIndex,
322
- (unsigned long)originalIndex, (unsigned long)finalIndex, originalGroup, key];
323
- }
324
- else
325
- {
326
- // External style (for debugging UITableView & UICollectionView updates)
327
- return [NSString stringWithFormat:
328
- @"<YapDatabaseViewRowChange: Update indexPath(%lu, %lu) group(%@) key(%@)",
329
- (unsigned long)originalSection, (unsigned long)originalIndex, originalGroup, key];
330
- }
331
- }
332
- }
333
-
334
- @end
335
-
336
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
337
- #pragma mark -
338
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
339
-
340
- @implementation YapDatabaseViewChange
341
-
342
- /**
343
- * During a read-write transaction, every modification to the view results in one or more
344
- * YapDatabaseViewSectionChange or YapDatabaseViewRowChange objects being appended to an internal array.
345
- *
346
- * At the end of the read-write transaction we have a big list of changes that have occurred.
347
- *
348
- * This method takes the original list and pre-processes it:
349
- *
350
- * - splits the array in sectionChanges and rowChanges
351
- * - removes any items from the changes array that don't concern us (group not in mappings)
352
- * - injects extra changes if there are cell dependencies configured in the mappings
353
- **/
354
- + (void)preProcessChanges:(NSArray *)changes
355
- withOriginalMappings:(YapDatabaseViewMappings *)originalMappings
356
- finalMappings:(YapDatabaseViewMappings *)finalMappings
357
- andGetSectionChanges:(NSMutableArray **)sectionChangesPtr
358
- rowChanges:(NSMutableArray **)rowChangesPtr
359
- {
360
-
361
- // We remove any items from the changes array that don't concern us.
362
- // For example, if mappings only contain groupA & groupB,
363
- // then we can ignore changes in groupC.
364
- //
365
- // We also may need to inject extra changes.
366
- // The user may specify, as a configuration option within mappings,
367
- // the the drawing of cells has an dependency upon neighboring cells.
368
-
369
- NSMutableArray *sectionChanges = [NSMutableArray arrayWithCapacity:1];
370
- NSMutableArray *rowChanges = [NSMutableArray arrayWithCapacity:[changes count]];
371
-
372
- NSSet *originalGroups = [NSSet setWithArray:[originalMappings allGroups]];
373
- NSSet *finalGroups = [NSSet setWithArray:[finalMappings allGroups]];
374
-
375
- NSMutableDictionary *counts = [originalMappings counts];
376
- NSDictionary *dependencies = [originalMappings dependencies];
377
-
378
- for (id change in changes)
379
- {
380
- if ([change isKindOfClass:[YapDatabaseViewSectionChange class]])
381
- {
382
- __unsafe_unretained YapDatabaseViewSectionChange *immutableSectionChange =
383
- (YapDatabaseViewSectionChange *)change;
384
-
385
- if (immutableSectionChange->type == YapDatabaseViewChangeDelete)
386
- {
387
- if ([originalGroups containsObject:immutableSectionChange->group])
388
- {
389
- YapDatabaseViewSectionChange *sectionChange = [immutableSectionChange copy];
390
- [sectionChanges addObject:sectionChange];
391
-
392
- if (sectionChange->isReset)
393
- {
394
- // Special case processing.
395
- //
396
- // Most of the time, groups are deleted because the last key within the group was removed.
397
- // Thus a regular section delete is accompanied by all the corresponding row deletes.
398
- // But if the user invokes:
399
- // - removeAllObjectsInAllCollections
400
- //
401
- // then we get a section delete that isn't accompanied by the corresponding row deletes.
402
- // This operation is flagged via isReset.
403
- //
404
- // So here's what we do in this situation:
405
- // - remove any previous row changes within the group
406
- // - manually inject all the proper row deletes
407
-
408
- __unsafe_unretained YapDatabaseViewRowChange *rowChange;
409
-
410
- for (NSUInteger i = [rowChanges count]; i > 0; i--)
411
- {
412
- rowChange = [rowChanges objectAtIndex:(i-1)];
413
-
414
- if (rowChange->type == YapDatabaseViewChangeDelete)
415
- {
416
- if ([rowChange->originalGroup isEqualToString:sectionChange->group])
417
- {
418
- [rowChanges removeObjectAtIndex:(i-1)];
419
- }
420
- }
421
- else // YapDatabaseViewChangeInsert || YapDatabaseViewChangeUpdate
422
- {
423
- if ([rowChange->finalGroup isEqualToString:sectionChange->group])
424
- {
425
- [rowChanges removeObjectAtIndex:(i-1)];
426
- }
427
- }
428
- }
429
-
430
- YapDatabaseViewRangePosition rangePosition =
431
- [originalMappings rangePositionForGroup:sectionChange->group];
432
-
433
- NSUInteger prevRowOffset = rangePosition.offsetFromBeginning;
434
- NSUInteger prevRowCount = rangePosition.length;
435
-
436
- while (prevRowCount > 0)
437
- {
438
- YapDatabaseViewRowChange *rowChange =
439
- [YapDatabaseViewRowChange deleteKey:nil
440
- inGroup:sectionChange->group
441
- atIndex:(prevRowOffset+prevRowCount-1)];
442
-
443
- [rowChanges addObject:rowChange];
444
- prevRowCount--;
445
- }
446
-
447
- [counts setObject:@(0) forKey:sectionChange->group];
448
- }
449
- }
450
- }
451
- else if (immutableSectionChange->type == YapDatabaseViewChangeInsert)
452
- {
453
- if ([finalGroups containsObject:immutableSectionChange->group])
454
- {
455
- YapDatabaseViewSectionChange *sectionChange = [immutableSectionChange copy];
456
- [sectionChanges addObject:sectionChange];
457
- }
458
- }
459
- }
460
- else
461
- {
462
- __unsafe_unretained YapDatabaseViewRowChange *immutableRowChange = (YapDatabaseViewRowChange *)change;
463
-
464
- __unsafe_unretained NSString *group = nil;
465
- NSUInteger groupCount = 0;
466
- NSUInteger groupIndex = 0;
467
- BOOL wasDelete = 0;
468
-
469
- if (immutableRowChange->type == YapDatabaseViewChangeDelete)
470
- {
471
- if ([originalGroups containsObject:immutableRowChange->originalGroup])
472
- {
473
- YapDatabaseViewRowChange *rowChange = [immutableRowChange copy];
474
- [rowChanges addObject:rowChange];
475
-
476
- group = rowChange->originalGroup;
477
- groupIndex = rowChange->originalIndex;
478
-
479
- groupCount = [[counts objectForKey:group] unsignedIntegerValue];
480
- groupCount--;
481
- [counts setObject:@(groupCount) forKey:group];
482
-
483
- wasDelete = YES;
484
- }
485
- }
486
- else if (immutableRowChange->type == YapDatabaseViewChangeInsert)
487
- {
488
- if ([finalGroups containsObject:immutableRowChange->finalGroup])
489
- {
490
- YapDatabaseViewRowChange *rowChange = [immutableRowChange copy];
491
- [rowChanges addObject:rowChange];
492
-
493
- group = rowChange->finalGroup;
494
- groupIndex = rowChange->finalIndex;
495
-
496
- groupCount = [[counts objectForKey:group] unsignedIntegerValue];
497
- groupCount++;
498
- [counts setObject:@(groupCount) forKey:group];
499
- }
500
- }
501
- else if (immutableRowChange->type == YapDatabaseViewChangeUpdate)
502
- {
503
- if ([finalGroups containsObject:immutableRowChange->originalGroup])
504
- {
505
- YapDatabaseViewRowChange *rowChange = [immutableRowChange copy];
506
- [rowChanges addObject:rowChange];
507
-
508
- group = rowChange->originalGroup;
509
- groupIndex = rowChange->originalIndex;
510
-
511
- groupCount = [[counts objectForKey:group] unsignedIntegerValue];
512
- }
513
- }
514
-
515
- // Handle cell drawing dependencies.
516
-
517
- NSSet *dependenciesForGroup = [dependencies objectForKey:group];
518
- for (NSNumber *offsetNum in dependenciesForGroup)
519
- {
520
- NSInteger offset = [offsetNum integerValue] * -1;
521
- NSUInteger dependencyIndex = groupCount;
522
-
523
- if (offset > 0)
524
- {
525
- dependencyIndex = groupIndex + offset;
526
- if (wasDelete)
527
- dependencyIndex--;
528
- }
529
- else if ((offset < 0) && (-1*offset <= groupIndex))
530
- {
531
- dependencyIndex = groupIndex + offset;
532
- }
533
-
534
- if (dependencyIndex < groupCount)
535
- {
536
- int changes = YapDatabaseViewChangedDependency;
537
-
538
- YapDatabaseViewRowChange *rowChange =
539
- [YapDatabaseViewRowChange updateKey:nil changes:changes inGroup:group atIndex:dependencyIndex];
540
-
541
- [rowChanges addObject:rowChange];
542
- }
543
- }
544
-
545
- }
546
- }
547
-
548
- if (sectionChangesPtr) *sectionChangesPtr = sectionChanges;
549
- if (rowChangesPtr) *rowChangesPtr = rowChanges;
550
- }
551
-
552
-
553
- /**
554
- * During a read-write transaction, every modification to the view results in one or more
555
- * YapDatabaseViewSectionChange or YapDatabaseViewRowChange objects being appended to an internal array.
556
- *
557
- * At the end of the read-write transaction we have a big list of changes that have occurred.
558
- * But each change represents the change state at the moment the change took place.
559
- * And we ultimately need to get the change state to reflect the original and/or final position of the change.
560
- *
561
- * This method takes a list of YapDatabaseViewRowChange objects and processes them to
562
- * properly calculate and set the original and/or final index of each row change.
563
- **/
564
- + (void)processRowChanges:(NSMutableArray *)changes
565
- {
566
- // Each YapDatabaseViewRowChange object is one of:
567
- //
568
- // - Row insert
569
- // - Row delete
570
- // - Row update
571
- //
572
- // If a row is moved, then it is represented in the given array as a delete followed by an insert.
573
- //
574
- // Each YapDatabaseViewRowChange represents the change state AT THE MOMENT THE CHANGE TOOK PLACE.
575
- // This is critically important to understand.
576
- //
577
- // For example, imagine the following array:
578
- // @[
579
- // <RowInsert group=fruit index=0 key=apple>
580
- // <RowDelete group=fruit index=7 key=carrot>
581
- // <RowInsert group=fruit index=2 key=blueberry>
582
- // <RowInsert group=fruit index=2 key=banana>
583
- // ]
584
- //
585
- // What was the original index of 'carrot'?
586
- // What is the final index of 'blueberry'?
587
- //
588
- // The original index of 'carrot' was 6, because the earlier insert of 'apple' pushed its index upward.
589
- // The final index of 'blueberry' is 3, because a later insert of 'banana' pushed its index upward.
590
- //
591
- // As you might guess, there are a number of edge cases to watch out for.
592
- // Ultimately, the algorithm is fairly straight-forward, but the code gets a little verbose.
593
- //
594
- // There are are crap ton of unit tests for this code...
595
- //
596
- // Please see the UNIT TESTS for a bunch of examples that may shed additional light on the algorithm:
597
- // TestViewChangeLogic.m
598
-
599
- NSUInteger i;
600
- NSUInteger j;
601
-
602
- // First we enumerate the items BACKWARDS,
603
- // and update the ORIGINAL values.
604
-
605
- NSUInteger count = [changes count];
606
-
607
- for (i = count; i > 0; i--)
608
- {
609
- YapDatabaseViewRowChange *change = [changes objectAtIndex:(i-1)];
610
-
611
- if (change->type == YapDatabaseViewChangeDelete)
612
- {
613
- // A DELETE operation may affect the ORIGINAL index value of operations that occurred AFTER it,
614
- // IF the later operation occurs at a greater or equal index value. ( +1 )
615
-
616
- for (j = i; j < count; j++)
617
- {
618
- YapDatabaseViewRowChange *laterChange = [changes objectAtIndex:j];
619
-
620
- if (laterChange->type == YapDatabaseViewChangeDelete ||
621
- laterChange->type == YapDatabaseViewChangeUpdate)
622
- {
623
- if (laterChange->originalIndex >= change->opOriginalIndex &&
624
- [laterChange->originalGroup isEqualToString:change->originalGroup])
625
- {
626
- laterChange->originalIndex += 1;
627
- }
628
- }
629
- }
630
- }
631
- else if (change->type == YapDatabaseViewChangeInsert)
632
- {
633
- // An INSERT operation may affect the ORIGINAL index value of operations that occurred AFTER it,
634
- // IF the later operation occurs at a greater or equal index value. ( -1 )
635
-
636
- for (j = i; j < count; j++)
637
- {
638
- YapDatabaseViewRowChange *laterChange = [changes objectAtIndex:j];
639
-
640
- if (laterChange->type == YapDatabaseViewChangeDelete ||
641
- laterChange->type == YapDatabaseViewChangeUpdate)
642
- {
643
- if (laterChange->originalIndex >= change->opFinalIndex &&
644
- [laterChange->originalGroup isEqualToString:change->finalGroup])
645
- {
646
- laterChange->originalIndex -= 1;
647
- }
648
- }
649
- }
650
- }
651
- }
652
-
653
- // Next we enumerate the items FORWARDS,
654
- // and update the FINAL values.
655
-
656
- for (i = 1; i < count; i++)
657
- {
658
- YapDatabaseViewRowChange *change = [changes objectAtIndex:i];
659
-
660
- if (change->type == YapDatabaseViewChangeDelete)
661
- {
662
- // A DELETE operation may affect the FINAL index value of operations that occurred BEFORE it,
663
- // IF the earlier operation occurs at a greater (but not equal) index value. ( -1 )
664
-
665
- for (j = i; j > 0; j--)
666
- {
667
- YapDatabaseViewRowChange *earlierChange = [changes objectAtIndex:(j-1)];
668
-
669
- if (earlierChange->type == YapDatabaseViewChangeInsert ||
670
- earlierChange->type == YapDatabaseViewChangeUpdate )
671
- {
672
- if (earlierChange->finalIndex > change->opOriginalIndex &&
673
- [earlierChange->finalGroup isEqualToString:change->originalGroup])
674
- {
675
- earlierChange->finalIndex -= 1;
676
- }
677
- }
678
- }
679
- }
680
- else if (change->type == YapDatabaseViewChangeInsert)
681
- {
682
- // An INSERT operation may affect the FINAL index value of operations that occurred BEFORE it,
683
- // IF the earlier operation occurs at a greater index value ( +1 )
684
-
685
- for (j = i; j > 0; j--)
686
- {
687
- YapDatabaseViewRowChange *earlierChange = [changes objectAtIndex:(j-1)];
688
-
689
- if (earlierChange->type == YapDatabaseViewChangeInsert ||
690
- earlierChange->type == YapDatabaseViewChangeUpdate)
691
- {
692
- if (earlierChange->finalIndex >= change->opFinalIndex &&
693
- [earlierChange->finalGroup isEqualToString:change->finalGroup])
694
- {
695
- earlierChange->finalIndex += 1;
696
- }
697
- }
698
- }
699
- }
700
- }
701
- }
702
-
703
- /**
704
- * This method consolidates multiple changes to the same row into a single change that reflects
705
- * the original and final position of each changed row.
706
- **/
707
- + (void)consolidateRowChanges:(NSMutableArray *)changes
708
- {
709
- NSUInteger i;
710
- NSUInteger j;
711
-
712
- NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
713
-
714
- i = 0;
715
- while (i < [changes count])
716
- {
717
- YapDatabaseViewRowChange *firstChangeForKey = [changes objectAtIndex:i];
718
- YapDatabaseViewRowChange *mostRecentChangeForKey = firstChangeForKey;
719
-
720
- // Find later operations with the same key
721
-
722
- for (j = i+1; j < [changes count]; j++)
723
- {
724
- YapDatabaseViewRowChange *laterChange = [changes objectAtIndex:j];
725
- BOOL changesAreForSameKey = NO;
726
-
727
- if (firstChangeForKey->key && laterChange->key)
728
- {
729
- // Compare keys
730
-
731
- if ([laterChange->key isEqual:firstChangeForKey->key])
732
- changesAreForSameKey = YES;
733
- }
734
- else
735
- {
736
- // Compare indexes & groups
737
- //
738
- // This technique is used if one of the keys is nil,
739
- // and applies to situations where one of the changes is an Update with a nil key,
740
- // which was injected during pre-processing due to cell drawing dependencies.
741
-
742
- if (mostRecentChangeForKey->type == YapDatabaseViewChangeUpdate)
743
- {
744
- if (laterChange->type == YapDatabaseViewChangeUpdate ||
745
- laterChange->type == YapDatabaseViewChangeDelete)
746
- {
747
- if (mostRecentChangeForKey->originalIndex == laterChange->originalIndex &&
748
- [mostRecentChangeForKey->originalGroup isEqualToString:laterChange->originalGroup]) {
749
- changesAreForSameKey = YES;
750
- }
751
- }
752
- }
753
- else if (mostRecentChangeForKey->type == YapDatabaseViewChangeInsert)
754
- {
755
- if (laterChange->type == YapDatabaseViewChangeUpdate)
756
- {
757
- if (mostRecentChangeForKey->originalIndex == laterChange->originalIndex &&
758
- [mostRecentChangeForKey->originalGroup isEqualToString:laterChange->originalGroup]) {
759
- changesAreForSameKey = YES;
760
- }
761
- }
762
- }
763
-
764
- if (changesAreForSameKey)
765
- {
766
- if (mostRecentChangeForKey->key == nil)
767
- mostRecentChangeForKey->key = laterChange->key;
768
- else
769
- laterChange->key = mostRecentChangeForKey->key;
770
- }
771
- }
772
-
773
- if (changesAreForSameKey)
774
- {
775
- firstChangeForKey->changes |= laterChange->changes;
776
- [indexSet addIndex:j];
777
-
778
- mostRecentChangeForKey = laterChange;
779
- }
780
- }
781
-
782
- if ([indexSet count] == 0)
783
- {
784
- i++; // continue;
785
- }
786
- else
787
- {
788
- YapDatabaseViewRowChange *lastChangeForKey = [changes objectAtIndex:[indexSet lastIndex]];
789
-
790
- if (firstChangeForKey->type == YapDatabaseViewChangeDelete)
791
- {
792
- if (lastChangeForKey->type == YapDatabaseViewChangeDelete)
793
- {
794
- // Delete + Insert + ... + Delete
795
- //
796
- // All operations except the first are no-ops
797
-
798
- [changes removeObjectsAtIndexes:indexSet];
799
- i++;
800
- }
801
- else if (lastChangeForKey->type == YapDatabaseViewChangeInsert)
802
- {
803
- // Delete + Insert = Move
804
- //
805
- // This is always a move operation.
806
- // Even if the final location hasn't ultimately changed, we still want to treat it as a move.
807
- // Only a true update, where the index never budged, can be emitted as an update.
808
- //
809
- // If we attempt to consolidate this into an update,
810
- // then the tableView/collectionView will offset the update's index
811
- // based on insertions & deletions at smaller indexes,
812
- // and may ultimately update the wrong cell.
813
-
814
- firstChangeForKey->type = YapDatabaseViewChangeMove;
815
- firstChangeForKey->finalIndex = lastChangeForKey->finalIndex;
816
- firstChangeForKey->finalGroup = lastChangeForKey->finalGroup;
817
- firstChangeForKey->opFinalIndex = lastChangeForKey->opFinalIndex; // for postProcessing
818
-
819
- [changes removeObjectsAtIndexes:indexSet];
820
- i++;
821
- }
822
- else if (lastChangeForKey->type == YapDatabaseViewChangeUpdate)
823
- {
824
- // Delete + Insert + ... + Update = Move
825
- //
826
- // This is always a move operation.
827
- // Even if the final location hasn't ultimately changed, we still want to treat it as a move.
828
- // Only a true update, where the index never budged, can be emitted as an update.
829
- //
830
- // If we attempt to consolidate this into an update,
831
- // then the tableView/collectionView will offset the update's index
832
- // based on insertions & deletions at smaller indexes,
833
- // and may ultimately update the wrong cell.
834
-
835
- firstChangeForKey->type = YapDatabaseViewChangeMove;
836
- firstChangeForKey->finalIndex = lastChangeForKey->finalIndex;
837
- firstChangeForKey->finalGroup = lastChangeForKey->finalGroup;
838
- firstChangeForKey->opFinalIndex = lastChangeForKey->opFinalIndex; // for postProcessing
839
-
840
- [changes removeObjectsAtIndexes:indexSet];
841
- i++;
842
- }
843
- }
844
- else if (firstChangeForKey->type == YapDatabaseViewChangeInsert)
845
- {
846
- if (lastChangeForKey->type == YapDatabaseViewChangeDelete)
847
- {
848
- // Insert + Delete
849
- //
850
- // All operations are no-ops (& i remains the same)
851
-
852
- [changes removeObjectsAtIndexes:indexSet];
853
- [changes removeObjectAtIndex:i];
854
- }
855
- else if (lastChangeForKey->type == YapDatabaseViewChangeInsert)
856
- {
857
- // Insert + Delete + ... + Insert
858
- //
859
- // All operations except the last are no-ops.
860
-
861
- firstChangeForKey->finalIndex = lastChangeForKey->finalIndex;
862
- firstChangeForKey->finalGroup = lastChangeForKey->finalGroup;
863
-
864
- [changes removeObjectsAtIndexes:indexSet];
865
- i++;
866
- }
867
- else // if (lastChangeForKey->type == YapDatabaseViewChangeUpdate)
868
- {
869
- // Insert + Update
870
- //
871
- // This is still an insert, but the final location may have changed.
872
-
873
- firstChangeForKey->finalIndex = lastChangeForKey->finalIndex;
874
- firstChangeForKey->finalGroup = lastChangeForKey->finalGroup;
875
-
876
- [changes removeObjectsAtIndexes:indexSet];
877
- i++;
878
- }
879
- }
880
- else if (firstChangeForKey->type == YapDatabaseViewChangeUpdate)
881
- {
882
- if (lastChangeForKey->type == YapDatabaseViewChangeDelete)
883
- {
884
- // Update + Delete
885
- //
886
- // This is ultimately a Delete.
887
- // We need to be sure to use the original original index.
888
-
889
- firstChangeForKey->type = YapDatabaseViewChangeDelete;
890
-
891
- [changes removeObjectsAtIndexes:indexSet];
892
- i++;
893
- }
894
- else if (lastChangeForKey->type == YapDatabaseViewChangeInsert)
895
- {
896
- // Update + Delete + ... + Insert = Move
897
- //
898
- // This is always a move operation.
899
- // Even if the final location hasn't ultimately changed, we still want to treat it as a move.
900
- // Only a true update, where the index never budged, can be emitted as an update.
901
- //
902
- // If we attempt to consolidate this into an update,
903
- // then the tableView/collectionView will offset the update's index
904
- // based on insertions & deletions at smaller indexes,
905
- // and may ultimately update the wrong cell.
906
- //
907
- // The final location comes from the last update
908
-
909
- firstChangeForKey->type = YapDatabaseViewChangeMove;
910
- firstChangeForKey->finalIndex = lastChangeForKey->finalIndex;
911
- firstChangeForKey->finalGroup = lastChangeForKey->finalGroup;
912
- firstChangeForKey->opFinalIndex = lastChangeForKey->opFinalIndex; // for postProcessing
913
-
914
- [changes removeObjectsAtIndexes:indexSet];
915
- i++;
916
- }
917
- else // if (lastChangeForKey->type == YapDatabaseViewChangeUpdate)
918
- {
919
- // Update + ... + Update
920
- //
921
- // This is either an Update or a Move.
922
- // Only a true update, where the index never budged, can be emitted as an update.
923
- //
924
- // So we scan all the changes, and if every single one is an update, then we can emit an update.
925
-
926
- __block BOOL isTrueUpdate = YES;
927
-
928
- [indexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
929
-
930
- YapDatabaseViewRowChange *changeForKey = [changes objectAtIndex:idx];
931
-
932
- if (changeForKey->type != YapDatabaseViewChangeUpdate)
933
- {
934
- isTrueUpdate = NO;
935
- *stop = YES;
936
- }
937
- }];
938
-
939
- if (isTrueUpdate)
940
- {
941
- // = Update
942
-
943
- [changes removeObjectsAtIndexes:indexSet];
944
- i++;
945
- }
946
- else
947
- {
948
- // = Move
949
- //
950
- // The final location comes from the last update
951
-
952
- firstChangeForKey->type = YapDatabaseViewChangeMove;
953
- firstChangeForKey->finalIndex = lastChangeForKey->finalIndex;
954
- firstChangeForKey->finalGroup = lastChangeForKey->finalGroup;
955
- firstChangeForKey->opFinalIndex = lastChangeForKey->opFinalIndex; // for postProcessing
956
-
957
- [changes removeObjectsAtIndexes:indexSet];
958
- i++;
959
- }
960
- }
961
- }
962
-
963
- [indexSet removeAllIndexes];
964
-
965
- } // ([indexSet count] > 0)
966
-
967
- } // while (i < [changes count])
968
- }
969
-
970
- /**
971
- * This method consolidates multiple changes to the same section into a single change.
972
- **/
973
- + (void)consolidateSectionChanges:(NSMutableArray *)changes
974
- {
975
- NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
976
-
977
- NSUInteger i = 0;
978
- while (i < [changes count])
979
- {
980
- YapDatabaseViewSectionChange *firstSectionChangeForGroup = [changes objectAtIndex:i];
981
-
982
- // Find later operations with the same group
983
-
984
- for (NSUInteger j = i+1; j < [changes count]; j++)
985
- {
986
- YapDatabaseViewSectionChange *laterSectionChange = [changes objectAtIndex:j];
987
-
988
- if ([laterSectionChange->group isEqualToString:firstSectionChangeForGroup->group])
989
- {
990
- [indexSet addIndex:j];
991
- }
992
- }
993
-
994
- if ([indexSet count] == 0)
995
- {
996
- i++;
997
- }
998
- else
999
- {
1000
- YapDatabaseViewSectionChange *lastSectionChangeForGroup = [changes objectAtIndex:[indexSet lastIndex]];
1001
-
1002
- if (firstSectionChangeForGroup->type == YapDatabaseViewChangeDelete)
1003
- {
1004
- if (lastSectionChangeForGroup->type == YapDatabaseViewChangeDelete)
1005
- {
1006
- // Delete + Insert + ... + Delete
1007
- //
1008
- // All operations except the first are no-ops
1009
-
1010
- [changes removeObjectsAtIndexes:indexSet];
1011
- i++;
1012
- }
1013
- else // if (lastSectionChangeForGroup->type == YapDatabaseViewChangeInsert)
1014
- {
1015
- // Delete + Insert
1016
- //
1017
- // All operations are no-ops (& i remains the same)
1018
-
1019
- [changes removeObjectsAtIndexes:indexSet];
1020
- [changes removeObjectAtIndex:i];
1021
- }
1022
- }
1023
- else if (firstSectionChangeForGroup->type == YapDatabaseViewChangeInsert)
1024
- {
1025
- if (lastSectionChangeForGroup->type == YapDatabaseViewChangeDelete)
1026
- {
1027
- // Insert + Delete
1028
- //
1029
- // All operations are no-ops (& i remains the same)
1030
-
1031
- [changes removeObjectsAtIndexes:indexSet];
1032
- [changes removeObjectAtIndex:i];
1033
- }
1034
- else if (lastSectionChangeForGroup->type == YapDatabaseViewChangeInsert)
1035
- {
1036
- // Insert + Delete + ... + Insert
1037
- //
1038
- // All operations except the first are no-ops.
1039
-
1040
- [changes removeObjectsAtIndexes:indexSet];
1041
- i++;
1042
- }
1043
- }
1044
- }
1045
- }
1046
- }
1047
-
1048
- /**
1049
- * This method applies the given mappings to the processed list of row changes.
1050
- * Based upon the configuration of the mappings, it will
1051
- *
1052
- * - filter items that are excluded based on per-group range configurations
1053
- * - alter indexes based on per-group range configurations
1054
- * - reverse indexes based on per-group reversal settings
1055
- **/
1056
- + (void)postProcessAndFilterRowChanges:(NSMutableArray *)rowChanges
1057
- withOriginalMappings:(YapDatabaseViewMappings *)originalMappings
1058
- finalMappings:(YapDatabaseViewMappings *)finalMappings
1059
- {
1060
-
1061
- // The user may have various range options set for each section/group.
1062
- // For example:
1063
- //
1064
- // The user has a hard range on group "fiction" in the "bookSalesRank" view in order to display the top 20.
1065
- // So any items outside of that range must be filtered.
1066
-
1067
- NSDictionary *rangeOptions = [finalMappings rangeOptions];
1068
- BOOL rangeOptionsChanged = YES;
1069
-
1070
- // Note: The rangeOptions are the same between originalMappings & finalMappings.
1071
-
1072
- for (NSString *group in rangeOptions)
1073
- {
1074
- YapDatabaseViewRangeOptions *rangeOpts = [rangeOptions objectForKey:group];
1075
-
1076
- NSUInteger originalGroupCount = [originalMappings fullCountForGroup:group];
1077
- NSUInteger finalGroupCount = [finalMappings fullCountForGroup:group];
1078
-
1079
- YapDatabaseViewPin pin = rangeOpts.pin;
1080
-
1081
- //
1082
- // STEP 1 : Calculate the originalRange & finalRange
1083
- //
1084
-
1085
- NSUInteger originalRangeLength = rangeOpts.length;
1086
- NSUInteger originalRangeOffset = rangeOpts.offset;
1087
-
1088
- NSUInteger originalRangeMin;
1089
- NSUInteger originalRangeMax;
1090
-
1091
- if (pin == YapDatabaseViewBeginning)
1092
- {
1093
- originalRangeMin = originalRangeOffset;
1094
- originalRangeMax = originalRangeOffset + originalRangeLength;
1095
- }
1096
- else // if (pin == YapDatabaseViewEnd)
1097
- {
1098
- if (originalRangeOffset < originalGroupCount) {
1099
- originalRangeMax = originalGroupCount - originalRangeOffset;
1100
- originalRangeMin = originalRangeMax - originalRangeLength;
1101
- }
1102
- else {
1103
- originalRangeMax = 0;
1104
- originalRangeMin = 0;
1105
- }
1106
- }
1107
-
1108
- NSUInteger finalRangeLength;
1109
- NSUInteger finalRangeOffset;
1110
-
1111
- NSUInteger finalRangeMin;
1112
- NSUInteger finalRangeMax;
1113
-
1114
- NSUInteger flexibleRangeNonPinSideDeleteDiff = 0;
1115
- NSUInteger flexibleRangePinSideInsertDiff = 0;
1116
- NSUInteger flexibleRangeNonPinSideInsertDiff = 0;
1117
-
1118
- if (rangeOpts.isFixedRange)
1119
- {
1120
- // FIXED Range:
1121
- //
1122
- // - The length is fixed. It only shrinks if we run out of keys.
1123
- // - The offset never changes.
1124
- //
1125
- // If pinned to the BEGINNING:
1126
- // The offset represents how far the beginning of the range is from the beginning of the group.
1127
- //
1128
- // Group : <---------------------------------------->
1129
- // Range : <--------->
1130
- // Offset: <----------------> (pin == YapDatabaseViewBeginning)
1131
- //
1132
- // If pinned to the END:
1133
- // The offset represents how far the end of the range is from the end of the group.
1134
- //
1135
- // Group : <---------------------------------------->
1136
- // Range : <--------->
1137
- // Offset: <-------------> (pin == YapDatabaseViewEnd)
1138
-
1139
- finalRangeOffset = originalRangeOffset;
1140
-
1141
- NSUInteger maxFinalRangeLength;
1142
- if (finalGroupCount > finalRangeOffset)
1143
- maxFinalRangeLength = finalGroupCount - finalRangeOffset;
1144
- else
1145
- maxFinalRangeLength = 0;
1146
-
1147
- finalRangeLength = MIN(rangeOpts.maxLength, maxFinalRangeLength);
1148
-
1149
- if (pin == YapDatabaseViewBeginning)
1150
- {
1151
- finalRangeMin = finalRangeOffset;
1152
- finalRangeMax = finalRangeOffset + finalRangeLength;
1153
- }
1154
- else // if (pin == YapDatabaseViewEnd)
1155
- {
1156
- if (finalRangeOffset < finalGroupCount) {
1157
- finalRangeMax = finalGroupCount - finalRangeOffset;
1158
- finalRangeMin = finalRangeMax - finalRangeLength;
1159
- }
1160
- else {
1161
- finalRangeMax = 0;
1162
- finalRangeMin = 0;
1163
- }
1164
- }
1165
- }
1166
- else // if (rangeOpts.isFlexibleRange)
1167
- {
1168
- // FLEXIBLE Range:
1169
- //
1170
- // The length changes as items are inserted and deleted with the range boundary.
1171
- // The offset changes as items are inserted and deleted between the range and its pinned end.
1172
-
1173
- finalRangeMin = originalRangeMin;
1174
- finalRangeMax = originalRangeMax;
1175
-
1176
- BOOL finalRangeWasEmpty = ((finalRangeMax - finalRangeMin) == 0);
1177
-
1178
- YapDatabaseViewGrowOptions growOptions = rangeOpts.growOptions;
1179
-
1180
- for (YapDatabaseViewRowChange *rowChange in rowChanges)
1181
- {
1182
- if (rowChange->type == YapDatabaseViewChangeDelete || rowChange->type == YapDatabaseViewChangeMove)
1183
- {
1184
- if ([rowChange->originalGroup isEqualToString:group])
1185
- {
1186
- // A DELETE operation can:
1187
- // - decrement the location of the final range
1188
- // - decrease the length of the final range
1189
-
1190
- if (rowChange->opOriginalIndex < finalRangeMin)
1191
- {
1192
- finalRangeMin -= 1;
1193
- }
1194
- if (rowChange->opOriginalIndex < finalRangeMax)
1195
- {
1196
- finalRangeMax -= 1;
1197
- }
1198
- }
1199
-
1200
- }// fi (rowChange->type == YapDatabaseViewChangeDelete || rowChange->type == YapDatabaseViewChangeMove)
1201
-
1202
- if (rowChange->type == YapDatabaseViewChangeInsert || rowChange->type == YapDatabaseViewChangeMove)
1203
- {
1204
- if ([rowChange->finalGroup isEqualToString:group])
1205
- {
1206
- // An INSERT operation can:
1207
- // - increment the location of the final range
1208
- // - increase the length of the final range
1209
- //
1210
- // How do we know if an inserted item should be included in the range?
1211
- // This is based upon the growOptions.
1212
- //
1213
- // Please see the documentation in the header file for the growOptions property.
1214
- // It has an extended discussion.
1215
-
1216
- if (pin == YapDatabaseViewBeginning)
1217
- {
1218
- if ((growOptions & YapDatabaseViewGrowPinSide) || finalRangeWasEmpty)
1219
- {
1220
- if (rowChange->opFinalIndex < finalRangeMin)
1221
- finalRangeMin++;
1222
- }
1223
- else
1224
- {
1225
- if (rowChange->opFinalIndex <= finalRangeMin)
1226
- finalRangeMin++;
1227
- }
1228
-
1229
- if ((growOptions & YapDatabaseViewGrowNonPinSide) || finalRangeWasEmpty)
1230
- {
1231
- if (rowChange->opFinalIndex <= finalRangeMax)
1232
- finalRangeMax++;
1233
- }
1234
- else
1235
- {
1236
- if (rowChange->opFinalIndex < finalRangeMax)
1237
- finalRangeMax++;
1238
- }
1239
- }
1240
- else // if (pin == YapDatabaseViewEnd)
1241
- {
1242
- if ((growOptions & YapDatabaseViewGrowNonPinSide) || finalRangeWasEmpty)
1243
- {
1244
- if (rowChange->opFinalIndex < finalRangeMin)
1245
- finalRangeMin++;
1246
- }
1247
- else
1248
- {
1249
- if (rowChange->opFinalIndex <= finalRangeMin)
1250
- finalRangeMin++;
1251
- }
1252
-
1253
- if ((growOptions & YapDatabaseViewGrowPinSide) || finalRangeWasEmpty)
1254
- {
1255
- if (rowChange->opFinalIndex <= finalRangeMax)
1256
- finalRangeMax++;
1257
- }
1258
- else
1259
- {
1260
- if (rowChange->opFinalIndex < finalRangeMax)
1261
- finalRangeMax++;
1262
- }
1263
- }
1264
- }
1265
-
1266
- }// fi (rowChange->type == YapDatabaseViewChangeInsert || rowChange->type == YapDatabaseViewChangeMove)
1267
-
1268
- // If the range ever becomes empty,
1269
- // then we need to effectively set the growOptions to YapDatabaseViewGrowOnBothSides.
1270
- //
1271
- // With an empty range, there is no different between PinSide and NonPinSide.
1272
- //
1273
- // Notice that this flag, once set, remains set.
1274
-
1275
- finalRangeWasEmpty = finalRangeWasEmpty || ((finalRangeMax - finalRangeMin) == 0);
1276
-
1277
- } // end for (YapDatabaseViewRowChange *rowChange in rowChanges)
1278
-
1279
-
1280
- // Adjust if we exceed max length, or drop below min length
1281
-
1282
- finalRangeLength = finalRangeMax - finalRangeMin;
1283
-
1284
- if (finalRangeLength > rangeOpts.maxLength)
1285
- {
1286
- NSUInteger diff = finalRangeLength - rangeOpts.maxLength;
1287
- flexibleRangeNonPinSideDeleteDiff = diff;
1288
-
1289
- if (pin == YapDatabaseViewBeginning)
1290
- {
1291
- // Prune from non-pin-side (end)
1292
- finalRangeMax -= diff;
1293
- }
1294
- else // if (pin == YapDatabaseViewEnd)
1295
- {
1296
- // Prune from non-pin-side (beginning)
1297
- finalRangeMin += diff;
1298
- }
1299
-
1300
- }
1301
- else if ((finalRangeLength < rangeOpts.minLength) && (finalRangeLength < finalGroupCount))
1302
- {
1303
- NSUInteger diff = rangeOpts.minLength - finalRangeLength;
1304
-
1305
- if (pin == YapDatabaseViewBeginning)
1306
- {
1307
- // Append from pin-side first (beginning) (if possible)
1308
- if (finalRangeMin > 0)
1309
- {
1310
- NSUInteger pinSideDiff = MIN(diff, finalRangeMin);
1311
- flexibleRangePinSideInsertDiff = pinSideDiff;
1312
-
1313
- finalRangeMin -= pinSideDiff;
1314
- diff -= pinSideDiff;
1315
- }
1316
-
1317
- // Append from non-pin-side second (end) (if possible) (if still needed)
1318
- if ((finalRangeMax < finalGroupCount) && (diff > 0))
1319
- {
1320
- NSUInteger nonPinSideDiff = MIN(diff, (finalGroupCount - finalRangeMax));
1321
- flexibleRangeNonPinSideInsertDiff = nonPinSideDiff;
1322
-
1323
- finalRangeMax += nonPinSideDiff;
1324
- //diff -= nonPinSideDiff;
1325
- }
1326
- }
1327
- else // if (pin == YapDatabaseViewEnd)
1328
- {
1329
- // Append from pin-side first (end) (if possible)
1330
- if (finalRangeMax < finalGroupCount)
1331
- {
1332
- NSUInteger pinSideDiff = MIN(diff, (finalGroupCount - finalRangeMax));
1333
- flexibleRangePinSideInsertDiff = pinSideDiff;
1334
-
1335
- finalRangeMax += pinSideDiff;
1336
- diff -= pinSideDiff;
1337
- }
1338
-
1339
- // Append from non-pin-side second (beginning) (if possible) (if still needed)
1340
- if ((finalRangeMin > 0) && (diff > 0))
1341
- {
1342
- NSUInteger nonPinSideDiff = MIN(diff, finalRangeMin);
1343
- flexibleRangeNonPinSideInsertDiff = nonPinSideDiff;
1344
-
1345
- finalRangeMin -= nonPinSideDiff;
1346
- //diff -= nonPinSideDiff;
1347
- }
1348
- }
1349
- }
1350
-
1351
- // Set finalLength & finalOffset
1352
-
1353
- finalRangeLength = finalRangeMax - finalRangeMin;
1354
-
1355
- if (pin == YapDatabaseViewBeginning)
1356
- finalRangeOffset = finalRangeMin;
1357
- else
1358
- finalRangeOffset = finalGroupCount - finalRangeMax;
1359
-
1360
- } // END if (rangeOpts.isFlexibleRange)
1361
-
1362
- //
1363
- // STEP 2 : Filter items that are outside the range, and "map" items that are inside the range.
1364
- //
1365
- // By "map" we mean update the index to match the range, not the entire view.
1366
- // For example, if there is a hard range to display only the last 20 items in the view,
1367
- // then the index of the last item should be 20 (range.length), not 436 (group.length).
1368
-
1369
- NSUInteger deleteCount = 0;
1370
- NSUInteger insertCount = 0;
1371
-
1372
- NSUInteger i = 0;
1373
- while (i < [rowChanges count])
1374
- {
1375
- YapDatabaseViewRowChange *rowChange = [rowChanges objectAtIndex:i];
1376
-
1377
- if (rowChange->type == YapDatabaseViewChangeDelete)
1378
- {
1379
- if ([rowChange->originalGroup isEqualToString:group])
1380
- {
1381
- if (rowChange->originalIndex >= originalRangeMin &&
1382
- rowChange->originalIndex < originalRangeMax)
1383
- {
1384
- // Include in changeset
1385
- i++;
1386
- deleteCount++;
1387
-
1388
- // Update index to match range
1389
- rowChange->originalIndex -= originalRangeMin;
1390
- }
1391
- else
1392
- {
1393
- // Exclude from changeset
1394
- [rowChanges removeObjectAtIndex:i];
1395
- }
1396
- }
1397
- }
1398
- else if (rowChange->type == YapDatabaseViewChangeInsert)
1399
- {
1400
- if ([rowChange->finalGroup isEqualToString:group])
1401
- {
1402
- if (rowChange->finalIndex >= finalRangeMin &&
1403
- rowChange->finalIndex < finalRangeMax)
1404
- {
1405
- // Include in changeset
1406
- i++;
1407
- insertCount++;
1408
-
1409
- // Update index to match range
1410
- rowChange->finalIndex -= finalRangeMin;
1411
- }
1412
- else
1413
- {
1414
- // Exclude from changeset
1415
- [rowChanges removeObjectAtIndex:i];
1416
- }
1417
- }
1418
- }
1419
- else if (rowChange->type == YapDatabaseViewChangeUpdate)
1420
- {
1421
- if ([rowChange->originalGroup isEqualToString:group])
1422
- {
1423
- if (rowChange->originalIndex >= originalRangeMin &&
1424
- rowChange->originalIndex < originalRangeMax)
1425
- {
1426
- // Include in changeset
1427
- i++;
1428
-
1429
- // Update index to match range
1430
- rowChange->originalIndex -= originalRangeMin;
1431
- rowChange->finalIndex -= finalRangeMin;
1432
- }
1433
- else
1434
- {
1435
- // Exclude from changeset
1436
- [rowChanges removeObjectAtIndex:i];
1437
- }
1438
- }
1439
- }
1440
- else if (rowChange->type == YapDatabaseViewChangeMove)
1441
- {
1442
- // A move is both a delete and an insert.
1443
- // Sometimes both operations apply to this group.
1444
- // Sometimes only one.
1445
- // Sometimes neither.
1446
-
1447
- BOOL filterDelete = NO;
1448
- BOOL filterInsert = NO;
1449
-
1450
- if ([rowChange->originalGroup isEqualToString:group])
1451
- {
1452
- if (rowChange->originalIndex >= originalRangeMin &&
1453
- rowChange->originalIndex < originalRangeMax)
1454
- {
1455
- // Include (delete operation) in changeset
1456
-
1457
- // Update index to match range
1458
- rowChange->originalIndex -= originalRangeMin;
1459
- }
1460
- else
1461
- {
1462
- // Exclude (delete operation) from changeset
1463
- filterDelete = YES;
1464
- }
1465
- }
1466
-
1467
- if ([rowChange->finalGroup isEqualToString:group])
1468
- {
1469
- if (rowChange->finalIndex >= finalRangeMin &&
1470
- rowChange->finalIndex < finalRangeMax)
1471
- {
1472
- // Include (insert operation) in changeset
1473
-
1474
- // Update index to match range
1475
- rowChange->finalIndex -= finalRangeMin;
1476
- }
1477
- else
1478
- {
1479
- // Exclude (insert operation) from changeset
1480
- filterInsert = YES;
1481
- }
1482
- }
1483
-
1484
- if (filterDelete && filterInsert)
1485
- {
1486
- // Exclude from changeset
1487
- [rowChanges removeObjectAtIndex:i];
1488
- }
1489
- else if (filterDelete && !filterInsert)
1490
- {
1491
- // Move -> Insert
1492
- rowChange->type = YapDatabaseViewChangeInsert;
1493
- i++;
1494
- insertCount++;
1495
- }
1496
- else if (!filterDelete && filterInsert)
1497
- {
1498
- // Move -> Delete
1499
- rowChange->type = YapDatabaseViewChangeDelete;
1500
- i++;
1501
- deleteCount++;
1502
- }
1503
- else
1504
- {
1505
- // Move
1506
- i++;
1507
- insertCount++;
1508
- deleteCount++;
1509
- }
1510
- }
1511
- }
1512
-
1513
- //
1514
- // STEP 3: Fix the final counts by manually adding any needed insertions or deletions
1515
- //
1516
-
1517
- NSUInteger numberOfInsertOperationsToManuallyAdd = 0;
1518
- NSUInteger numberOfDeleteOperationsToManuallyAdd = 0;
1519
-
1520
- if (rangeOpts.isFixedRange)
1521
- {
1522
- // FIXED Range:
1523
- //
1524
- // For fixed ranges, we need to ensure the changeset reflects the proper count.
1525
- // For example:
1526
- //
1527
- // The fixed range has a lenth of 20.
1528
- // The only changes were 2 insertions.
1529
- // Thus, we need to add 2 delete changes to balance the length.
1530
- //
1531
- // These represent the items that got pushed out of the range.
1532
-
1533
- NSUInteger length = originalRangeLength;
1534
- length += insertCount;
1535
- length -= deleteCount;
1536
-
1537
- if (length > finalRangeLength)
1538
- {
1539
- // Need to add DELETE operations.
1540
-
1541
- numberOfDeleteOperationsToManuallyAdd = length - finalRangeLength;
1542
- }
1543
- else if (length < finalRangeLength)
1544
- {
1545
- // Need to add INSERT operations.
1546
-
1547
- numberOfInsertOperationsToManuallyAdd = finalRangeLength - length;
1548
- }
1549
- }
1550
- else if (flexibleRangeNonPinSideDeleteDiff != 0)
1551
- {
1552
- // FLEXIBLE Range:
1553
- //
1554
- // The range naturally expanded to the point where it exceeded the max length.
1555
- // We may need to manually add DELETE operations.
1556
-
1557
- NSInteger expectedDiff = finalRangeLength - originalRangeLength;
1558
- NSInteger actualDiff = insertCount - deleteCount;
1559
-
1560
- // Example 1: typical length going above max
1561
- //
1562
- // originalRangeLength = 5, finalRangeLength = 10, max = 10, insertCount = 10, deleteCount = 0
1563
- // expectedDiff = 5
1564
- // actualDiff = 10
1565
-
1566
- // Example 2: user changed max value on us without changing length
1567
- // (not technically supporeted, but not overly difficult to handle)
1568
- //
1569
- // originalRangeLength = 10, finalRangeLength = 5, max = 5, insertCount = 1, deleteCount = 0
1570
- // expectedDiff = -5
1571
- // actualDiff = 1
1572
-
1573
- if (actualDiff > expectedDiff)
1574
- {
1575
- numberOfDeleteOperationsToManuallyAdd = actualDiff - expectedDiff;
1576
- }
1577
- }
1578
- else if ((flexibleRangePinSideInsertDiff > 0) || (flexibleRangeNonPinSideInsertDiff > 0))
1579
- {
1580
- // FLEXIBLE Range:
1581
- //
1582
- // The range naturally shrunk to the point where it was smaller than the min length.
1583
- // We may need to manually add INSERT operations.
1584
- //
1585
- // Note: The originalRangeLength may actually be smaller than the finalRangeLength.
1586
-
1587
- NSInteger expectedDiff = finalRangeLength - originalRangeLength;
1588
- NSInteger actualDiff = insertCount - deleteCount;
1589
-
1590
- // Example 1: database near empty to begin with
1591
- //
1592
- // originalRangeLength = 1, finalRangeLength = 5, min = 5, insertCount = 5, deleteCount = 1
1593
- // expectedDiff = 4
1594
- // actualDiff = 4
1595
-
1596
- // Example 2: typical length dropping below min
1597
- //
1598
- // originalRangeLength = 5, finalRangeLength = 5, min = 5, insertCount = 0, deleteCount = 2
1599
- // expectedDiff = 0
1600
- // actualDiff = -2
1601
-
1602
- // Example 3: typical length dropping below min
1603
- //
1604
- // originalRangeLength = 10, finalRangeLength = 5, min = 5, insertCount = 0, deleteCount = 8
1605
- // expectedDiff = -5
1606
- // actualDiff = -8
1607
-
1608
- // Example 4: user changed min value on us without changing length
1609
- // (not technically supported, but not overly difficult to handle)
1610
- //
1611
- // originalRangeLength = 2, finalRangeLength = 5, min = 5, insertCount = 2, deleteCount = 0
1612
- // expectedDiff = 3
1613
- // actualDiff = 2
1614
-
1615
- if (actualDiff < expectedDiff)
1616
- {
1617
- numberOfInsertOperationsToManuallyAdd = expectedDiff - actualDiff;
1618
- }
1619
- }
1620
-
1621
- if (numberOfDeleteOperationsToManuallyAdd > 0)
1622
- {
1623
- // Manually add DELETE operations.
1624
- //
1625
- // These operations represent the objects that got pushed out of the final range,
1626
- // even though the items themselves didn't change.
1627
- //
1628
- // They are to go at the end opposite the pin.
1629
-
1630
- NSUInteger count = 0;
1631
-
1632
- NSUInteger index;
1633
- if (pin == YapDatabaseViewBeginning)
1634
- index = originalRangeLength - 1;
1635
- else
1636
- index = 0;
1637
-
1638
- while (count < numberOfDeleteOperationsToManuallyAdd)
1639
- {
1640
- // We need to be careful not to step on existing rowChanges.
1641
- // If there is an existing delete for this index, we need to continue onto the next index.
1642
- // If there is an existing move from this index, we need to continue onto the next index.
1643
- // If there is an existing update for this index, we need to change it to a delete.
1644
-
1645
- BOOL found = NO;
1646
-
1647
- for (YapDatabaseViewRowChange *rowChange in rowChanges)
1648
- {
1649
- if (rowChange->type == YapDatabaseViewChangeDelete ||
1650
- rowChange->type == YapDatabaseViewChangeMove)
1651
- {
1652
- if (rowChange->originalIndex == index && [rowChange->originalGroup isEqualToString:group])
1653
- {
1654
- found = YES;
1655
- break;
1656
- }
1657
- }
1658
- else if (rowChange->type == YapDatabaseViewChangeUpdate)
1659
- {
1660
- if (rowChange->originalIndex == index && [rowChange->originalGroup isEqualToString:group])
1661
- {
1662
- rowChange->type = YapDatabaseViewChangeDelete;
1663
-
1664
- count++;
1665
- found = YES;
1666
- break;
1667
- }
1668
- }
1669
- }
1670
-
1671
- if (!found)
1672
- {
1673
- YapDatabaseViewRowChange *rowChange =
1674
- [YapDatabaseViewRowChange deleteKey:nil inGroup:group atIndex:index];
1675
-
1676
- [rowChanges addObject:rowChange];
1677
- count++;
1678
- }
1679
-
1680
- if (pin == YapDatabaseViewBeginning)
1681
- index--;
1682
- else
1683
- index++;
1684
- }
1685
- }
1686
-
1687
- if ((numberOfInsertOperationsToManuallyAdd > 0) && (flexibleRangePinSideInsertDiff > 0))
1688
- {
1689
- // Manually add INSERT operations.
1690
- //
1691
- // These operations represent the objects that got pulled into the final range,
1692
- // even though the items themselves didn't change.
1693
- //
1694
- // They are to go pin side.
1695
- //
1696
- // Note: This code path is only taken if using a flexibleRange
1697
-
1698
- NSUInteger i = 0;
1699
- NSUInteger count = 0;
1700
-
1701
- NSUInteger index;
1702
- if (pin == YapDatabaseViewBeginning)
1703
- index = finalRangeMin;
1704
- else
1705
- index = finalRangeLength - 1;
1706
-
1707
- while ((count < numberOfInsertOperationsToManuallyAdd) && (i < flexibleRangePinSideInsertDiff))
1708
- {
1709
- // We need to be careful not to step on existing rowChanges.
1710
- // If there is an existing insert for this index, we need to continue onto the next index.
1711
- // If there is an existing move to this index, we need to continue onto the next index.
1712
- // If there is an existing update for this index, we need to change it to an insert.
1713
- //
1714
- // Note: I don't think the update scenario is actually possible.
1715
-
1716
- BOOL found = NO;
1717
-
1718
- for (YapDatabaseViewRowChange *rowChange in rowChanges)
1719
- {
1720
- if (rowChange->type == YapDatabaseViewChangeInsert ||
1721
- rowChange->type == YapDatabaseViewChangeMove)
1722
- {
1723
- if (rowChange->finalIndex == index && [rowChange->finalGroup isEqualToString:group])
1724
- {
1725
- found = YES;
1726
- break;
1727
- }
1728
- }
1729
- else if (rowChange->type == YapDatabaseViewChangeUpdate)
1730
- {
1731
- if (rowChange->finalIndex == index && [rowChange->finalGroup isEqualToString:group])
1732
- {
1733
- rowChange->type = YapDatabaseViewChangeInsert;
1734
-
1735
- count++;
1736
- found = YES;
1737
- break;
1738
- }
1739
- }
1740
- }
1741
-
1742
- if (!found)
1743
- {
1744
- YapDatabaseViewRowChange *rowChange =
1745
- [YapDatabaseViewRowChange insertKey:nil inGroup:group atIndex:index];
1746
-
1747
- [rowChanges addObject:rowChange];
1748
- count++;
1749
- }
1750
-
1751
- if (pin == YapDatabaseViewBeginning)
1752
- index++;
1753
- else
1754
- index--;
1755
-
1756
- i++;
1757
- }
1758
-
1759
- numberOfInsertOperationsToManuallyAdd -= count;
1760
- }
1761
-
1762
- if (numberOfInsertOperationsToManuallyAdd > 0)
1763
- {
1764
- // Manually add INSERT operations.
1765
- //
1766
- // These operations represent the objects that got pulled into the final range,
1767
- // even though the items themselves didn't change.
1768
- //
1769
- // They are to go at the end opposite the pin.
1770
-
1771
- NSUInteger count = 0;
1772
-
1773
- NSUInteger index;
1774
- if (pin == YapDatabaseViewBeginning)
1775
- index = finalRangeLength - 1;
1776
- else
1777
- index = 0;
1778
-
1779
- while (count < numberOfInsertOperationsToManuallyAdd)
1780
- {
1781
- // We need to be careful not to step on existing rowChanges.
1782
- // If there is an existing insert for this index, we need to continue onto the next index.
1783
- // If there is an existing move to this index, we need to continue onto the next index.
1784
- // If there is an existing update for this index, we need to change it to an insert.
1785
- //
1786
- // Note: I don't think the update scenario is actually possible.
1787
-
1788
- BOOL found = NO;
1789
-
1790
- for (YapDatabaseViewRowChange *rowChange in rowChanges)
1791
- {
1792
- if (rowChange->type == YapDatabaseViewChangeInsert ||
1793
- rowChange->type == YapDatabaseViewChangeMove)
1794
- {
1795
- if (rowChange->finalIndex == index && [rowChange->finalGroup isEqualToString:group])
1796
- {
1797
- found = YES;
1798
- break;
1799
- }
1800
- }
1801
- else if (rowChange->type == YapDatabaseViewChangeUpdate)
1802
- {
1803
- if (rowChange->finalIndex == index && [rowChange->finalGroup isEqualToString:group])
1804
- {
1805
- rowChange->type = YapDatabaseViewChangeInsert;
1806
-
1807
- count++;
1808
- found = YES;
1809
- break;
1810
- }
1811
- }
1812
- }
1813
-
1814
- if (!found)
1815
- {
1816
- YapDatabaseViewRowChange *rowChange =
1817
- [YapDatabaseViewRowChange insertKey:nil inGroup:group atIndex:index];
1818
-
1819
- [rowChanges addObject:rowChange];
1820
- count++;
1821
- }
1822
-
1823
- if (pin == YapDatabaseViewBeginning)
1824
- index--;
1825
- else
1826
- index++;
1827
- }
1828
- }
1829
-
1830
- //
1831
- // STEP 4.A : Update finalMappings if needed (by updating rangeOpts.length & rangeOpts.offset)
1832
-
1833
- if ((originalRangeLength != finalRangeLength) || (originalRangeOffset != finalRangeOffset))
1834
- {
1835
- [finalMappings updateRangeOptionsForGroup:group withNewLength:finalRangeLength newOffset:finalRangeOffset];
1836
- rangeOptionsChanged = YES;
1837
- }
1838
-
1839
- } // for (NSString *group in rangeOptions)
1840
-
1841
- // Step 4.B : Update finalMappings if needed (by updating visibleGroups)
1842
-
1843
- if (rangeOptionsChanged)
1844
- {
1845
- [finalMappings updateVisibility];
1846
- }
1847
-
1848
- //
1849
- // STEP 5 : Set the originalSection & finalSection
1850
- // STEP 6 : Reverse indexes for reversed groups
1851
- //
1852
-
1853
- NSSet *reverse = [originalMappings reverse];
1854
-
1855
- for (YapDatabaseViewRowChange *rowChange in rowChanges)
1856
- {
1857
- // Set the originalSection & finalSection
1858
-
1859
- if (rowChange->type == YapDatabaseViewChangeDelete)
1860
- {
1861
- rowChange->originalSection = [originalMappings sectionForGroup:rowChange->originalGroup];
1862
- }
1863
- else if (rowChange->type == YapDatabaseViewChangeInsert)
1864
- {
1865
- rowChange->finalSection = [finalMappings sectionForGroup:rowChange->finalGroup];
1866
- }
1867
- else if (rowChange->type == YapDatabaseViewChangeUpdate)
1868
- {
1869
- rowChange->originalSection = [originalMappings sectionForGroup:rowChange->originalGroup];
1870
- rowChange->finalSection = [finalMappings sectionForGroup:rowChange->finalGroup];
1871
-
1872
- if (rowChange->originalSection != rowChange->finalSection)
1873
- {
1874
- // Turn the update into a move.
1875
- // If we don't do so, UITableView seems to do the wrong thing.
1876
-
1877
- rowChange->type = YapDatabaseViewChangeMove;
1878
- }
1879
- }
1880
- else // if (rowChange->type == YapDatabaseViewChangeMove)
1881
- {
1882
- rowChange->originalSection = [originalMappings sectionForGroup:rowChange->originalGroup];
1883
- rowChange->finalSection = [finalMappings sectionForGroup:rowChange->finalGroup];
1884
- }
1885
-
1886
- // Reverse indexes for reversed groups.
1887
- //
1888
- // For example, if the group contains 4 items, the indexes get reversed like so:
1889
- // 0 -> 3
1890
- // 1 -> 2
1891
- // 2 -> 1
1892
- // 3 -> 0
1893
- //
1894
- // Basically, we find the midpoint, and then move each index to the other side of the midpoint,
1895
- // but we keep its distance from the midpoint the same.
1896
-
1897
- if ([reverse containsObject:rowChange->originalGroup])
1898
- {
1899
- NSUInteger count = [originalMappings visibleCountForGroup:rowChange->originalGroup];
1900
- double mid = (count - 1) / 2.0;
1901
-
1902
- rowChange->originalIndex = (NSUInteger)(mid - (rowChange->originalIndex - mid));
1903
- }
1904
-
1905
- if ([reverse containsObject:rowChange->finalGroup])
1906
- {
1907
- NSUInteger count = [finalMappings visibleCountForGroup:rowChange->finalGroup];
1908
- double mid = (count - 1) / 2.0;
1909
-
1910
- rowChange->finalIndex = (NSUInteger)(mid - (rowChange->finalIndex - mid));
1911
- }
1912
- }
1913
-
1914
- //
1915
- // STEP 7 : Handle group consolidation
1916
- //
1917
-
1918
- BOOL oldIsUsingConsolidatedGroup = [originalMappings isUsingConsolidatedGroup];
1919
- BOOL newIsUsingConsolidatedGroup = [finalMappings isUsingConsolidatedGroup];
1920
-
1921
- if (oldIsUsingConsolidatedGroup && newIsUsingConsolidatedGroup)
1922
- {
1923
- //
1924
- // The groups were previously consolidated, and still are.
1925
- //
1926
-
1927
- NSString *consolidatedGroupName = [originalMappings consolidatedGroupName];
1928
-
1929
- // Step 1
1930
- //
1931
- // - calculate original & final offset for each group
1932
-
1933
- NSArray *allGroups = [originalMappings allGroups];
1934
-
1935
- NSMutableDictionary *originalOffsets = [NSMutableDictionary dictionaryWithCapacity:[allGroups count]];
1936
- NSMutableDictionary *finalOffsets = [NSMutableDictionary dictionaryWithCapacity:[allGroups count]];
1937
-
1938
- NSUInteger originalOffset = 0;
1939
- NSUInteger finalOffset = 0;
1940
-
1941
- for (NSString *group in allGroups)
1942
- {
1943
- [originalOffsets setObject:@(originalOffset) forKey:group];
1944
- [finalOffsets setObject:@(finalOffset) forKey:group];
1945
-
1946
- originalOffset += [originalMappings visibleCountForGroup:group];
1947
- finalOffset += [finalMappings visibleCountForGroup:group];
1948
- }
1949
-
1950
- // Step 2
1951
- //
1952
- // - change section to zero, and group to consolidatedGroupName for each change
1953
- // - increment original & final row index for each change
1954
-
1955
- for (YapDatabaseViewRowChange *rowChange in rowChanges)
1956
- {
1957
- if (rowChange->type == YapDatabaseViewChangeDelete)
1958
- {
1959
- NSUInteger oOffset = [[originalOffsets objectForKey:rowChange->originalGroup] unsignedIntegerValue];
1960
-
1961
- rowChange->originalGroup = consolidatedGroupName;
1962
- rowChange->originalSection = 0;
1963
- rowChange->originalIndex += oOffset;
1964
- }
1965
- else if (rowChange->type == YapDatabaseViewChangeInsert)
1966
- {
1967
- NSUInteger fOffset = [[finalOffsets objectForKey:rowChange->finalGroup] unsignedIntegerValue];
1968
-
1969
- rowChange->finalGroup = consolidatedGroupName;
1970
- rowChange->finalSection = 0;
1971
- rowChange->finalIndex += fOffset;
1972
- }
1973
- else if (rowChange->type == YapDatabaseViewChangeMove)
1974
- {
1975
- NSUInteger oOffset = [[originalOffsets objectForKey:rowChange->originalGroup] unsignedIntegerValue];
1976
- NSUInteger fOffset = [[finalOffsets objectForKey:rowChange->finalGroup] unsignedIntegerValue];
1977
-
1978
- rowChange->originalGroup = consolidatedGroupName;
1979
- rowChange->originalSection = 0;
1980
- rowChange->originalIndex += oOffset;
1981
-
1982
- rowChange->finalGroup = consolidatedGroupName;
1983
- rowChange->finalSection = 0;
1984
- rowChange->finalIndex += fOffset;
1985
- }
1986
- else // if (rowChange->type == YapDatabaseViewChangeUpdate)
1987
- {
1988
- NSUInteger oOffset = [[originalOffsets objectForKey:rowChange->originalGroup] unsignedIntegerValue];
1989
- NSUInteger fOffset = [[finalOffsets objectForKey:rowChange->finalGroup] unsignedIntegerValue];
1990
-
1991
- rowChange->originalGroup = consolidatedGroupName;
1992
- rowChange->originalSection = 0;
1993
- rowChange->originalIndex += oOffset;
1994
-
1995
- rowChange->finalGroup = consolidatedGroupName;
1996
- rowChange->finalSection = 0;
1997
- rowChange->finalIndex += fOffset;
1998
-
1999
- if (rowChange->originalIndex != rowChange->finalIndex)
2000
- {
2001
- rowChange->type = YapDatabaseViewChangeMove;
2002
- }
2003
- }
2004
- }
2005
- }
2006
- else if (!oldIsUsingConsolidatedGroup && newIsUsingConsolidatedGroup)
2007
- {
2008
- //
2009
- // Switching from groups to consolidated group
2010
- //
2011
-
2012
- NSString *consolidatedGroupName = [originalMappings consolidatedGroupName];
2013
-
2014
- // Step 1
2015
- //
2016
- // - calculate the offsets for each group within the consolidated group
2017
-
2018
- NSArray *allGroups = [originalMappings allGroups];
2019
-
2020
- NSMutableDictionary *finalOffsets = [NSMutableDictionary dictionaryWithCapacity:[allGroups count]];
2021
- NSUInteger finalOffset = 0;
2022
-
2023
- for (NSString *group in allGroups)
2024
- {
2025
- [finalOffsets setObject:@(finalOffset) forKey:group];
2026
-
2027
- finalOffset += [finalMappings visibleCountForGroup:group];
2028
- }
2029
-
2030
- // Step 2
2031
- //
2032
- // - enumerate over every single row that was visible in the originalMappings
2033
- // - check to see if its already represented in the existing array of rowChanges
2034
- // - if not, then inject a move operation for it
2035
-
2036
- NSUInteger beginningChangeCount = [rowChanges count];
2037
-
2038
- for (NSString *group in [originalMappings visibleGroups])
2039
- {
2040
- NSUInteger originalSection = [originalMappings sectionForGroup:group];
2041
- NSUInteger finalSection = [finalMappings sectionForGroup:group];
2042
-
2043
- NSUInteger originalGroupCount = [originalMappings visibleCountForGroup:group];
2044
-
2045
- for (NSUInteger originalIndex = 0; originalIndex < originalGroupCount; originalIndex++)
2046
- {
2047
- BOOL found = NO;
2048
- NSUInteger finalIndex = originalIndex;
2049
-
2050
- for (NSUInteger i = 0; i < beginningChangeCount; i++)
2051
- {
2052
- YapDatabaseViewRowChange *rowChange = [rowChanges objectAtIndex:i];
2053
-
2054
- if (rowChange->type != YapDatabaseViewChangeInsert &&
2055
- rowChange->originalSection == originalSection &&
2056
- rowChange->originalIndex == originalIndex)
2057
- {
2058
- found = YES;
2059
- break;
2060
- }
2061
-
2062
- if (rowChange->type == YapDatabaseViewChangeDelete ||
2063
- rowChange->type == YapDatabaseViewChangeMove )
2064
- {
2065
- if (rowChange->originalSection == originalSection)
2066
- {
2067
- if (rowChange->originalIndex < finalIndex)
2068
- {
2069
- // A row was deleted below our row.
2070
- // So its finalIndex gets decremented.
2071
- finalIndex--;
2072
- }
2073
- }
2074
- }
2075
-
2076
- if (rowChange->type == YapDatabaseViewChangeInsert ||
2077
- rowChange->type == YapDatabaseViewChangeMove )
2078
- {
2079
- if (rowChange->finalSection == finalSection)
2080
- {
2081
- if (rowChange->finalIndex <= finalIndex)
2082
- {
2083
- // A row was inserted below our row.
2084
- // So its finalIndex gets incremented.
2085
- finalIndex++;
2086
- }
2087
- }
2088
- }
2089
- }
2090
-
2091
- if (!found)
2092
- {
2093
- YapDatabaseViewRowChange *op = [[YapDatabaseViewRowChange alloc] init];
2094
- op->type = YapDatabaseViewChangeMove;
2095
- op->key = nil;
2096
- op->changes = 0;
2097
-
2098
- op->originalGroup = group;
2099
- op->originalSection = originalSection;
2100
- op->originalIndex = originalIndex;
2101
-
2102
- NSUInteger finalGroupOffset = [[finalOffsets objectForKey:group] unsignedIntegerValue];
2103
-
2104
- op->finalGroup = consolidatedGroupName;
2105
- op->finalSection = 0;
2106
- op->finalIndex = finalGroupOffset + finalIndex;
2107
-
2108
- [rowChanges addObject:op];
2109
- }
2110
- }
2111
- }
2112
-
2113
- // Step 3
2114
- //
2115
- // - update the finalGroup/finalSection/finalIndex for every rowChange
2116
- // (excluding the one's we injected)
2117
-
2118
- for (NSUInteger i = 0; i < beginningChangeCount; i++)
2119
- {
2120
- YapDatabaseViewRowChange *rowChange = [rowChanges objectAtIndex:i];
2121
-
2122
- if (rowChange->type == YapDatabaseViewChangeInsert)
2123
- {
2124
- NSUInteger fOffset = [[finalOffsets objectForKey:rowChange->finalGroup] unsignedIntegerValue];
2125
-
2126
- rowChange->finalGroup = consolidatedGroupName;
2127
- rowChange->finalSection = 0;
2128
- rowChange->finalIndex += fOffset;
2129
- }
2130
- else if (rowChange->type == YapDatabaseViewChangeMove)
2131
- {
2132
- NSUInteger fOffset = [[finalOffsets objectForKey:rowChange->finalGroup] unsignedIntegerValue];
2133
-
2134
- rowChange->finalGroup = consolidatedGroupName;
2135
- rowChange->finalSection = 0;
2136
- rowChange->finalIndex += fOffset;
2137
- }
2138
- else if (rowChange->type == YapDatabaseViewChangeUpdate)
2139
- {
2140
- rowChange->type = YapDatabaseViewChangeMove;
2141
-
2142
- NSUInteger fOffset = [[finalOffsets objectForKey:rowChange->finalGroup] unsignedIntegerValue];
2143
-
2144
- rowChange->finalGroup = consolidatedGroupName;
2145
- rowChange->finalSection = 0;
2146
- rowChange->finalIndex += fOffset;
2147
- }
2148
- }
2149
- }
2150
- else if (oldIsUsingConsolidatedGroup && !newIsUsingConsolidatedGroup)
2151
- {
2152
- //
2153
- // Switching from consolidated group to groups
2154
- //
2155
-
2156
- NSString *consolidatedGroupName = [originalMappings consolidatedGroupName];
2157
-
2158
- // Step 1
2159
- //
2160
- // - calculate the offsets for each group within the consolidated group
2161
-
2162
- NSArray *allGroups = [originalMappings allGroups];
2163
-
2164
- NSMutableDictionary *originalOffsets = [NSMutableDictionary dictionaryWithCapacity:[allGroups count]];
2165
-
2166
- NSUInteger originalOffset = 0;
2167
-
2168
- for (NSString *group in allGroups)
2169
- {
2170
- [originalOffsets setObject:@(originalOffset) forKey:group];
2171
-
2172
- originalOffset += [originalMappings visibleCountForGroup:group];
2173
- }
2174
-
2175
- // Step 2
2176
- //
2177
- // - enumerate over every single row that was visible in the originalMappings
2178
- // - check to see if its already represented in the existing array of rowChanges
2179
- // - if not, then inject a move operation for it
2180
-
2181
- NSUInteger beginningChangeCount = [rowChanges count];
2182
-
2183
- for (NSString *group in [originalMappings visibleGroups])
2184
- {
2185
- NSUInteger originalSection = [originalMappings sectionForGroup:group];
2186
- NSUInteger finalSection = [finalMappings sectionForGroup:group];
2187
-
2188
- NSUInteger originalGroupCount = [originalMappings visibleCountForGroup:group];
2189
-
2190
- for (NSUInteger originalIndex = 0; originalIndex < originalGroupCount; originalIndex++)
2191
- {
2192
- BOOL found = NO;
2193
- NSUInteger finalIndex = originalIndex;
2194
-
2195
- for (NSUInteger i = 0; i < beginningChangeCount; i++)
2196
- {
2197
- YapDatabaseViewRowChange *rowChange = [rowChanges objectAtIndex:i];
2198
-
2199
- if (rowChange->type != YapDatabaseViewChangeInsert &&
2200
- rowChange->originalSection == originalSection &&
2201
- rowChange->originalIndex == originalIndex)
2202
- {
2203
- found = YES;
2204
- break;
2205
- }
2206
-
2207
- if (rowChange->type == YapDatabaseViewChangeDelete ||
2208
- rowChange->type == YapDatabaseViewChangeMove )
2209
- {
2210
- if (rowChange->originalSection == originalSection)
2211
- {
2212
- if (rowChange->originalIndex < finalIndex)
2213
- {
2214
- // A row was deleted below our row.
2215
- // So its finalIndex gets decremented.
2216
- finalIndex--;
2217
- }
2218
- }
2219
- }
2220
-
2221
- if (rowChange->type == YapDatabaseViewChangeInsert ||
2222
- rowChange->type == YapDatabaseViewChangeMove )
2223
- {
2224
- if (rowChange->finalSection == finalSection)
2225
- {
2226
- if (rowChange->finalIndex <= finalIndex)
2227
- {
2228
- // A row was inserted below our row.
2229
- // So its finalIndex gets incremented.
2230
- finalIndex++;
2231
- }
2232
- }
2233
- }
2234
- }
2235
-
2236
- if (!found)
2237
- {
2238
- YapDatabaseViewRowChange *op = [[YapDatabaseViewRowChange alloc] init];
2239
- op->type = YapDatabaseViewChangeMove;
2240
- op->key = nil;
2241
- op->changes = 0;
2242
-
2243
- NSUInteger originalGroupOffset = [[originalOffsets objectForKey:group] unsignedIntegerValue];
2244
-
2245
- op->originalGroup = consolidatedGroupName;
2246
- op->originalSection = 0;
2247
- op->originalIndex = originalGroupOffset + originalIndex;
2248
-
2249
- op->finalGroup = group;
2250
- op->finalSection = finalSection;
2251
- op->finalIndex = finalIndex;
2252
-
2253
- [rowChanges addObject:op];
2254
- }
2255
- }
2256
- }
2257
-
2258
- // Step 3
2259
- //
2260
- // - update the originalGroup/originalSection/originalIndex for every rowChange
2261
- // (excluding the one's we injected)
2262
-
2263
- for (NSUInteger i = 0; i < beginningChangeCount; i++)
2264
- {
2265
- YapDatabaseViewRowChange *rowChange = [rowChanges objectAtIndex:i];
2266
-
2267
- if (rowChange->type == YapDatabaseViewChangeDelete)
2268
- {
2269
- NSUInteger oOffset = [[originalOffsets objectForKey:rowChange->originalGroup] unsignedIntegerValue];
2270
-
2271
- rowChange->originalGroup = consolidatedGroupName;
2272
- rowChange->originalSection = 0;
2273
- rowChange->originalIndex += oOffset;
2274
- }
2275
- else if (rowChange->type == YapDatabaseViewChangeMove)
2276
- {
2277
- NSUInteger oOffset = [[originalOffsets objectForKey:rowChange->originalGroup] unsignedIntegerValue];
2278
-
2279
- rowChange->originalGroup = consolidatedGroupName;
2280
- rowChange->originalSection = 0;
2281
- rowChange->originalIndex += oOffset;
2282
- }
2283
- else if (rowChange->type == YapDatabaseViewChangeUpdate)
2284
- {
2285
- rowChange->type = YapDatabaseViewChangeMove;
2286
-
2287
- NSUInteger oOffset = [[originalOffsets objectForKey:rowChange->originalGroup] unsignedIntegerValue];
2288
-
2289
- rowChange->originalGroup = consolidatedGroupName;
2290
- rowChange->originalSection = 0;
2291
- rowChange->originalIndex += oOffset;
2292
- }
2293
- }
2294
- }
2295
- }
2296
-
2297
- /**
2298
- * This method applies the given mappings to the processed list of section changes.
2299
- * It will filter the sectionChanges array to properly represent the configuration of the mappings.
2300
- **/
2301
- + (void)postProcessAndFilterSectionChanges:(NSMutableArray *)sectionChanges
2302
- withOriginalMappings:(YapDatabaseViewMappings *)originalMappings
2303
- finalMappings:(YapDatabaseViewMappings *)finalMappings
2304
- {
2305
- //
2306
- // STEP 1 : Handle dynamic sections
2307
- //
2308
-
2309
- NSUInteger i = 0;
2310
- while (i < [sectionChanges count])
2311
- {
2312
- YapDatabaseViewSectionChange *sectionChange = [sectionChanges objectAtIndex:i];
2313
-
2314
- if (sectionChange->type == YapDatabaseViewChangeDelete)
2315
- {
2316
- // Although a group was deleted, the user may be allowing empty sections.
2317
- // If so, we shouldn't emit a removeSection change.
2318
-
2319
- NSUInteger originalSection = [originalMappings sectionForGroup:sectionChange->group];
2320
- NSUInteger finalSection = [finalMappings sectionForGroup:sectionChange->group];
2321
-
2322
- if ((originalSection != NSNotFound) && (finalSection == NSNotFound))
2323
- {
2324
- // Emit
2325
- sectionChange->originalSection = originalSection;
2326
- i++;
2327
- }
2328
- else
2329
- {
2330
- // Don't emit
2331
- [sectionChanges removeObjectAtIndex:i];
2332
- }
2333
- }
2334
- else // if (sectionChange->type == YapDatabaseViewChangeInsert)
2335
- {
2336
- // Although a group was inserted, the user may have been allowing empty sections.
2337
- // If so, we shouldn't emit an insertSection change.
2338
-
2339
- NSUInteger originalSection = [originalMappings sectionForGroup:sectionChange->group];
2340
- NSUInteger finalSection = [finalMappings sectionForGroup:sectionChange->group];
2341
-
2342
- if ((originalSection == NSNotFound) && (finalSection != NSNotFound))
2343
- {
2344
- // Emit
2345
- sectionChange->finalSection = finalSection;
2346
- i++;
2347
- }
2348
- else
2349
- {
2350
- // Don't emit
2351
- [sectionChanges removeObjectAtIndex:i];
2352
- }
2353
- }
2354
- }
2355
-
2356
- //
2357
- // STEP 2 : Handle group consolidation
2358
- //
2359
-
2360
- BOOL oldIsUsingConsolidatedGroup = [originalMappings isUsingConsolidatedGroup];
2361
- BOOL newIsUsingConsolidatedGroup = [finalMappings isUsingConsolidatedGroup];
2362
-
2363
- if (oldIsUsingConsolidatedGroup && newIsUsingConsolidatedGroup)
2364
- {
2365
- //
2366
- // The groups were previously consolidated, and still are.
2367
- //
2368
-
2369
- // - clear section changes (everything stays within consolidated group)
2370
-
2371
- [sectionChanges removeAllObjects];
2372
- }
2373
- else if (!oldIsUsingConsolidatedGroup && newIsUsingConsolidatedGroup)
2374
- {
2375
- //
2376
- // Switching from groups to consolidated group
2377
- //
2378
-
2379
- // - clear section changes (so we can set them manually)
2380
-
2381
- [sectionChanges removeAllObjects];
2382
-
2383
- // - insert section delete for all original sections
2384
-
2385
- NSUInteger originalSection = 0;
2386
- for (NSString *originalGroup in [originalMappings visibleGroups])
2387
- {
2388
- YapDatabaseViewSectionChange *deleteOp = [YapDatabaseViewSectionChange deleteGroup:originalGroup];
2389
- deleteOp->originalSection = originalSection;
2390
-
2391
- [sectionChanges addObject:deleteOp];
2392
- originalSection++;
2393
- }
2394
-
2395
- // - insert section insert for consolidated group
2396
-
2397
- NSString *consolidatedGroupName = [originalMappings consolidatedGroupName];
2398
-
2399
- YapDatabaseViewSectionChange *insertOp = [YapDatabaseViewSectionChange insertGroup:consolidatedGroupName];
2400
- insertOp->finalSection = 0;
2401
-
2402
- [sectionChanges addObject:insertOp];
2403
- }
2404
- else if (oldIsUsingConsolidatedGroup && !newIsUsingConsolidatedGroup)
2405
- {
2406
- //
2407
- // Switching from consolidated group to groups
2408
- //
2409
-
2410
- // - clear section changes (so we can set them manually)
2411
-
2412
- [sectionChanges removeAllObjects];
2413
-
2414
- // - insert section delete for consolidatedGroup
2415
-
2416
- NSString *consolidatedGroupName = [originalMappings consolidatedGroupName];
2417
-
2418
- YapDatabaseViewSectionChange *deleteOp = [YapDatabaseViewSectionChange deleteGroup:consolidatedGroupName];
2419
- deleteOp->originalSection = 0;
2420
-
2421
- [sectionChanges addObject:deleteOp];
2422
-
2423
- // - insert section insert for all final sections
2424
-
2425
- NSUInteger finalSection = 0;
2426
- for (NSString *finalGroup in [finalMappings visibleGroups])
2427
- {
2428
- YapDatabaseViewSectionChange *insertOp = [YapDatabaseViewSectionChange insertGroup:finalGroup];
2429
- insertOp->finalSection = finalSection;
2430
-
2431
- [sectionChanges addObject:insertOp];
2432
- finalSection++;
2433
- }
2434
- }
2435
- }
2436
-
2437
- + (void)getSectionChanges:(NSArray **)sectionChangesPtr
2438
- rowChanges:(NSArray **)rowChangesPtr
2439
- withOriginalMappings:(YapDatabaseViewMappings *)originalMappings
2440
- finalMappings:(YapDatabaseViewMappings *)finalMappings
2441
- fromChanges:(NSArray *)changes
2442
- {
2443
- NSMutableArray *sectionChanges = nil;
2444
- NSMutableArray *rowChanges = nil;
2445
-
2446
- [originalMappings setAutoConsolidatingDisabled:YES]; // disable during processing
2447
- [finalMappings setAutoConsolidatingDisabled:YES]; // disable during processing
2448
-
2449
- // PRE-PROCESSING
2450
- //
2451
- // Remove any items from the changes array that don't concern us.
2452
-
2453
- [self preProcessChanges:changes
2454
- withOriginalMappings:originalMappings
2455
- finalMappings:finalMappings
2456
- andGetSectionChanges:&sectionChanges
2457
- rowChanges:&rowChanges];
2458
-
2459
- //
2460
- // PROCESSING
2461
- //
2462
- // This is where the magic happens.
2463
- // Calculates original and final index of every change.
2464
-
2465
- [self processRowChanges:rowChanges];
2466
-
2467
- // CONSOLIDATION
2468
- //
2469
- // Merge multiple changes to same row into a single change.
2470
- // Merge multiple changes to a group into a zero or one change.
2471
-
2472
- [self consolidateRowChanges:rowChanges];
2473
-
2474
- [self consolidateSectionChanges:sectionChanges];
2475
-
2476
- //
2477
- // POST-PROCESSING
2478
- //
2479
- // This is where we apply the mappings to filter & alter the changeset.
2480
-
2481
- [self postProcessAndFilterRowChanges:rowChanges
2482
- withOriginalMappings:originalMappings
2483
- finalMappings:finalMappings];
2484
-
2485
- [self postProcessAndFilterSectionChanges:sectionChanges
2486
- withOriginalMappings:originalMappings
2487
- finalMappings:finalMappings];
2488
-
2489
- //
2490
- // DONE
2491
- //
2492
-
2493
- [originalMappings setAutoConsolidatingDisabled:NO];
2494
- [finalMappings setAutoConsolidatingDisabled:NO];
2495
-
2496
- if (sectionChangesPtr) *sectionChangesPtr = sectionChanges;
2497
- if (rowChangesPtr) *rowChangesPtr = rowChanges;
2498
- }
2499
-
2500
- @end