motion-yapper 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.travis.yml +6 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +63 -0
- data/README.md +16 -0
- data/Rakefile +20 -0
- data/app/app_delegate.rb +5 -0
- data/lib/yapper.rb +30 -0
- data/lib/yapper/attachment.rb +48 -0
- data/lib/yapper/bson.rb +20 -0
- data/lib/yapper/config.rb +18 -0
- data/lib/yapper/db.rb +151 -0
- data/lib/yapper/document.rb +54 -0
- data/lib/yapper/document/attachment.rb +26 -0
- data/lib/yapper/document/callbacks.rb +86 -0
- data/lib/yapper/document/persistance.rb +171 -0
- data/lib/yapper/document/relation.rb +84 -0
- data/lib/yapper/document/selection.rb +100 -0
- data/lib/yapper/extensions.rb +80 -0
- data/lib/yapper/log.rb +5 -0
- data/lib/yapper/sync.rb +134 -0
- data/lib/yapper/sync/data.rb +12 -0
- data/lib/yapper/sync/event.rb +194 -0
- data/lib/yapper/sync/queue.rb +164 -0
- data/lib/yapper/timestamps.rb +16 -0
- data/lib/yapper/version.rb +3 -0
- data/lib/yapper/yapper.rb +2 -0
- data/spec/helpers/time_helper.rb +3 -0
- data/spec/integration/all_spec.rb +40 -0
- data/spec/integration/callback_spec.rb +87 -0
- data/spec/integration/db_spec.rb +40 -0
- data/spec/integration/find_spec.rb +51 -0
- data/spec/integration/persistance_spec.rb +118 -0
- data/spec/integration/relation_spec.rb +174 -0
- data/spec/integration/sync_spec.rb +42 -0
- data/spec/integration/timestamps_spec.rb +34 -0
- data/spec/integration/types_spec.rb +23 -0
- data/spec/integration/when_spec.rb +29 -0
- data/spec/integration/where_spec.rb +132 -0
- data/vendor/Podfile.lock +24 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +641 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +1396 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +327 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +113 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +321 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +150 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +157 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +43 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +143 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +370 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +848 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +167 -0
- data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +191 -0
- data/vendor/Pods/AFNetworking/LICENSE +19 -0
- data/vendor/Pods/AFNetworking/README.md +208 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +641 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +113 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +43 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +370 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/vendor/Pods/BuildHeaders/CocoaLumberjack/ContextFilterLogFormatter.h +65 -0
- data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDASLLogger.h +41 -0
- data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDAbstractDatabaseLogger.h +102 -0
- data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDFileLogger.h +334 -0
- data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDLog.h +601 -0
- data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDTTYLogger.h +167 -0
- data/vendor/Pods/BuildHeaders/CocoaLumberjack/DispatchQueueLogFormatter.h +116 -0
- data/vendor/Pods/BuildHeaders/NSData+MD5Digest/NSData+MD5Digest.h +18 -0
- data/vendor/Pods/BuildHeaders/Reachability/Reachability.h +109 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapCache.h +90 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapCollectionKey.h +20 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabase.h +547 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseConnection.h +447 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseConnectionState.h +29 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseDefaults.h +37 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtension.h +15 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionConnection.h +11 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionPrivate.h +440 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionTransaction.h +11 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredView.h +108 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewConnection.h +12 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewPrivate.h +19 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewTransaction.h +39 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearch.h +89 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchConnection.h +32 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchPrivate.h +69 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchSnippetOptions.h +79 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchTransaction.h +68 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseLogging.h +158 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseManager.h +17 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabasePrivate.h +424 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseQuery.h +42 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndex.h +100 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexConnection.h +33 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +73 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexSetup.h +33 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexTransaction.h +58 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseStatement.h +13 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseString.h +121 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseTransaction.h +541 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseView.h +186 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewChange.h +272 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewChangePrivate.h +94 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewConnection.h +115 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewMappings.h +825 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewMappingsPrivate.h +72 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewOptions.h +56 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPage.h +36 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPageMetadata.h +27 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPrivate.h +153 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewRangeOptions.h +330 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewRangeOptionsPrivate.h +17 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewTransaction.h +447 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapMemoryTable.h +74 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapNull.h +17 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapSet.h +41 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapTouch.h +15 -0
- data/vendor/Pods/CocoaLumberjack/LICENSE.txt +18 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.h +41 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.m +99 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.h +102 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.m +727 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.h +334 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.m +1353 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.h +601 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.m +1083 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.h +167 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.m +1479 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/ContextFilterLogFormatter.h +65 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/ContextFilterLogFormatter.m +191 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DispatchQueueLogFormatter.h +116 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DispatchQueueLogFormatter.m +251 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/README.txt +7 -0
- data/vendor/Pods/CocoaLumberjack/README.markdown +37 -0
- data/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +641 -0
- data/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +113 -0
- data/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/vendor/Pods/Headers/AFNetworking/AFNetworking.h +43 -0
- data/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +370 -0
- data/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/vendor/Pods/Headers/CocoaLumberjack/ContextFilterLogFormatter.h +65 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DDASLLogger.h +41 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DDAbstractDatabaseLogger.h +102 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DDFileLogger.h +334 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DDLog.h +601 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DDTTYLogger.h +167 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DispatchQueueLogFormatter.h +116 -0
- data/vendor/Pods/Headers/NSData+MD5Digest/NSData+MD5Digest.h +18 -0
- data/vendor/Pods/Headers/Reachability/Reachability.h +109 -0
- data/vendor/Pods/Headers/YapDatabase/YapCache.h +90 -0
- data/vendor/Pods/Headers/YapDatabase/YapCollectionKey.h +20 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabase.h +547 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnection.h +447 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnectionState.h +29 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseDefaults.h +37 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtension.h +15 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionConnection.h +11 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionPrivate.h +440 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionTransaction.h +11 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredView.h +108 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewConnection.h +12 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewPrivate.h +19 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewTransaction.h +39 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearch.h +89 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchConnection.h +32 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchPrivate.h +69 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchSnippetOptions.h +79 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchTransaction.h +68 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseLogging.h +158 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseManager.h +17 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabasePrivate.h +424 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseQuery.h +42 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndex.h +100 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexConnection.h +33 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +73 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexSetup.h +33 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexTransaction.h +58 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseStatement.h +13 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseString.h +121 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseTransaction.h +541 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseView.h +186 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChange.h +272 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChangePrivate.h +94 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewConnection.h +115 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappings.h +825 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappingsPrivate.h +72 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewOptions.h +56 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPage.h +36 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPageMetadata.h +27 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPrivate.h +153 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewRangeOptions.h +330 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewRangeOptionsPrivate.h +17 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewTransaction.h +447 -0
- data/vendor/Pods/Headers/YapDatabase/YapMemoryTable.h +74 -0
- data/vendor/Pods/Headers/YapDatabase/YapNull.h +17 -0
- data/vendor/Pods/Headers/YapDatabase/YapSet.h +41 -0
- data/vendor/Pods/Headers/YapDatabase/YapTouch.h +15 -0
- data/vendor/Pods/Headers/____Pods-AFNetworking-prefix.h +17 -0
- data/vendor/Pods/Headers/____Pods-CocoaLumberjack-prefix.h +5 -0
- data/vendor/Pods/Headers/____Pods-NSData+MD5Digest-prefix.h +5 -0
- data/vendor/Pods/Headers/____Pods-Reachability-prefix.h +5 -0
- data/vendor/Pods/Headers/____Pods-YapDatabase-prefix.h +5 -0
- data/vendor/Pods/Headers/____Pods-environment.h +38 -0
- data/vendor/Pods/Manifest.lock +24 -0
- data/vendor/Pods/NSData+MD5Digest/NSData+MD5Digest/NSData+MD5Digest.h +18 -0
- data/vendor/Pods/NSData+MD5Digest/NSData+MD5Digest/NSData+MD5Digest.m +39 -0
- data/vendor/Pods/NSData+MD5Digest/README.md +11 -0
- data/vendor/Pods/Pods-AFNetworking-Private.xcconfig +5 -0
- data/vendor/Pods/Pods-AFNetworking-dummy.m +5 -0
- data/vendor/Pods/Pods-AFNetworking-prefix.pch +17 -0
- data/vendor/Pods/Pods-AFNetworking.xcconfig +1 -0
- data/vendor/Pods/Pods-Acknowledgements.markdown +96 -0
- data/vendor/Pods/Pods-Acknowledgements.plist +142 -0
- data/vendor/Pods/Pods-CocoaLumberjack-Private.xcconfig +5 -0
- data/vendor/Pods/Pods-CocoaLumberjack-dummy.m +5 -0
- data/vendor/Pods/Pods-CocoaLumberjack-prefix.pch +5 -0
- data/vendor/Pods/Pods-CocoaLumberjack.xcconfig +0 -0
- data/vendor/Pods/Pods-NSData+MD5Digest-Private.xcconfig +5 -0
- data/vendor/Pods/Pods-NSData+MD5Digest-dummy.m +5 -0
- data/vendor/Pods/Pods-NSData+MD5Digest-prefix.pch +5 -0
- data/vendor/Pods/Pods-NSData+MD5Digest.xcconfig +0 -0
- data/vendor/Pods/Pods-Reachability-Private.xcconfig +5 -0
- data/vendor/Pods/Pods-Reachability-dummy.m +5 -0
- data/vendor/Pods/Pods-Reachability-prefix.pch +5 -0
- data/vendor/Pods/Pods-Reachability.xcconfig +1 -0
- data/vendor/Pods/Pods-YapDatabase-Private.xcconfig +5 -0
- data/vendor/Pods/Pods-YapDatabase-dummy.m +5 -0
- data/vendor/Pods/Pods-YapDatabase-prefix.pch +5 -0
- data/vendor/Pods/Pods-YapDatabase.xcconfig +1 -0
- data/vendor/Pods/Pods-dummy.m +5 -0
- data/vendor/Pods/Pods-environment.h +38 -0
- data/vendor/Pods/Pods-resources.sh +68 -0
- data/vendor/Pods/Pods.bridgesupport +5096 -0
- data/vendor/Pods/Pods.xcconfig +5 -0
- data/vendor/Pods/Pods.xcodeproj/project.pbxproj +5536 -0
- data/vendor/Pods/Reachability/LICENCE.txt +24 -0
- data/vendor/Pods/Reachability/README.md +65 -0
- data/vendor/Pods/Reachability/Reachability.h +109 -0
- data/vendor/Pods/Reachability/Reachability.m +527 -0
- data/vendor/Pods/YapDatabase/LICENSE.txt +18 -0
- data/vendor/Pods/YapDatabase/README.md +30 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/Internal/YapDatabaseFilteredViewPrivate.h +19 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.h +108 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.m +175 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewConnection.h +12 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewConnection.m +41 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.h +39 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.m +966 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/Internal/YapDatabaseFullTextSearchPrivate.h +69 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearch.h +89 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearch.m +146 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchConnection.h +32 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchConnection.m +298 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchSnippetOptions.h +79 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchSnippetOptions.m +95 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchTransaction.h +68 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchTransaction.m +1352 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/Internal/YapDatabaseExtensionPrivate.h +440 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtension.h +15 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtension.m +58 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionConnection.h +11 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionConnection.m +46 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionTransaction.h +11 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionTransaction.m +180 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/Internal/YapDatabaseSecondaryIndexPrivate.h +73 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.h +100 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.m +149 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexConnection.h +33 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexConnection.m +330 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexSetup.h +33 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexSetup.m +184 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexTransaction.h +58 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexTransaction.m +1166 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewChangePrivate.h +94 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewMappingsPrivate.h +72 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPage.h +36 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPage.mm +296 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPageMetadata.h +27 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPageMetadata.m +28 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPrivate.h +153 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewRangeOptionsPrivate.h +17 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.h +272 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.m +2494 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.h +825 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.m +1567 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewRangeOptions.h +330 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewRangeOptions.m +141 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.h +186 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.m +191 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.h +115 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.m +897 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewOptions.h +56 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewOptions.m +27 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.h +447 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.m +4505 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.h +90 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.m +453 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseConnectionState.h +29 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseConnectionState.m +48 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.h +37 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.m +83 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseLogging.h +158 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseLogging.m +73 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseManager.h +17 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseManager.m +56 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabasePrivate.h +424 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseStatement.h +13 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseStatement.m +26 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseString.h +121 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapMemoryTable.h +74 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapMemoryTable.m +603 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapNull.h +17 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapNull.m +31 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapTouch.h +15 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapTouch.m +31 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.h +20 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.m +194 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapDatabaseQuery.h +42 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapDatabaseQuery.m +96 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapSet.h +41 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapSet.m +82 -0
- data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.h +547 -0
- data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.m +2022 -0
- data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.h +447 -0
- data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.m +3874 -0
- data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.h +541 -0
- data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.m +5282 -0
- data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.bridgesupport +16 -0
- data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.h +13 -0
- data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.m +20 -0
- data/yapper.gemspec +24 -0
- metadata +458 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
#import <Foundation/Foundation.h>
|
2
|
+
#import "sqlite3.h"
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Simple wrapper class to facilitate storing sqlite3_stmt items as objects (primarily in YapCache).
|
6
|
+
**/
|
7
|
+
@interface YapDatabaseStatement : NSObject
|
8
|
+
|
9
|
+
- (id)initWithStatement:(sqlite3_stmt *)stmt;
|
10
|
+
|
11
|
+
@property (nonatomic, assign, readonly) sqlite3_stmt *stmt;
|
12
|
+
|
13
|
+
@end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#import "YapDatabaseStatement.h"
|
2
|
+
#import "YapDatabasePrivate.h"
|
3
|
+
|
4
|
+
|
5
|
+
@implementation YapDatabaseStatement
|
6
|
+
{
|
7
|
+
sqlite3_stmt *stmt;
|
8
|
+
}
|
9
|
+
|
10
|
+
@synthesize stmt = stmt;
|
11
|
+
|
12
|
+
- (id)initWithStatement:(sqlite3_stmt *)inStmt
|
13
|
+
{
|
14
|
+
if ((self = [super init]))
|
15
|
+
{
|
16
|
+
stmt = inStmt;
|
17
|
+
}
|
18
|
+
return self;
|
19
|
+
}
|
20
|
+
|
21
|
+
- (void)dealloc
|
22
|
+
{
|
23
|
+
sqlite_finalize_null(&stmt);
|
24
|
+
}
|
25
|
+
|
26
|
+
@end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
/**
|
2
|
+
* There are a LOT of conversions from NSString to char array.
|
3
|
+
* This happens in almost every method, where we bind text to prepared sqlite3 statements.
|
4
|
+
*
|
5
|
+
* It is inefficient to use [key UTF8String] for these situations.
|
6
|
+
* The Apple documentation is very explicit concerning the UTF8String method:
|
7
|
+
*
|
8
|
+
* > The returned C string is automatically freed just as a returned object would be released;
|
9
|
+
* > you should copy the C string if [you need] to store it outside of the
|
10
|
+
* > autorelease context in which the C string is created.
|
11
|
+
*
|
12
|
+
* In other words, the UTF8String method does a malloc for character buffer, copies the characters,
|
13
|
+
* and autoreleases the buffer (just like an autoreleased NSData instance).
|
14
|
+
*
|
15
|
+
* Thus we suffer a bunch of malloc's if we use UTF8String.
|
16
|
+
*
|
17
|
+
* Considering that almost all keys are likely to be relatively small,
|
18
|
+
* a much faster technique is to use the stack instead of the heap (with obvious precautions, see below).
|
19
|
+
*
|
20
|
+
* Note: This technique ONLY applies to key names and collection names.
|
21
|
+
* It does NOT apply to object/primitiveData or metadata. Those are binded to sqlite3 statements using binary blobs.
|
22
|
+
**/
|
23
|
+
|
24
|
+
|
25
|
+
/**
|
26
|
+
* We must be cautious and conservative so as to avoid stack overflow.
|
27
|
+
* This is possibe if really huge key names or collection names are used.
|
28
|
+
*
|
29
|
+
* The number below represents the largest amount of memory (in bytes) that will be allocated on the stack per string.
|
30
|
+
**/
|
31
|
+
#define YapDatabaseStringMaxStackLength (1024 * 4)
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Struct designed to be allocated on the stack.
|
35
|
+
* You then use the inline functions below to "setup" and "teardown" the struct.
|
36
|
+
* For example:
|
37
|
+
*
|
38
|
+
* > YapDatabaseString myKeyChar;
|
39
|
+
* > MakeYapDatabaseString(&myKeyChar, myNSStringKey);
|
40
|
+
* > ...
|
41
|
+
* > sqlite3_bind_text(statement, position, myKeyChar.str, myKeyChar.length, SQLITE_STATIC);
|
42
|
+
* > ...
|
43
|
+
* > sqlite3_clear_bindings(statement);
|
44
|
+
* > sqlite3_reset(statement);
|
45
|
+
* > FreeYapDatabaseString(&myKeyChar);
|
46
|
+
*
|
47
|
+
* There are 2 "public" fields:
|
48
|
+
* str - Pointer to the char[] string.
|
49
|
+
* length - Represents the length (in bytes) of the char[] str (excluding the NULL termination byte, as usual).
|
50
|
+
*
|
51
|
+
* The other 2 "private" fields are for internal use:
|
52
|
+
* strStack - If the string doesn't exceed YapDatabaseStringMaxStackLength,
|
53
|
+
* then the bytes are copied here (onto stack storage), and str actually points to strStack.
|
54
|
+
* strHeap - If the string exceeds YapDatabaseStringMaxStackLength,
|
55
|
+
* the space is allocated on the heap, strHeap holds the pointer, and str has the same pointer.
|
56
|
+
*
|
57
|
+
* Thus the "setup" and "teardown" methods below will automatically switch to heap storage (just like UTF8String),
|
58
|
+
* if the key/collection name is too long, and performance will be equivalent.
|
59
|
+
* But in the common case of short key/collection names, we can skip the more expensive heap allocation/deallocation.
|
60
|
+
**/
|
61
|
+
struct YapDatabaseString {
|
62
|
+
int length;
|
63
|
+
char strStack[YapDatabaseStringMaxStackLength];
|
64
|
+
char *strHeap;
|
65
|
+
char *str; // Pointer to either strStack or strHeap
|
66
|
+
};
|
67
|
+
typedef struct YapDatabaseString YapDatabaseString;
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Initializes the YapDatabaseString structure.
|
71
|
+
* It will automatically use heap storage if the given NSString is too long.
|
72
|
+
*
|
73
|
+
* This method should always be balanced with a call to FreeYapDatabaseString.
|
74
|
+
**/
|
75
|
+
NS_INLINE void MakeYapDatabaseString(YapDatabaseString *dbStr, NSString *nsStr)
|
76
|
+
{
|
77
|
+
if (nsStr)
|
78
|
+
{
|
79
|
+
// We convert to int because the sqlite3_bind_text() function expects an int parameter.
|
80
|
+
// So we can change it to int here, or we can cast everywhere throughout the project.
|
81
|
+
|
82
|
+
dbStr->length = (int)[nsStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
|
83
|
+
|
84
|
+
if ((dbStr->length + 1) <= YapDatabaseStringMaxStackLength)
|
85
|
+
{
|
86
|
+
dbStr->strHeap = NULL;
|
87
|
+
dbStr->str = dbStr->strStack;
|
88
|
+
}
|
89
|
+
else
|
90
|
+
{
|
91
|
+
dbStr->strHeap = (char *)malloc((dbStr->length + 1));
|
92
|
+
dbStr->str = dbStr->strHeap;
|
93
|
+
}
|
94
|
+
|
95
|
+
[nsStr getCString:dbStr->str maxLength:(dbStr->length + 1) encoding:NSUTF8StringEncoding];
|
96
|
+
}
|
97
|
+
else
|
98
|
+
{
|
99
|
+
dbStr->length = 0;
|
100
|
+
dbStr->strHeap = NULL;
|
101
|
+
dbStr->str = NULL;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
/**
|
106
|
+
* If heap storage was needed (because the string length exceeded YapDatabaseStringMaxStackLength),
|
107
|
+
* this method frees the heap allocated memory.
|
108
|
+
*
|
109
|
+
* In the common case of stack storage, strHeap will be NULL, and this method is essentially a no-op.
|
110
|
+
*
|
111
|
+
* This method should be invoked AFTER sqlite3_clear_bindings (assuming SQLITE_STATIC is used).
|
112
|
+
**/
|
113
|
+
NS_INLINE void FreeYapDatabaseString(YapDatabaseString *dbStr)
|
114
|
+
{
|
115
|
+
if (dbStr->strHeap)
|
116
|
+
{
|
117
|
+
free(dbStr->strHeap);
|
118
|
+
dbStr->strHeap = NULL;
|
119
|
+
dbStr->str = NULL;
|
120
|
+
}
|
121
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#import <Foundation/Foundation.h>
|
2
|
+
|
3
|
+
@class YapMemoryTableTransaction;
|
4
|
+
|
5
|
+
|
6
|
+
/**
|
7
|
+
* A "memory table" is a dictionary that supports versioning.
|
8
|
+
* There may be multiple values for a single key, with each value associated with a different snapshot.
|
9
|
+
*
|
10
|
+
* The memory table is accessed via a YapMemoryTableTransaction instance,
|
11
|
+
* which is itself associated with a particular timestamp. Thus the transaction is able to properly identify
|
12
|
+
* which version is appropriate for itself.
|
13
|
+
**/
|
14
|
+
@interface YapMemoryTable : NSObject
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Initializes a memory table.
|
18
|
+
*
|
19
|
+
* The keyClass is used for debugging, to ensure the proper key type is always used when accessing the table.
|
20
|
+
* The keyClass is used within NSAssert statements that typically get compiled out for release builds.
|
21
|
+
**/
|
22
|
+
- (id)initWithKeyClass:(Class)keyClass;
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Creates and returns a new connection associated with the shared cache.
|
26
|
+
**/
|
27
|
+
- (YapMemoryTableTransaction *)newReadTransactionWithSnapshot:(uint64_t)snapshot;
|
28
|
+
- (YapMemoryTableTransaction *)newReadWriteTransactionWithSnapshot:(uint64_t)snapshot;
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Invoked automatically by YapDatabase architecture.
|
32
|
+
**/
|
33
|
+
- (void)asyncCheckpoint:(int64_t)minSnapshot;
|
34
|
+
|
35
|
+
@end
|
36
|
+
|
37
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
38
|
+
#pragma mark -
|
39
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
+
|
41
|
+
@interface YapMemoryTableTransaction : NSObject
|
42
|
+
|
43
|
+
@property (nonatomic, readonly) uint64_t snapshot;
|
44
|
+
@property (nonatomic, readonly) BOOL isReadWriteTransaction;
|
45
|
+
|
46
|
+
- (id)objectForKey:(id)key;
|
47
|
+
|
48
|
+
- (void)enumerateKeysWithBlock:(void (^)(id key, BOOL *stop))block;
|
49
|
+
|
50
|
+
- (void)enumerateKeysAndObjectsWithBlock:(void (^)(id key, id obj, BOOL *stop))block;
|
51
|
+
|
52
|
+
//
|
53
|
+
// For ReadWrite transactions:
|
54
|
+
|
55
|
+
- (void)setObject:(id)object forKey:(id)key;
|
56
|
+
|
57
|
+
- (void)removeObjectForKey:(id)key;
|
58
|
+
- (void)removeObjectsForKeys:(NSArray *)keys;
|
59
|
+
|
60
|
+
- (void)removeAllObjects;
|
61
|
+
|
62
|
+
//
|
63
|
+
// Batch access / modifications
|
64
|
+
|
65
|
+
- (void)accessWithBlock:(dispatch_block_t)block;
|
66
|
+
- (void)modifyWithBlock:(dispatch_block_t)block;
|
67
|
+
|
68
|
+
//
|
69
|
+
// Transaction state
|
70
|
+
|
71
|
+
- (void)commit;
|
72
|
+
- (void)rollback;
|
73
|
+
|
74
|
+
@end
|
@@ -0,0 +1,603 @@
|
|
1
|
+
#import "YapMemoryTable.h"
|
2
|
+
|
3
|
+
|
4
|
+
/**
|
5
|
+
* There may be multiple simulatneous database transactions, each using different atomic snapshots.
|
6
|
+
* In other words, the value in the database at snapshot A may be different than at snapshot B.
|
7
|
+
* Each value is correct, and depends entirely on the snapshot being used by the transaction.
|
8
|
+
*
|
9
|
+
* This presents a unique property of the table:
|
10
|
+
* - the table may store multiple values for a single key.
|
11
|
+
* - the stored values are associated with a snapshot
|
12
|
+
*
|
13
|
+
* This class represents a single stored value and its associated snapshot.
|
14
|
+
* It is one value contained within a linked-list of possibly multiple values for the same key.
|
15
|
+
* The linked-list remains sorted, with the most recent value at the front of the linked-list.
|
16
|
+
**/
|
17
|
+
@interface YapMemoryTableValue : NSObject {
|
18
|
+
@public
|
19
|
+
YapMemoryTableValue *olderValue;
|
20
|
+
|
21
|
+
uint64_t snapshot;
|
22
|
+
id object;
|
23
|
+
}
|
24
|
+
|
25
|
+
@end
|
26
|
+
|
27
|
+
@implementation YapMemoryTableValue
|
28
|
+
|
29
|
+
- (NSString *)description
|
30
|
+
{
|
31
|
+
return [NSString stringWithFormat:@"<YapMemoryTableValue[%p]: snapshot(%llu), olderValue(%p), object(%@)>",
|
32
|
+
self, snapshot, olderValue, object];
|
33
|
+
}
|
34
|
+
|
35
|
+
@end
|
36
|
+
|
37
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
38
|
+
#pragma mark -
|
39
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
+
|
41
|
+
@interface YapMemoryTable () {
|
42
|
+
@public
|
43
|
+
|
44
|
+
Class keyClass;
|
45
|
+
|
46
|
+
NSMutableDictionary *dict;
|
47
|
+
|
48
|
+
dispatch_queue_t queue;
|
49
|
+
void *IsOnQueueKey;
|
50
|
+
|
51
|
+
NSMutableArray *snapshots;
|
52
|
+
NSMutableArray *changes;
|
53
|
+
NSLock *lock;
|
54
|
+
}
|
55
|
+
@end
|
56
|
+
|
57
|
+
@interface YapMemoryTableTransaction () {
|
58
|
+
@public
|
59
|
+
|
60
|
+
__unsafe_unretained YapMemoryTable *table;
|
61
|
+
|
62
|
+
uint64_t snapshot;
|
63
|
+
BOOL isReadWriteTransaction;
|
64
|
+
|
65
|
+
NSMutableSet *changedKeys;
|
66
|
+
}
|
67
|
+
@end
|
68
|
+
|
69
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
70
|
+
#pragma mark -
|
71
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
72
|
+
|
73
|
+
@implementation YapMemoryTable
|
74
|
+
|
75
|
+
- (id)initWithKeyClass:(Class)inKeyClass
|
76
|
+
{
|
77
|
+
if ((self = [super init]))
|
78
|
+
{
|
79
|
+
keyClass = inKeyClass;
|
80
|
+
|
81
|
+
dict = [[NSMutableDictionary alloc] init];
|
82
|
+
queue = dispatch_queue_create("YapMemoryTable", DISPATCH_QUEUE_CONCURRENT);
|
83
|
+
|
84
|
+
IsOnQueueKey = &IsOnQueueKey;
|
85
|
+
dispatch_queue_set_specific(queue, IsOnQueueKey, IsOnQueueKey, NULL);
|
86
|
+
|
87
|
+
snapshots = [[NSMutableArray alloc] init];
|
88
|
+
changes = [[NSMutableArray alloc] init];
|
89
|
+
lock = [[NSLock alloc] init];
|
90
|
+
}
|
91
|
+
return self;
|
92
|
+
}
|
93
|
+
- (YapMemoryTableTransaction *)newReadTransactionWithSnapshot:(uint64_t)snapshot
|
94
|
+
{
|
95
|
+
YapMemoryTableTransaction *transaction = [[YapMemoryTableTransaction alloc] init];
|
96
|
+
transaction->table = self;
|
97
|
+
transaction->snapshot = snapshot;
|
98
|
+
transaction->isReadWriteTransaction = NO;
|
99
|
+
|
100
|
+
return transaction;
|
101
|
+
}
|
102
|
+
|
103
|
+
- (YapMemoryTableTransaction *)newReadWriteTransactionWithSnapshot:(uint64_t)snapshot
|
104
|
+
{
|
105
|
+
YapMemoryTableTransaction *transaction = [[YapMemoryTableTransaction alloc] init];
|
106
|
+
transaction->table = self;
|
107
|
+
transaction->snapshot = snapshot;
|
108
|
+
transaction->isReadWriteTransaction = YES;
|
109
|
+
|
110
|
+
return transaction;
|
111
|
+
}
|
112
|
+
|
113
|
+
- (void)asyncCheckpoint:(int64_t)minSnapshot
|
114
|
+
{
|
115
|
+
dispatch_barrier_async(queue, ^{ @autoreleasepool {
|
116
|
+
|
117
|
+
while (YES) // using manual return
|
118
|
+
{
|
119
|
+
int64_t snapshot = 0;
|
120
|
+
NSSet *changedKeys = nil;
|
121
|
+
|
122
|
+
[lock lock];
|
123
|
+
|
124
|
+
if ([snapshots count] > 0)
|
125
|
+
{
|
126
|
+
snapshot = [[snapshots objectAtIndex:0] unsignedLongLongValue];
|
127
|
+
|
128
|
+
if (snapshot < minSnapshot)
|
129
|
+
{
|
130
|
+
changedKeys = [changes objectAtIndex:0];
|
131
|
+
|
132
|
+
[snapshots removeObjectAtIndex:0];
|
133
|
+
[changes removeObjectAtIndex:0];
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
[lock unlock];
|
138
|
+
|
139
|
+
if (changedKeys == nil)
|
140
|
+
{
|
141
|
+
return; // Done
|
142
|
+
}
|
143
|
+
|
144
|
+
for (id key in changedKeys)
|
145
|
+
{
|
146
|
+
BOOL hasObject = NO;
|
147
|
+
|
148
|
+
__unsafe_unretained YapMemoryTableValue *prvValue = nil;
|
149
|
+
__unsafe_unretained YapMemoryTableValue *value = [dict objectForKey:key];
|
150
|
+
|
151
|
+
while (value && value->snapshot >= minSnapshot)
|
152
|
+
{
|
153
|
+
if (hasObject == NO)
|
154
|
+
hasObject = (value->object != nil);
|
155
|
+
|
156
|
+
prvValue = value;
|
157
|
+
value = value->olderValue;
|
158
|
+
}
|
159
|
+
|
160
|
+
if (value)
|
161
|
+
{
|
162
|
+
if (prvValue)
|
163
|
+
{
|
164
|
+
// The 'value' is not the latest value
|
165
|
+
|
166
|
+
if (!hasObject)
|
167
|
+
{
|
168
|
+
// All values >= minSnapshot represent a deletion.
|
169
|
+
// So we can just dump all values.
|
170
|
+
|
171
|
+
[dict removeObjectForKey:key];
|
172
|
+
}
|
173
|
+
else
|
174
|
+
{
|
175
|
+
// There are values >= minSnapshot in the table.
|
176
|
+
// So the stay in the dict.
|
177
|
+
// But everything older than minSnapshot can go.
|
178
|
+
|
179
|
+
prvValue->olderValue = nil;
|
180
|
+
}
|
181
|
+
}
|
182
|
+
else
|
183
|
+
{
|
184
|
+
// The 'value' is the latest value
|
185
|
+
|
186
|
+
if (value->object == nil)
|
187
|
+
{
|
188
|
+
// The 'value' is the latest value.
|
189
|
+
// And 'value' represents a deletion.
|
190
|
+
// So we can just dump all values.
|
191
|
+
|
192
|
+
[dict removeObjectForKey:key];
|
193
|
+
}
|
194
|
+
else
|
195
|
+
{
|
196
|
+
// The 'value' is the latest value.
|
197
|
+
// So it stays in the dict.
|
198
|
+
// But everything after it can go (if there is anything).
|
199
|
+
|
200
|
+
value->olderValue = nil;
|
201
|
+
}
|
202
|
+
}
|
203
|
+
|
204
|
+
} // end: if (value)
|
205
|
+
|
206
|
+
} // end: for (id key in changedKeys)
|
207
|
+
|
208
|
+
} // end: while (YES)
|
209
|
+
}});
|
210
|
+
}
|
211
|
+
|
212
|
+
- (void)asyncRollback:(int64_t)snapshot withChanges:(NSSet *)changedKeys
|
213
|
+
{
|
214
|
+
dispatch_barrier_async(queue, ^{ @autoreleasepool {
|
215
|
+
|
216
|
+
for (id key in changedKeys)
|
217
|
+
{
|
218
|
+
__unsafe_unretained YapMemoryTableValue *value = [dict objectForKey:key];
|
219
|
+
|
220
|
+
if (value && value->snapshot == snapshot)
|
221
|
+
{
|
222
|
+
if (value->olderValue == nil)
|
223
|
+
{
|
224
|
+
[dict removeObjectForKey:key];
|
225
|
+
}
|
226
|
+
else
|
227
|
+
{
|
228
|
+
[dict setObject:value->olderValue forKey:key];
|
229
|
+
}
|
230
|
+
}
|
231
|
+
}
|
232
|
+
}});
|
233
|
+
}
|
234
|
+
|
235
|
+
@end
|
236
|
+
|
237
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
238
|
+
#pragma mark -
|
239
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
240
|
+
|
241
|
+
@implementation YapMemoryTableTransaction
|
242
|
+
|
243
|
+
@synthesize snapshot = snapshot;
|
244
|
+
@synthesize isReadWriteTransaction = isReadWriteTransaction;
|
245
|
+
|
246
|
+
- (id)objectForKey:(id)key
|
247
|
+
{
|
248
|
+
NSAssert([key isKindOfClass:table->keyClass],
|
249
|
+
@"Unexpected key class. Expected %@, passed %@", table->keyClass, [key class]);
|
250
|
+
|
251
|
+
__block id result = nil;
|
252
|
+
|
253
|
+
dispatch_block_t block = ^{
|
254
|
+
|
255
|
+
__unsafe_unretained YapMemoryTableValue *value = [table->dict objectForKey:key];
|
256
|
+
|
257
|
+
while (value)
|
258
|
+
{
|
259
|
+
if (value->snapshot <= snapshot)
|
260
|
+
{
|
261
|
+
result = value->object;
|
262
|
+
break;
|
263
|
+
}
|
264
|
+
else
|
265
|
+
{
|
266
|
+
value = value->olderValue;
|
267
|
+
}
|
268
|
+
}
|
269
|
+
};
|
270
|
+
|
271
|
+
if (dispatch_get_specific(table->IsOnQueueKey))
|
272
|
+
block();
|
273
|
+
else
|
274
|
+
dispatch_sync(table->queue, block);
|
275
|
+
|
276
|
+
return result;
|
277
|
+
}
|
278
|
+
|
279
|
+
- (void)enumerateKeysWithBlock:(void (^)(id key, BOOL *stop))userBlock
|
280
|
+
{
|
281
|
+
dispatch_block_t block = ^{ @autoreleasepool {
|
282
|
+
|
283
|
+
[table->dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
284
|
+
|
285
|
+
__unsafe_unretained YapMemoryTableValue *value = [table->dict objectForKey:key];
|
286
|
+
while (value)
|
287
|
+
{
|
288
|
+
if (value->snapshot <= snapshot)
|
289
|
+
{
|
290
|
+
if (value->object)
|
291
|
+
{
|
292
|
+
userBlock(key, stop);
|
293
|
+
}
|
294
|
+
break;
|
295
|
+
}
|
296
|
+
else
|
297
|
+
{
|
298
|
+
value = value->olderValue;
|
299
|
+
}
|
300
|
+
}
|
301
|
+
}];
|
302
|
+
}};
|
303
|
+
|
304
|
+
if (dispatch_get_specific(table->IsOnQueueKey))
|
305
|
+
block();
|
306
|
+
else
|
307
|
+
dispatch_sync(table->queue, block);
|
308
|
+
}
|
309
|
+
|
310
|
+
- (void)enumerateKeysAndObjectsWithBlock:(void (^)(id key, id obj, BOOL *stop))userBlock
|
311
|
+
{
|
312
|
+
dispatch_block_t block = ^{ @autoreleasepool {
|
313
|
+
|
314
|
+
[table->dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
315
|
+
|
316
|
+
__unsafe_unretained YapMemoryTableValue *value = [table->dict objectForKey:key];
|
317
|
+
while (value)
|
318
|
+
{
|
319
|
+
if (value->snapshot <= snapshot)
|
320
|
+
{
|
321
|
+
if (value->object)
|
322
|
+
{
|
323
|
+
userBlock(key, value->object, stop);
|
324
|
+
}
|
325
|
+
break;
|
326
|
+
}
|
327
|
+
else
|
328
|
+
{
|
329
|
+
value = value->olderValue;
|
330
|
+
}
|
331
|
+
}
|
332
|
+
}];
|
333
|
+
}};
|
334
|
+
|
335
|
+
if (dispatch_get_specific(table->IsOnQueueKey))
|
336
|
+
block();
|
337
|
+
else
|
338
|
+
dispatch_sync(table->queue, block);
|
339
|
+
}
|
340
|
+
|
341
|
+
- (void)setObject:(id)object forKey:(id)key
|
342
|
+
{
|
343
|
+
NSAssert([key isKindOfClass:table->keyClass],
|
344
|
+
@"Unexpected key class. Expected %@, passed %@", table->keyClass, [key class]);
|
345
|
+
|
346
|
+
if (!isReadWriteTransaction) {
|
347
|
+
NSAssert(NO, @"Cannot modify table in read-only transaction.");
|
348
|
+
return;
|
349
|
+
}
|
350
|
+
|
351
|
+
if (changedKeys == nil)
|
352
|
+
changedKeys = [[NSMutableSet alloc] init];
|
353
|
+
|
354
|
+
dispatch_block_t block = ^{
|
355
|
+
|
356
|
+
__unsafe_unretained YapMemoryTableValue *value = [table->dict objectForKey:key];
|
357
|
+
|
358
|
+
if (value && value->snapshot == snapshot)
|
359
|
+
{
|
360
|
+
// We've already updated this key during this transaction.
|
361
|
+
|
362
|
+
value->object = object;
|
363
|
+
}
|
364
|
+
else
|
365
|
+
{
|
366
|
+
// First update for this key during this transaction.
|
367
|
+
|
368
|
+
YapMemoryTableValue *newValue = [[YapMemoryTableValue alloc] init];
|
369
|
+
newValue->olderValue = value;
|
370
|
+
newValue->object = object;
|
371
|
+
newValue->snapshot = snapshot;
|
372
|
+
|
373
|
+
[table->dict setObject:newValue forKey:key];
|
374
|
+
|
375
|
+
[changedKeys addObject:key];
|
376
|
+
}
|
377
|
+
};
|
378
|
+
|
379
|
+
if (dispatch_get_specific(table->IsOnQueueKey))
|
380
|
+
block();
|
381
|
+
else
|
382
|
+
dispatch_barrier_sync(table->queue, block);
|
383
|
+
}
|
384
|
+
|
385
|
+
- (void)removeObjectForKey:(id)key
|
386
|
+
{
|
387
|
+
NSAssert([key isKindOfClass:table->keyClass],
|
388
|
+
@"Unexpected key class. Expected %@, passed %@", table->keyClass, [key class]);
|
389
|
+
|
390
|
+
if (!isReadWriteTransaction) {
|
391
|
+
NSAssert(NO, @"Cannot modify table in read-only transaction.");
|
392
|
+
return;
|
393
|
+
}
|
394
|
+
|
395
|
+
if (changedKeys == nil)
|
396
|
+
changedKeys = [[NSMutableSet alloc] init];
|
397
|
+
|
398
|
+
dispatch_block_t block = ^{
|
399
|
+
|
400
|
+
__unsafe_unretained YapMemoryTableValue *value = [table->dict objectForKey:key];
|
401
|
+
|
402
|
+
if (value)
|
403
|
+
{
|
404
|
+
if (value->snapshot == snapshot)
|
405
|
+
{
|
406
|
+
// We've already updated this key during this transaction.
|
407
|
+
|
408
|
+
if (value->olderValue == nil)
|
409
|
+
{
|
410
|
+
// Removing a previously set value within this transaction.
|
411
|
+
// And there are no other values outside this transaction.
|
412
|
+
|
413
|
+
[table->dict removeObjectForKey:key];
|
414
|
+
|
415
|
+
[changedKeys removeObject:key];
|
416
|
+
}
|
417
|
+
else
|
418
|
+
{
|
419
|
+
// Updating a previously set value within this transaction.
|
420
|
+
// But there are other values for older snapshots.
|
421
|
+
|
422
|
+
value->object = nil;
|
423
|
+
}
|
424
|
+
}
|
425
|
+
else
|
426
|
+
{
|
427
|
+
// First update for this key during this transaction.
|
428
|
+
|
429
|
+
YapMemoryTableValue *newValue = [[YapMemoryTableValue alloc] init];
|
430
|
+
newValue->olderValue = value;
|
431
|
+
newValue->object = nil;
|
432
|
+
newValue->snapshot = snapshot;
|
433
|
+
|
434
|
+
[table->dict setObject:newValue forKey:key];
|
435
|
+
|
436
|
+
[changedKeys addObject:key];
|
437
|
+
}
|
438
|
+
}
|
439
|
+
};
|
440
|
+
|
441
|
+
if (dispatch_get_specific(table->IsOnQueueKey))
|
442
|
+
block();
|
443
|
+
else
|
444
|
+
dispatch_barrier_sync(table->queue, block);
|
445
|
+
}
|
446
|
+
|
447
|
+
- (void)removeObjectsForKeys:(NSArray *)keys
|
448
|
+
{
|
449
|
+
if (!isReadWriteTransaction) {
|
450
|
+
NSAssert(NO, @"Cannot modify table in read-only transaction.");
|
451
|
+
return;
|
452
|
+
}
|
453
|
+
|
454
|
+
if (changedKeys == nil)
|
455
|
+
changedKeys = [[NSMutableSet alloc] init];
|
456
|
+
|
457
|
+
dispatch_block_t block = ^{ @autoreleasepool {
|
458
|
+
|
459
|
+
for (id key in keys)
|
460
|
+
{
|
461
|
+
NSAssert([key isKindOfClass:table->keyClass],
|
462
|
+
@"Unexpected key class. Expected %@, passed %@", table->keyClass, [key class]);
|
463
|
+
|
464
|
+
__unsafe_unretained YapMemoryTableValue *value = [table->dict objectForKey:key];
|
465
|
+
|
466
|
+
if (value)
|
467
|
+
{
|
468
|
+
if (value->snapshot == snapshot)
|
469
|
+
{
|
470
|
+
// We've already updated this key during this transaction.
|
471
|
+
|
472
|
+
if (value->olderValue == nil)
|
473
|
+
{
|
474
|
+
// Removing a previously set value within this transaction.
|
475
|
+
// And there are no other values outside this transaction.
|
476
|
+
|
477
|
+
[table->dict removeObjectForKey:key];
|
478
|
+
|
479
|
+
[changedKeys removeObject:key];
|
480
|
+
}
|
481
|
+
else
|
482
|
+
{
|
483
|
+
// Updating a previously set value within this transaction.
|
484
|
+
// But there are other values for older snapshots.
|
485
|
+
|
486
|
+
value->object = nil;
|
487
|
+
}
|
488
|
+
}
|
489
|
+
else
|
490
|
+
{
|
491
|
+
// First update for this key during this transaction.
|
492
|
+
|
493
|
+
YapMemoryTableValue *newValue = [[YapMemoryTableValue alloc] init];
|
494
|
+
newValue->olderValue = value;
|
495
|
+
newValue->object = nil;
|
496
|
+
newValue->snapshot = snapshot;
|
497
|
+
|
498
|
+
[table->dict setObject:newValue forKey:key];
|
499
|
+
|
500
|
+
[changedKeys addObject:key];
|
501
|
+
}
|
502
|
+
}
|
503
|
+
}
|
504
|
+
}};
|
505
|
+
|
506
|
+
if (dispatch_get_specific(table->IsOnQueueKey))
|
507
|
+
block();
|
508
|
+
else
|
509
|
+
dispatch_barrier_sync(table->queue, block);
|
510
|
+
}
|
511
|
+
|
512
|
+
- (void)removeAllObjects
|
513
|
+
{
|
514
|
+
NSAssert(isReadWriteTransaction, @"Cannot modify table in read-only transaction.");
|
515
|
+
|
516
|
+
if (changedKeys == nil)
|
517
|
+
changedKeys = [[NSMutableSet alloc] init];
|
518
|
+
|
519
|
+
dispatch_block_t block = ^{ @autoreleasepool {
|
520
|
+
|
521
|
+
// Grab all keys
|
522
|
+
NSArray *keys = [table->dict allKeys];
|
523
|
+
|
524
|
+
// Mark all keys as changed
|
525
|
+
[changedKeys addObjectsFromArray:keys];
|
526
|
+
|
527
|
+
// Now enumerate all the keys, and update accordingly
|
528
|
+
for (id key in keys)
|
529
|
+
{
|
530
|
+
__unsafe_unretained YapMemoryTableValue *value = [table->dict objectForKey:key];
|
531
|
+
|
532
|
+
if (value->snapshot == snapshot)
|
533
|
+
{
|
534
|
+
// We've already updated this key during this transaction.
|
535
|
+
|
536
|
+
if (value->olderValue == nil)
|
537
|
+
{
|
538
|
+
// Removing a previously set value within this transaction.
|
539
|
+
// And there are no other values outside this transaction.
|
540
|
+
|
541
|
+
[table->dict removeObjectForKey:key];
|
542
|
+
[changedKeys removeObject:key];
|
543
|
+
}
|
544
|
+
else
|
545
|
+
{
|
546
|
+
// Updating a previously set value within this transaction.
|
547
|
+
// But there are other values for older snapshots.
|
548
|
+
|
549
|
+
value->object = nil;
|
550
|
+
}
|
551
|
+
}
|
552
|
+
else
|
553
|
+
{
|
554
|
+
// First update for this key during this transaction.
|
555
|
+
|
556
|
+
YapMemoryTableValue *newValue = [[YapMemoryTableValue alloc] init];
|
557
|
+
newValue->olderValue = value;
|
558
|
+
newValue->object = nil;
|
559
|
+
newValue->snapshot = snapshot;
|
560
|
+
|
561
|
+
[table->dict setObject:newValue forKey:key];
|
562
|
+
}
|
563
|
+
}
|
564
|
+
}};
|
565
|
+
|
566
|
+
if (dispatch_get_specific(table->IsOnQueueKey))
|
567
|
+
block();
|
568
|
+
else
|
569
|
+
dispatch_barrier_sync(table->queue, block);
|
570
|
+
}
|
571
|
+
|
572
|
+
- (void)accessWithBlock:(dispatch_block_t)block
|
573
|
+
{
|
574
|
+
dispatch_sync(table->queue, block);
|
575
|
+
}
|
576
|
+
|
577
|
+
- (void)modifyWithBlock:(dispatch_block_t)block
|
578
|
+
{
|
579
|
+
dispatch_barrier_sync(table->queue, block);
|
580
|
+
}
|
581
|
+
|
582
|
+
- (void)commit
|
583
|
+
{
|
584
|
+
if (isReadWriteTransaction && [changedKeys count] > 0)
|
585
|
+
{
|
586
|
+
[table->lock lock];
|
587
|
+
{
|
588
|
+
[table->snapshots addObject:@(snapshot)];
|
589
|
+
[table->changes addObject:changedKeys];
|
590
|
+
}
|
591
|
+
[table->lock unlock];
|
592
|
+
}
|
593
|
+
}
|
594
|
+
|
595
|
+
- (void)rollback
|
596
|
+
{
|
597
|
+
if (isReadWriteTransaction && [changedKeys count] > 0)
|
598
|
+
{
|
599
|
+
[table asyncRollback:snapshot withChanges:changedKeys];
|
600
|
+
}
|
601
|
+
}
|
602
|
+
|
603
|
+
@end
|