traceur-rb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +22 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +87 -0
- data/Rakefile +2 -0
- data/lib/js/compile.js +31 -0
- data/lib/traceur-rb.rb +1 -0
- data/lib/traceur.rb +43 -0
- data/lib/traceur/compilation_options.rb +65 -0
- data/lib/traceur/compiler.rb +33 -0
- data/lib/traceur/configuration.rb +47 -0
- data/lib/traceur/node.rb +26 -0
- data/lib/traceur/node/command_result.rb +28 -0
- data/lib/traceur/node/runner.rb +40 -0
- data/lib/traceur/version.rb +3 -0
- data/spec/examples/classes.js +12 -0
- data/spec/integration/examples_spec.rb +28 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/traceur/compilation_options_spec.rb +31 -0
- data/spec/traceur/configuration_spec.rb +54 -0
- data/spec/traceur/node_spec.rb +15 -0
- data/traceur-rb.gemspec +25 -0
- data/vendor/node_modules/.bin/traceur +3 -0
- data/vendor/node_modules/traceur/README.md +40 -0
- data/vendor/node_modules/traceur/bin/traceur-runtime.js +2101 -0
- data/vendor/node_modules/traceur/bin/traceur.js +23034 -0
- data/vendor/node_modules/traceur/node_modules/.bin/semver +125 -0
- data/vendor/node_modules/traceur/node_modules/commander/Readme.md +208 -0
- data/vendor/node_modules/traceur/node_modules/commander/index.js +852 -0
- data/vendor/node_modules/traceur/node_modules/commander/package.json +40 -0
- data/vendor/node_modules/traceur/node_modules/q-io/.npmignore +1 -0
- data/vendor/node_modules/traceur/node_modules/q-io/.travis.yml +3 -0
- data/vendor/node_modules/traceur/node_modules/q-io/CHANGES.md +122 -0
- data/vendor/node_modules/traceur/node_modules/q-io/LICENSE +19 -0
- data/vendor/node_modules/traceur/node_modules/q-io/README.md +928 -0
- data/vendor/node_modules/traceur/node_modules/q-io/buffer-stream.js +59 -0
- data/vendor/node_modules/traceur/node_modules/q-io/coverage-report.js +44 -0
- data/vendor/node_modules/traceur/node_modules/q-io/deprecate.js +51 -0
- data/vendor/node_modules/traceur/node_modules/q-io/fs-boot.js +307 -0
- data/vendor/node_modules/traceur/node_modules/q-io/fs-common.js +499 -0
- data/vendor/node_modules/traceur/node_modules/q-io/fs-mock.js +547 -0
- data/vendor/node_modules/traceur/node_modules/q-io/fs-root.js +105 -0
- data/vendor/node_modules/traceur/node_modules/q-io/fs.js +355 -0
- data/vendor/node_modules/traceur/node_modules/q-io/fs2http.js +65 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps.js +152 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/chain.js +24 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/content.js +93 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/cookie.js +154 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/decorators.js +178 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/fs.js +417 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/html.js +58 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/json.js +78 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/negotiate.js +120 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/proxy.js +27 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/redirect.js +209 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/route.js +125 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/status.js +175 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-cookie.js +75 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http.js +378 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/.npmignore +11 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/.travis.yml +4 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/CHANGES.md +78 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/LICENSE.md +21 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/README.md +1285 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/collections.js +22 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/dict.js +142 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/fast-map.js +57 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/fast-set.js +183 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/generic-collection.js +261 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/generic-map.js +186 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/generic-order.js +55 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/generic-set.js +59 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/heap.js +236 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/iterator.js +371 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/list.js +435 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/listen/array-changes.js +247 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/listen/map-changes.js +147 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/listen/property-changes.js +448 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/listen/range-changes.js +139 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/lru-map.js +79 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/lru-set.js +142 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/map.js +60 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/multi-map.js +41 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/node_modules/weak-map/package.json +12 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/node_modules/weak-map/sync +7 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/node_modules/weak-map/sync.patch +48 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/node_modules/weak-map/weak-map.js +590 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/package.json +49 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/set.js +173 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/shim-array.js +274 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/shim-function.js +59 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/shim-object.js +538 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/shim-regexp.js +14 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/shim.js +6 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/sorted-array-map.js +49 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/sorted-array-set.js +51 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/sorted-array.js +269 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/sorted-map.js +61 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/sorted-set.js +736 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/tree-log.js +40 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/weak-map.js +1 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/LICENSE +19 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/README.md +66 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/mime.js +114 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/package.json +35 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/test.js +84 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/types/mime.types +1588 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/types/node.types +77 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mimeparse/CHANGES +15 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mimeparse/LICENSE +19 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mimeparse/README +96 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mimeparse/lib/mimeparse.js +166 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mimeparse/package.json +43 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/CONTRIBUTING.md +40 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/LICENSE +19 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/README.md +813 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/benchmark/compare-with-callbacks.js +71 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/benchmark/scenarios.js +36 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/package.json +93 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/q.js +1937 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/queue.js +35 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/.gitmodules +6 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/History.md +36 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/Makefile +7 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/Readme.md +38 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/benchmark.js +32 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/examples.js +39 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/index.js +2 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/lib/querystring.js +123 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/package.json +19 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/.gitmodules +3 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/.npmignore +3 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/History.md +128 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/Makefile +53 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/Readme.md +61 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/bin/expresso +856 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/docs/api.html +1080 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/docs/index.html +377 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/docs/index.md +290 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/docs/layout/foot.html +3 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/docs/layout/head.html +42 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/lib/bar.js +4 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/lib/foo.js +16 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/package.json +12 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/assert.test.js +91 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/async.test.js +12 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/bar.test.js +13 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/foo.test.js +14 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/http.test.js +146 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/serial/async.test.js +39 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/serial/http.test.js +48 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/.gitmodules +3 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/History.md +22 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/Makefile +6 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/Readme.md +248 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/examples/runner.js +53 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/index.js +2 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/lib/eql.js +91 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/lib/should.js +548 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/package.json +8 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/test/should.test.js +358 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/test/querystring.test.js +133 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/.npmignore +3 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/.travis.yml +4 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/LICENSE.md +20 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/README.md +33 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/package.json +37 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/test/url2-spec.js +125 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/url2.js +151 -0
- data/vendor/node_modules/traceur/node_modules/q-io/package.json +51 -0
- data/vendor/node_modules/traceur/node_modules/q-io/reader.js +133 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/boot-directory-spec.js +47 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/contains-spec.js +11 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/fixtures/hello.txt +1 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/issues/1-spec.js +33 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/make-tree-spec.js +92 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/append-spec.js +41 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/copy-tree-spec.js +57 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/fixture/hello.txt +1 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/link-spec.js +70 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/make-tree-spec.js +109 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/merge-spec.js +67 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/move-spec.js +219 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/object-spec.js +20 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/range-spec.js +26 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/read-spec.js +40 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/remove-directory-spec.js +37 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/remove-tree-spec.js +39 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/root-spec.js +32 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/stat-spec.js +26 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/symbolic-link-spec.js +86 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/working-directory-spec.js +31 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/write-spec.js +73 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/range-spec.js +23 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/range-spec.txt +1 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/read-spec.js +22 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/relative-spec.js +25 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/reroot-spec.js +45 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/write-spec.js +38 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/cookie-spec.js +52 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/directory-list-spec.js +86 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/fixtures/01234.txt +1 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/fixtures/1234.txt +1 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/fixtures/5678.txt +0 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/fixtures/9012/3456.txt +0 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/hosts-spec.js +49 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/interpret-range-spec.js +47 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/partial-range-spec.js +186 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/proxy-spec.js +82 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/symbolic-link-spec.js +110 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http/agent-spec.js +96 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http/basic-spec.js +96 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/lib/jasmine-promise.js +42 -0
- data/vendor/node_modules/traceur/node_modules/q-io/writer.js +111 -0
- data/vendor/node_modules/traceur/node_modules/semver/.npmignore +1 -0
- data/vendor/node_modules/traceur/node_modules/semver/LICENSE +27 -0
- data/vendor/node_modules/traceur/node_modules/semver/Makefile +24 -0
- data/vendor/node_modules/traceur/node_modules/semver/README.md +158 -0
- data/vendor/node_modules/traceur/node_modules/semver/bin/semver +125 -0
- data/vendor/node_modules/traceur/node_modules/semver/foot.js +6 -0
- data/vendor/node_modules/traceur/node_modules/semver/head.js +2 -0
- data/vendor/node_modules/traceur/node_modules/semver/package.json +31 -0
- data/vendor/node_modules/traceur/node_modules/semver/semver.browser.js +1039 -0
- data/vendor/node_modules/traceur/node_modules/semver/semver.browser.js.gz +0 -0
- data/vendor/node_modules/traceur/node_modules/semver/semver.js +1043 -0
- data/vendor/node_modules/traceur/node_modules/semver/semver.min.js +1 -0
- data/vendor/node_modules/traceur/node_modules/semver/semver.min.js.gz +0 -0
- data/vendor/node_modules/traceur/node_modules/semver/test/amd.js +15 -0
- data/vendor/node_modules/traceur/node_modules/semver/test/gtr.js +173 -0
- data/vendor/node_modules/traceur/node_modules/semver/test/index.js +584 -0
- data/vendor/node_modules/traceur/node_modules/semver/test/ltr.js +174 -0
- data/vendor/node_modules/traceur/node_modules/semver/test/no-module.js +19 -0
- data/vendor/node_modules/traceur/package.json +64 -0
- data/vendor/node_modules/traceur/src/node/System.js +31 -0
- data/vendor/node_modules/traceur/src/node/api.js +124 -0
- data/vendor/node_modules/traceur/src/node/command.js +141 -0
- data/vendor/node_modules/traceur/src/node/compile-single-file.js +69 -0
- data/vendor/node_modules/traceur/src/node/compiler.js +116 -0
- data/vendor/node_modules/traceur/src/node/deferred.js +110 -0
- data/vendor/node_modules/traceur/src/node/file-util.js +73 -0
- data/vendor/node_modules/traceur/src/node/getopt.js +147 -0
- data/vendor/node_modules/traceur/src/node/inline-module.js +149 -0
- data/vendor/node_modules/traceur/src/node/interpreter.js +33 -0
- data/vendor/node_modules/traceur/src/node/nodeLoader.js +41 -0
- data/vendor/node_modules/traceur/src/node/require.js +85 -0
- data/vendor/node_modules/traceur/src/node/to-amd-compiler.js +33 -0
- data/vendor/node_modules/traceur/src/node/to-commonjs-compiler.js +33 -0
- data/vendor/node_modules/traceur/src/node/traceur.js +32 -0
- data/vendor/node_modules/traceur/traceur +3 -0
- metadata +359 -0
@@ -0,0 +1,736 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
module.exports = SortedSet;
|
4
|
+
|
5
|
+
var Shim = require("./shim");
|
6
|
+
var GenericCollection = require("./generic-collection");
|
7
|
+
var GenericSet = require("./generic-set");
|
8
|
+
var PropertyChanges = require("./listen/property-changes");
|
9
|
+
var RangeChanges = require("./listen/range-changes");
|
10
|
+
var TreeLog = require("./tree-log");
|
11
|
+
|
12
|
+
function SortedSet(values, equals, compare, getDefault) {
|
13
|
+
if (!(this instanceof SortedSet)) {
|
14
|
+
return new SortedSet(values, equals, compare, getDefault);
|
15
|
+
}
|
16
|
+
this.contentEquals = equals || Object.equals;
|
17
|
+
this.contentCompare = compare || Object.compare;
|
18
|
+
this.getDefault = getDefault || Function.noop;
|
19
|
+
this.root = null;
|
20
|
+
this.length = 0;
|
21
|
+
this.addEach(values);
|
22
|
+
}
|
23
|
+
|
24
|
+
// hack so require("sorted-set").SortedSet will work in MontageJS
|
25
|
+
SortedSet.SortedSet = SortedSet;
|
26
|
+
|
27
|
+
Object.addEach(SortedSet.prototype, GenericCollection.prototype);
|
28
|
+
Object.addEach(SortedSet.prototype, GenericSet.prototype);
|
29
|
+
Object.addEach(SortedSet.prototype, PropertyChanges.prototype);
|
30
|
+
Object.addEach(SortedSet.prototype, RangeChanges.prototype);
|
31
|
+
|
32
|
+
SortedSet.prototype.constructClone = function (values) {
|
33
|
+
return new this.constructor(
|
34
|
+
values,
|
35
|
+
this.contentEquals,
|
36
|
+
this.contentCompare,
|
37
|
+
this.getDefault
|
38
|
+
);
|
39
|
+
};
|
40
|
+
|
41
|
+
SortedSet.prototype.has = function (value) {
|
42
|
+
if (this.root) {
|
43
|
+
this.splay(value);
|
44
|
+
return this.contentEquals(value, this.root.value);
|
45
|
+
} else {
|
46
|
+
return false;
|
47
|
+
}
|
48
|
+
};
|
49
|
+
|
50
|
+
SortedSet.prototype.get = function (value) {
|
51
|
+
if (this.root) {
|
52
|
+
this.splay(value);
|
53
|
+
if (this.contentEquals(value, this.root.value)) {
|
54
|
+
return this.root.value;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
return this.getDefault(value);
|
58
|
+
};
|
59
|
+
|
60
|
+
SortedSet.prototype.add = function (value) {
|
61
|
+
var node = new this.Node(value);
|
62
|
+
if (this.root) {
|
63
|
+
this.splay(value);
|
64
|
+
if (!this.contentEquals(value, this.root.value)) {
|
65
|
+
var comparison = this.contentCompare(value, this.root.value);
|
66
|
+
if (comparison === 0) {
|
67
|
+
throw new Error("SortedSet cannot contain incomparable but inequal values: " + value + " and " + this.root.value);
|
68
|
+
}
|
69
|
+
if (this.dispatchesRangeChanges) {
|
70
|
+
this.dispatchBeforeRangeChange([value], [], this.root.index);
|
71
|
+
}
|
72
|
+
if (comparison < 0) {
|
73
|
+
// rotate right
|
74
|
+
// R N
|
75
|
+
// / \ -> / \
|
76
|
+
// l r l R
|
77
|
+
// : : : \
|
78
|
+
// r
|
79
|
+
// :
|
80
|
+
node.right = this.root;
|
81
|
+
node.left = this.root.left;
|
82
|
+
this.root.left = null;
|
83
|
+
this.root.touch();
|
84
|
+
} else {
|
85
|
+
// rotate left
|
86
|
+
// R N
|
87
|
+
// / \ -> / \
|
88
|
+
// l r R r
|
89
|
+
// : : / :
|
90
|
+
// l
|
91
|
+
// :
|
92
|
+
node.left = this.root;
|
93
|
+
node.right = this.root.right;
|
94
|
+
this.root.right = null;
|
95
|
+
this.root.touch();
|
96
|
+
}
|
97
|
+
node.touch();
|
98
|
+
this.root = node;
|
99
|
+
this.length++;
|
100
|
+
if (this.dispatchesRangeChanges) {
|
101
|
+
this.dispatchRangeChange([value], [], this.root.index);
|
102
|
+
}
|
103
|
+
return true;
|
104
|
+
}
|
105
|
+
} else {
|
106
|
+
if (this.dispatchesRangeChanges) {
|
107
|
+
this.dispatchBeforeRangeChange([value], [], 0);
|
108
|
+
}
|
109
|
+
this.root = node;
|
110
|
+
this.length++;
|
111
|
+
if (this.dispatchesRangeChanges) {
|
112
|
+
this.dispatchRangeChange([value], [], 0);
|
113
|
+
}
|
114
|
+
return true;
|
115
|
+
}
|
116
|
+
return false;
|
117
|
+
};
|
118
|
+
|
119
|
+
SortedSet.prototype['delete'] = function (value) {
|
120
|
+
if (this.root) {
|
121
|
+
this.splay(value);
|
122
|
+
if (this.contentEquals(value, this.root.value)) {
|
123
|
+
var index = this.root.index;
|
124
|
+
if (this.dispatchesRangeChanges) {
|
125
|
+
this.dispatchBeforeRangeChange([], [value], index);
|
126
|
+
}
|
127
|
+
if (!this.root.left) {
|
128
|
+
this.root = this.root.right;
|
129
|
+
} else {
|
130
|
+
// remove the right side of the tree,
|
131
|
+
var right = this.root.right;
|
132
|
+
this.root = this.root.left;
|
133
|
+
// the tree now only contains the left side of the tree, so all
|
134
|
+
// values are less than the value deleted.
|
135
|
+
// splay so that the root has an empty right child
|
136
|
+
this.splay(value);
|
137
|
+
// put the right side of the tree back
|
138
|
+
this.root.right = right;
|
139
|
+
}
|
140
|
+
this.length--;
|
141
|
+
if (this.root) {
|
142
|
+
this.root.touch();
|
143
|
+
}
|
144
|
+
if (this.dispatchesRangeChanges) {
|
145
|
+
this.dispatchRangeChange([], [value], index);
|
146
|
+
}
|
147
|
+
return true;
|
148
|
+
}
|
149
|
+
}
|
150
|
+
return false;
|
151
|
+
};
|
152
|
+
|
153
|
+
SortedSet.prototype.indexOf = function (value) {
|
154
|
+
if (this.root) {
|
155
|
+
this.splay(value);
|
156
|
+
if (this.contentEquals(value, this.root.value)) {
|
157
|
+
return this.root.index;
|
158
|
+
}
|
159
|
+
}
|
160
|
+
return -1;
|
161
|
+
};
|
162
|
+
|
163
|
+
SortedSet.prototype.find = function (value) {
|
164
|
+
if (this.root) {
|
165
|
+
this.splay(value);
|
166
|
+
if (this.contentEquals(value, this.root.value)) {
|
167
|
+
return this.root;
|
168
|
+
}
|
169
|
+
}
|
170
|
+
};
|
171
|
+
|
172
|
+
SortedSet.prototype.findGreatest = function (at) {
|
173
|
+
if (this.root) {
|
174
|
+
at = at || this.root;
|
175
|
+
while (at.right) {
|
176
|
+
at = at.right;
|
177
|
+
}
|
178
|
+
return at;
|
179
|
+
}
|
180
|
+
};
|
181
|
+
|
182
|
+
SortedSet.prototype.findLeast = function (at) {
|
183
|
+
if (this.root) {
|
184
|
+
at = at || this.root;
|
185
|
+
while (at.left) {
|
186
|
+
at = at.left;
|
187
|
+
}
|
188
|
+
return at;
|
189
|
+
}
|
190
|
+
};
|
191
|
+
|
192
|
+
SortedSet.prototype.findGreatestLessThanOrEqual = function (value) {
|
193
|
+
if (this.root) {
|
194
|
+
this.splay(value);
|
195
|
+
// assert root.value <= value
|
196
|
+
return this.root;
|
197
|
+
}
|
198
|
+
};
|
199
|
+
|
200
|
+
SortedSet.prototype.findGreatestLessThan = function (value) {
|
201
|
+
if (this.root) {
|
202
|
+
this.splay(value);
|
203
|
+
// assert root.value <= value
|
204
|
+
return this.root.getPrevious();
|
205
|
+
}
|
206
|
+
};
|
207
|
+
|
208
|
+
SortedSet.prototype.findLeastGreaterThanOrEqual = function (value) {
|
209
|
+
if (this.root) {
|
210
|
+
this.splay(value);
|
211
|
+
// assert root.value <= value
|
212
|
+
var comparison = this.contentCompare(value, this.root.value);
|
213
|
+
if (comparison === 0) {
|
214
|
+
return this.root;
|
215
|
+
} else {
|
216
|
+
return this.root.getNext();
|
217
|
+
}
|
218
|
+
}
|
219
|
+
};
|
220
|
+
|
221
|
+
SortedSet.prototype.findLeastGreaterThan = function (value) {
|
222
|
+
if (this.root) {
|
223
|
+
this.splay(value);
|
224
|
+
// assert root.value <= value
|
225
|
+
var comparison = this.contentCompare(value, this.root.value);
|
226
|
+
return this.root.getNext();
|
227
|
+
}
|
228
|
+
};
|
229
|
+
|
230
|
+
SortedSet.prototype.pop = function () {
|
231
|
+
if (this.root) {
|
232
|
+
var found = this.findGreatest();
|
233
|
+
this["delete"](found.value);
|
234
|
+
return found.value;
|
235
|
+
}
|
236
|
+
};
|
237
|
+
|
238
|
+
SortedSet.prototype.shift = function () {
|
239
|
+
if (this.root) {
|
240
|
+
var found = this.findLeast();
|
241
|
+
this["delete"](found.value);
|
242
|
+
return found.value;
|
243
|
+
}
|
244
|
+
};
|
245
|
+
|
246
|
+
SortedSet.prototype.push = function () {
|
247
|
+
this.addEach(arguments);
|
248
|
+
};
|
249
|
+
|
250
|
+
SortedSet.prototype.unshift = function () {
|
251
|
+
this.addEach(arguments);
|
252
|
+
};
|
253
|
+
|
254
|
+
SortedSet.prototype.slice = function (start, end) {
|
255
|
+
var temp;
|
256
|
+
start = start || 0;
|
257
|
+
end = end || this.length;
|
258
|
+
if (start < 0) {
|
259
|
+
start += this.length;
|
260
|
+
}
|
261
|
+
if (end < 0) {
|
262
|
+
end += this.length;
|
263
|
+
}
|
264
|
+
var sliced = [];
|
265
|
+
if (this.root) {
|
266
|
+
this.splayIndex(start);
|
267
|
+
while (this.root.index < end) {
|
268
|
+
sliced.push(this.root.value);
|
269
|
+
if (!this.root.right) {
|
270
|
+
break;
|
271
|
+
}
|
272
|
+
this.splay(this.root.getNext().value);
|
273
|
+
}
|
274
|
+
}
|
275
|
+
return sliced;
|
276
|
+
};
|
277
|
+
|
278
|
+
SortedSet.prototype.splice = function (at, length /*...plus*/) {
|
279
|
+
return this.swap(at, length, Array.prototype.slice.call(arguments, 2));
|
280
|
+
};
|
281
|
+
|
282
|
+
SortedSet.prototype.swap = function (start, length, plus) {
|
283
|
+
if (start === undefined && length === undefined) {
|
284
|
+
return [];
|
285
|
+
}
|
286
|
+
start = start || 0;
|
287
|
+
if (start < 0) {
|
288
|
+
start += this.length;
|
289
|
+
}
|
290
|
+
if (length === undefined) {
|
291
|
+
length = Infinity;
|
292
|
+
}
|
293
|
+
var swapped = [];
|
294
|
+
|
295
|
+
if (this.root) {
|
296
|
+
|
297
|
+
// start
|
298
|
+
this.splayIndex(start);
|
299
|
+
|
300
|
+
// minus length
|
301
|
+
for (var i = 0; i < length; i++) {
|
302
|
+
swapped.push(this.root.value);
|
303
|
+
var next = this.root.getNext();
|
304
|
+
this["delete"](this.root.value);
|
305
|
+
if (!next) {
|
306
|
+
break;
|
307
|
+
}
|
308
|
+
this.splay(next.value);
|
309
|
+
}
|
310
|
+
}
|
311
|
+
|
312
|
+
// plus
|
313
|
+
this.addEach(plus);
|
314
|
+
|
315
|
+
return swapped;
|
316
|
+
};
|
317
|
+
|
318
|
+
// This is the simplified top-down splaying algorithm from: "Self-adjusting
|
319
|
+
// Binary Search Trees" by Sleator and Tarjan guarantees that the root.value <=
|
320
|
+
// value if root exists
|
321
|
+
// - as described in https://github.com/hij1nx/forest
|
322
|
+
SortedSet.prototype.splay = function (value) {
|
323
|
+
var stub, left, right, temp, root, history;
|
324
|
+
|
325
|
+
if (!this.root) {
|
326
|
+
return;
|
327
|
+
}
|
328
|
+
|
329
|
+
// Create a stub node. The use of the stub node is a bit
|
330
|
+
// counter-intuitive: The right child of the stub node will hold the L tree
|
331
|
+
// of the algorithm. The left child of the stub node will hold the R tree
|
332
|
+
// of the algorithm. Using a stub node, left and right will always be
|
333
|
+
// nodes and we avoid special cases.
|
334
|
+
// - http://code.google.com/p/v8/source/browse/branches/bleeding_edge/src/splay-tree-inl.h
|
335
|
+
stub = left = right = new this.Node();
|
336
|
+
// The history is an upside down tree used to propagate new tree sizes back
|
337
|
+
// up the left and right arms of a traversal. The right children of the
|
338
|
+
// transitive left side of the tree will be former roots while linking
|
339
|
+
// left. The left children of the transitive walk to the right side of the
|
340
|
+
// history tree will all be previous roots from linking right. The last
|
341
|
+
// node of the left and right traversal will each become a child of the new
|
342
|
+
// root.
|
343
|
+
history = new this.Node();
|
344
|
+
root = this.root;
|
345
|
+
|
346
|
+
while (true) {
|
347
|
+
var comparison = this.contentCompare(value, root.value);
|
348
|
+
if (comparison < 0) {
|
349
|
+
if (root.left) {
|
350
|
+
if (this.contentCompare(value, root.left.value) < 0) {
|
351
|
+
// rotate right
|
352
|
+
// Root L(temp)
|
353
|
+
// / \ / \
|
354
|
+
// L(temp) R LL Root
|
355
|
+
// / \ / \
|
356
|
+
// LL LR LR R
|
357
|
+
temp = root.left;
|
358
|
+
root.left = temp.right;
|
359
|
+
root.touch();
|
360
|
+
temp.right = root;
|
361
|
+
temp.touch();
|
362
|
+
root = temp;
|
363
|
+
if (!root.left) {
|
364
|
+
break;
|
365
|
+
}
|
366
|
+
}
|
367
|
+
// remember former root for repropagating length
|
368
|
+
temp = new Node();
|
369
|
+
temp.right = root;
|
370
|
+
temp.left = history.left;
|
371
|
+
history.left = temp;
|
372
|
+
// link left
|
373
|
+
right.left = root;
|
374
|
+
right.touch();
|
375
|
+
right = root;
|
376
|
+
root = root.left;
|
377
|
+
} else {
|
378
|
+
break;
|
379
|
+
}
|
380
|
+
} else if (comparison > 0) {
|
381
|
+
if (root.right) {
|
382
|
+
if (this.contentCompare(value, root.right.value) > 0) {
|
383
|
+
// rotate left
|
384
|
+
// Root L(temp)
|
385
|
+
// / \ / \
|
386
|
+
// L(temp) R LL Root
|
387
|
+
// / \ / \
|
388
|
+
// LL LR LR R
|
389
|
+
temp = root.right;
|
390
|
+
root.right = temp.left;
|
391
|
+
root.touch();
|
392
|
+
temp.left = root;
|
393
|
+
temp.touch();
|
394
|
+
root = temp;
|
395
|
+
if (!root.right) {
|
396
|
+
break;
|
397
|
+
}
|
398
|
+
}
|
399
|
+
// remember former root for repropagating length
|
400
|
+
temp = new Node();
|
401
|
+
temp.left = root;
|
402
|
+
temp.right = history.right;
|
403
|
+
history.right = temp;
|
404
|
+
// link right
|
405
|
+
left.right = root;
|
406
|
+
left.touch();
|
407
|
+
left = root;
|
408
|
+
root = root.right;
|
409
|
+
} else {
|
410
|
+
break;
|
411
|
+
}
|
412
|
+
} else { // equal or incomparable
|
413
|
+
break;
|
414
|
+
}
|
415
|
+
}
|
416
|
+
|
417
|
+
// reassemble
|
418
|
+
left.right = root.left;
|
419
|
+
left.touch();
|
420
|
+
right.left = root.right;
|
421
|
+
right.touch();
|
422
|
+
root.left = stub.right;
|
423
|
+
root.right = stub.left;
|
424
|
+
|
425
|
+
// propagate new lengths
|
426
|
+
while (history.left) {
|
427
|
+
history.left.right.touch();
|
428
|
+
history.left = history.left.left;
|
429
|
+
}
|
430
|
+
while (history.right) {
|
431
|
+
history.right.left.touch();
|
432
|
+
history.right = history.right.right;
|
433
|
+
}
|
434
|
+
root.touch();
|
435
|
+
|
436
|
+
this.root = root;
|
437
|
+
};
|
438
|
+
|
439
|
+
// an internal utility for splaying a node based on its index
|
440
|
+
SortedSet.prototype.splayIndex = function (index) {
|
441
|
+
if (this.root) {
|
442
|
+
var at = this.root;
|
443
|
+
var atIndex = this.root.index;
|
444
|
+
|
445
|
+
while (atIndex !== index) {
|
446
|
+
if (atIndex > index && at.left) {
|
447
|
+
at = at.left;
|
448
|
+
atIndex -= 1 + (at.right ? at.right.length : 0);
|
449
|
+
} else if (atIndex < index && at.right) {
|
450
|
+
at = at.right;
|
451
|
+
atIndex += 1 + (at.left ? at.left.length : 0);
|
452
|
+
} else {
|
453
|
+
break;
|
454
|
+
}
|
455
|
+
}
|
456
|
+
|
457
|
+
this.splay(at.value);
|
458
|
+
|
459
|
+
return this.root.index === index;
|
460
|
+
}
|
461
|
+
return false;
|
462
|
+
};
|
463
|
+
|
464
|
+
SortedSet.prototype.reduce = function (callback, basis, thisp) {
|
465
|
+
if (this.root) {
|
466
|
+
basis = this.root.reduce(callback, basis, 0, thisp, this);
|
467
|
+
}
|
468
|
+
return basis;
|
469
|
+
};
|
470
|
+
|
471
|
+
SortedSet.prototype.reduceRight = function (callback, basis, thisp) {
|
472
|
+
if (this.root) {
|
473
|
+
basis = this.root.reduceRight(callback, basis, this.length - 1, thisp, this);
|
474
|
+
}
|
475
|
+
return basis;
|
476
|
+
};
|
477
|
+
|
478
|
+
SortedSet.prototype.min = function (at) {
|
479
|
+
var least = this.findLeast(at);
|
480
|
+
if (least) {
|
481
|
+
return least.value;
|
482
|
+
}
|
483
|
+
};
|
484
|
+
|
485
|
+
SortedSet.prototype.max = function (at) {
|
486
|
+
var greatest = this.findGreatest(at);
|
487
|
+
if (greatest) {
|
488
|
+
return greatest.value;
|
489
|
+
}
|
490
|
+
};
|
491
|
+
|
492
|
+
SortedSet.prototype.one = function () {
|
493
|
+
return this.min();
|
494
|
+
};
|
495
|
+
|
496
|
+
SortedSet.prototype.clear = function () {
|
497
|
+
var minus;
|
498
|
+
if (this.dispatchesRangeChanges) {
|
499
|
+
minus = this.toArray();
|
500
|
+
this.dispatchBeforeRangeChange([], minus, 0);
|
501
|
+
}
|
502
|
+
this.root = null;
|
503
|
+
this.length = 0;
|
504
|
+
if (this.dispatchesRangeChanges) {
|
505
|
+
this.dispatchRangeChange([], minus, 0);
|
506
|
+
}
|
507
|
+
};
|
508
|
+
|
509
|
+
SortedSet.prototype.iterate = function (start, end) {
|
510
|
+
return new this.Iterator(this, start, end);
|
511
|
+
};
|
512
|
+
|
513
|
+
SortedSet.prototype.Iterator = Iterator;
|
514
|
+
|
515
|
+
SortedSet.prototype.summary = function () {
|
516
|
+
if (this.root) {
|
517
|
+
return this.root.summary();
|
518
|
+
} else {
|
519
|
+
return "()";
|
520
|
+
}
|
521
|
+
};
|
522
|
+
|
523
|
+
SortedSet.prototype.log = function (charmap, logNode, callback, thisp) {
|
524
|
+
charmap = charmap || TreeLog.unicodeRound;
|
525
|
+
logNode = logNode || this.logNode;
|
526
|
+
if (!callback) {
|
527
|
+
callback = console.log;
|
528
|
+
thisp = console;
|
529
|
+
}
|
530
|
+
callback = callback.bind(thisp);
|
531
|
+
if (this.root) {
|
532
|
+
this.root.log(charmap, logNode, callback, callback);
|
533
|
+
}
|
534
|
+
};
|
535
|
+
|
536
|
+
SortedSet.prototype.logNode = function (node, log, logBefore) {
|
537
|
+
log(" " + node.value);
|
538
|
+
};
|
539
|
+
|
540
|
+
SortedSet.logCharsets = TreeLog;
|
541
|
+
|
542
|
+
SortedSet.prototype.Node = Node;
|
543
|
+
|
544
|
+
function Node(value) {
|
545
|
+
this.value = value;
|
546
|
+
this.left = null;
|
547
|
+
this.right = null;
|
548
|
+
this.length = 1;
|
549
|
+
}
|
550
|
+
|
551
|
+
// TODO case where no basis is provided for reduction
|
552
|
+
|
553
|
+
Node.prototype.reduce = function (callback, basis, index, thisp, tree, depth) {
|
554
|
+
depth = depth || 0;
|
555
|
+
if (this.left) {
|
556
|
+
// prerecord length to be resistant to mutation
|
557
|
+
var length = this.left.length;
|
558
|
+
basis = this.left.reduce(callback, basis, index, thisp, tree, depth + 1);
|
559
|
+
index += length;
|
560
|
+
}
|
561
|
+
basis = callback.call(thisp, basis, this.value, index, tree, this, depth);
|
562
|
+
index += 1;
|
563
|
+
if (this.right) {
|
564
|
+
basis = this.right.reduce(callback, basis, index, thisp, tree, depth + 1);
|
565
|
+
}
|
566
|
+
return basis;
|
567
|
+
};
|
568
|
+
|
569
|
+
Node.prototype.reduceRight = function (callback, basis, index, thisp, tree, depth) {
|
570
|
+
depth = depth || 0;
|
571
|
+
if (this.right) {
|
572
|
+
basis = this.right.reduce(callback, basis, index, thisp, tree, depth + 1);
|
573
|
+
index -= this.right.length;
|
574
|
+
}
|
575
|
+
basis = callback.call(thisp, basis, this.value, this.value, tree, this, depth);
|
576
|
+
index -= 1;
|
577
|
+
if (this.left) {
|
578
|
+
basis = this.left.reduce(callback, basis, index, thisp, tree, depth + 1);
|
579
|
+
}
|
580
|
+
return basis;
|
581
|
+
};
|
582
|
+
|
583
|
+
Node.prototype.touch = function () {
|
584
|
+
this.length = 1 +
|
585
|
+
(this.left ? this.left.length : 0) +
|
586
|
+
(this.right ? this.right.length : 0);
|
587
|
+
this.index = this.left ? this.left.length : 0;
|
588
|
+
};
|
589
|
+
|
590
|
+
Node.prototype.checkIntegrity = function () {
|
591
|
+
var length = 1;
|
592
|
+
length += this.left ? this.left.checkIntegrity() : 0;
|
593
|
+
length += this.right ? this.right.checkIntegrity() : 0;
|
594
|
+
if (this.length !== length)
|
595
|
+
throw new Error("Integrity check failed: " + this.summary());
|
596
|
+
return length;
|
597
|
+
}
|
598
|
+
|
599
|
+
// get the next node in this subtree
|
600
|
+
Node.prototype.getNext = function () {
|
601
|
+
var node = this;
|
602
|
+
if (node.right) {
|
603
|
+
node = node.right;
|
604
|
+
while (node.left) {
|
605
|
+
node = node.left;
|
606
|
+
}
|
607
|
+
return node;
|
608
|
+
}
|
609
|
+
};
|
610
|
+
|
611
|
+
// get the previous node in this subtree
|
612
|
+
Node.prototype.getPrevious = function () {
|
613
|
+
var node = this;
|
614
|
+
if (node.left) {
|
615
|
+
node = node.left;
|
616
|
+
while (node.right) {
|
617
|
+
node = node.right;
|
618
|
+
}
|
619
|
+
return node;
|
620
|
+
}
|
621
|
+
};
|
622
|
+
|
623
|
+
Node.prototype.summary = function () {
|
624
|
+
var value = this.value || "-";
|
625
|
+
value += " <" + this.length;
|
626
|
+
if (!this.left && !this.right) {
|
627
|
+
return "(" + value + ")";
|
628
|
+
}
|
629
|
+
return "(" + value + " " + (
|
630
|
+
this.left ? this.left.summary() : "()"
|
631
|
+
) + ", " + (
|
632
|
+
this.right ? this.right.summary() : "()"
|
633
|
+
) + ")";
|
634
|
+
};
|
635
|
+
|
636
|
+
Node.prototype.log = function (charmap, logNode, log, logAbove) {
|
637
|
+
var self = this;
|
638
|
+
|
639
|
+
var branch;
|
640
|
+
if (this.left && this.right) {
|
641
|
+
branch = charmap.intersection;
|
642
|
+
} else if (this.left) {
|
643
|
+
branch = charmap.branchUp;
|
644
|
+
} else if (this.right) {
|
645
|
+
branch = charmap.branchDown;
|
646
|
+
} else {
|
647
|
+
branch = charmap.through;
|
648
|
+
}
|
649
|
+
|
650
|
+
var loggedAbove;
|
651
|
+
this.left && this.left.log(
|
652
|
+
charmap,
|
653
|
+
logNode,
|
654
|
+
function innerWrite(line) {
|
655
|
+
if (!loggedAbove) {
|
656
|
+
loggedAbove = true;
|
657
|
+
// leader
|
658
|
+
logAbove(charmap.fromBelow + charmap.through + line);
|
659
|
+
} else {
|
660
|
+
// below
|
661
|
+
logAbove(charmap.strafe + " " + line);
|
662
|
+
}
|
663
|
+
},
|
664
|
+
function innerWriteAbove(line) {
|
665
|
+
// above
|
666
|
+
logAbove(" " + line);
|
667
|
+
}
|
668
|
+
);
|
669
|
+
|
670
|
+
var loggedOn;
|
671
|
+
logNode(
|
672
|
+
this,
|
673
|
+
function innerWrite(line) {
|
674
|
+
if (!loggedOn) {
|
675
|
+
loggedOn = true;
|
676
|
+
log(branch + line);
|
677
|
+
} else {
|
678
|
+
log((self.right ? charmap.strafe : " ") + line);
|
679
|
+
}
|
680
|
+
},
|
681
|
+
function innerWriteAbove(line) {
|
682
|
+
logAbove((self.left ? charmap.strafe : " ") + line);
|
683
|
+
}
|
684
|
+
);
|
685
|
+
|
686
|
+
var loggedBelow;
|
687
|
+
this.right && this.right.log(
|
688
|
+
charmap,
|
689
|
+
logNode,
|
690
|
+
function innerWrite(line) {
|
691
|
+
if (!loggedBelow) {
|
692
|
+
loggedBelow = true;
|
693
|
+
log(charmap.fromAbove + charmap.through + line);
|
694
|
+
} else {
|
695
|
+
log(" " + line);
|
696
|
+
}
|
697
|
+
},
|
698
|
+
function innerWriteAbove(line) {
|
699
|
+
log(charmap.strafe + " " + line);
|
700
|
+
}
|
701
|
+
);
|
702
|
+
};
|
703
|
+
|
704
|
+
function Iterator(set, start, end) {
|
705
|
+
this.set = set;
|
706
|
+
this.prev = null;
|
707
|
+
this.end = end;
|
708
|
+
if (start) {
|
709
|
+
var next = this.set.findLeastGreaterThanOrEqual(start);
|
710
|
+
if (next) {
|
711
|
+
this.set.splay(next.value);
|
712
|
+
this.prev = next.getPrevious();
|
713
|
+
}
|
714
|
+
}
|
715
|
+
}
|
716
|
+
|
717
|
+
Iterator.prototype.next = function () {
|
718
|
+
var next;
|
719
|
+
if (this.prev) {
|
720
|
+
next = this.set.findLeastGreaterThan(this.prev.value);
|
721
|
+
} else {
|
722
|
+
next = this.set.findLeast();
|
723
|
+
}
|
724
|
+
if (!next) {
|
725
|
+
throw StopIteration;
|
726
|
+
}
|
727
|
+
if (
|
728
|
+
this.end !== undefined &&
|
729
|
+
this.set.contentCompare(next.value, this.end) >= 0
|
730
|
+
) {
|
731
|
+
throw StopIteration;
|
732
|
+
}
|
733
|
+
this.prev = next;
|
734
|
+
return next.value;
|
735
|
+
};
|
736
|
+
|