diff --git a/.github/workflows/doc-build.yml b/.github/workflows/doc-build.yml
deleted file mode 100644
index e701731..0000000
--- a/.github/workflows/doc-build.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-name: Build API Docs
-
-permissions:
- contents: write
-
-on:
- workflow_dispatch:
-
-jobs:
- call-doc-build-workflow:
- uses: clojure/build.ci/.github/workflows/doc-build.yml@master
- with:
- project: clojure/data.avl
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
deleted file mode 100644
index 286cf95..0000000
--- a/.github/workflows/release.yml
+++ /dev/null
@@ -1,22 +0,0 @@
-name: Release on demand
-
-permissions:
- contents: write
-
-on:
- workflow_dispatch:
- inputs:
- releaseVersion:
- description: "Version to release"
- required: true
- snapshotVersion:
- description: "Snapshot version after release"
- required: true
-
-jobs:
- call-release:
- uses: clojure/build.ci/.github/workflows/release.yml@master
- with:
- releaseVersion: ${{ github.event.inputs.releaseVersion }}
- snapshotVersion: ${{ github.event.inputs.snapshotVersion }}
- secrets: inherit
\ No newline at end of file
diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml
deleted file mode 100644
index 9fdad8c..0000000
--- a/.github/workflows/snapshot.yml
+++ /dev/null
@@ -1,11 +0,0 @@
-name: Snapshot on demand
-
-permissions:
- contents: read
-
-on: [workflow_dispatch]
-
-jobs:
- call-snapshot:
- uses: clojure/build.ci/.github/workflows/snapshot.yml@master
- secrets: inherit
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
deleted file mode 100644
index 2cc441a..0000000
--- a/.github/workflows/test.yml
+++ /dev/null
@@ -1,10 +0,0 @@
-name: Test
-
-permissions:
- contents: read
-
-on: [push]
-
-jobs:
- call-test:
- uses: clojure/build.ci/.github/workflows/test.yml@master
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index ae806e0..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,14 +0,0 @@
-/target
-/lib
-/classes
-/checkouts
-*.jar
-*.class
-.lein-deps-sum
-.lein-failures
-.lein-plugins
-.lein-repl-history
-.repl
-.\#*
-/out
-/.nrepl-port
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
deleted file mode 100644
index fa9511f..0000000
--- a/CONTRIBUTING.md
+++ /dev/null
@@ -1,12 +0,0 @@
-This is a [Clojure contrib] project.
-
-Under the Clojure contrib [guidelines], this project cannot accept
-pull requests. All patches must be submitted via [JIRA].
-
-See [Contributing] on the Clojure website for
-more information on how to contribute.
-
-[Clojure contrib]: https://clojure.org/community/contrib_libs
-[Contributing]: https://clojure.org/community/contributing
-[JIRA]: https://clojure.atlassian.net/browse/DAVL
-[guidelines]: https://clojure.org/community/contrib_howto
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index e246f6a..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,205 +0,0 @@
-Eclipse Public License - v 1.0
-
-THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
-LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
-CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
-
-1. DEFINITIONS
-
-"Contribution" means:
-
-a) in the case of the initial Contributor, the initial code and documentation
- distributed under this Agreement, and
-b) in the case of each subsequent Contributor:
- i) changes to the Program, and
- ii) additions to the Program;
-
- where such changes and/or additions to the Program originate from and are
- distributed by that particular Contributor. A Contribution 'originates'
- from a Contributor if it was added to the Program by such Contributor
- itself or anyone acting on such Contributor's behalf. Contributions do not
- include additions to the Program which: (i) are separate modules of
- software distributed in conjunction with the Program under their own
- license agreement, and (ii) are not derivative works of the Program.
-
-"Contributor" means any person or entity that distributes the Program.
-
-"Licensed Patents" mean patent claims licensable by a Contributor which are
-necessarily infringed by the use or sale of its Contribution alone or when
-combined with the Program.
-
-"Program" means the Contributions distributed in accordance with this
-Agreement.
-
-"Recipient" means anyone who receives the Program under this Agreement,
-including all Contributors.
-
-2. GRANT OF RIGHTS
- a) Subject to the terms of this Agreement, each Contributor hereby grants
- Recipient a non-exclusive, worldwide, royalty-free copyright license to
- reproduce, prepare derivative works of, publicly display, publicly
- perform, distribute and sublicense the Contribution of such Contributor,
- if any, and such derivative works, in source code and object code form.
- b) Subject to the terms of this Agreement, each Contributor hereby grants
- Recipient a non-exclusive, worldwide, royalty-free patent license under
- Licensed Patents to make, use, sell, offer to sell, import and otherwise
- transfer the Contribution of such Contributor, if any, in source code and
- object code form. This patent license shall apply to the combination of
- the Contribution and the Program if, at the time the Contribution is
- added by the Contributor, such addition of the Contribution causes such
- combination to be covered by the Licensed Patents. The patent license
- shall not apply to any other combinations which include the Contribution.
- No hardware per se is licensed hereunder.
- c) Recipient understands that although each Contributor grants the licenses
- to its Contributions set forth herein, no assurances are provided by any
- Contributor that the Program does not infringe the patent or other
- intellectual property rights of any other entity. Each Contributor
- disclaims any liability to Recipient for claims brought by any other
- entity based on infringement of intellectual property rights or
- otherwise. As a condition to exercising the rights and licenses granted
- hereunder, each Recipient hereby assumes sole responsibility to secure
- any other intellectual property rights needed, if any. For example, if a
- third party patent license is required to allow Recipient to distribute
- the Program, it is Recipient's responsibility to acquire that license
- before distributing the Program.
- d) Each Contributor represents that to its knowledge it has sufficient
- copyright rights in its Contribution, if any, to grant the copyright
- license set forth in this Agreement.
-
-3. REQUIREMENTS
-
-A Contributor may choose to distribute the Program in object code form under
-its own license agreement, provided that:
-
- a) it complies with the terms and conditions of this Agreement; and
- b) its license agreement:
- i) effectively disclaims on behalf of all Contributors all warranties
- and conditions, express and implied, including warranties or
- conditions of title and non-infringement, and implied warranties or
- conditions of merchantability and fitness for a particular purpose;
- ii) effectively excludes on behalf of all Contributors all liability for
- damages, including direct, indirect, special, incidental and
- consequential damages, such as lost profits;
- iii) states that any provisions which differ from this Agreement are
- offered by that Contributor alone and not by any other party; and
- iv) states that source code for the Program is available from such
- Contributor, and informs licensees how to obtain it in a reasonable
- manner on or through a medium customarily used for software exchange.
-
-When the Program is made available in source code form:
-
- a) it must be made available under this Agreement; and
- b) a copy of this Agreement must be included with each copy of the Program.
- Contributors may not remove or alter any copyright notices contained
- within the Program.
-
-Each Contributor must identify itself as the originator of its Contribution,
-if
-any, in a manner that reasonably allows subsequent Recipients to identify the
-originator of the Contribution.
-
-4. COMMERCIAL DISTRIBUTION
-
-Commercial distributors of software may accept certain responsibilities with
-respect to end users, business partners and the like. While this license is
-intended to facilitate the commercial use of the Program, the Contributor who
-includes the Program in a commercial product offering should do so in a manner
-which does not create potential liability for other Contributors. Therefore,
-if a Contributor includes the Program in a commercial product offering, such
-Contributor ("Commercial Contributor") hereby agrees to defend and indemnify
-every other Contributor ("Indemnified Contributor") against any losses,
-damages and costs (collectively "Losses") arising from claims, lawsuits and
-other legal actions brought by a third party against the Indemnified
-Contributor to the extent caused by the acts or omissions of such Commercial
-Contributor in connection with its distribution of the Program in a commercial
-product offering. The obligations in this section do not apply to any claims
-or Losses relating to any actual or alleged intellectual property
-infringement. In order to qualify, an Indemnified Contributor must:
-a) promptly notify the Commercial Contributor in writing of such claim, and
-b) allow the Commercial Contributor to control, and cooperate with the
-Commercial Contributor in, the defense and any related settlement
-negotiations. The Indemnified Contributor may participate in any such claim at
-its own expense.
-
-For example, a Contributor might include the Program in a commercial product
-offering, Product X. That Contributor is then a Commercial Contributor. If
-that Commercial Contributor then makes performance claims, or offers
-warranties related to Product X, those performance claims and warranties are
-such Commercial Contributor's responsibility alone. Under this section, the
-Commercial Contributor would have to defend claims against the other
-Contributors related to those performance claims and warranties, and if a
-court requires any other Contributor to pay any damages as a result, the
-Commercial Contributor must pay those damages.
-
-5. NO WARRANTY
-
-EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
-IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE,
-NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each
-Recipient is solely responsible for determining the appropriateness of using
-and distributing the Program and assumes all risks associated with its
-exercise of rights under this Agreement , including but not limited to the
-risks and costs of program errors, compliance with applicable laws, damage to
-or loss of data, programs or equipment, and unavailability or interruption of
-operations.
-
-6. DISCLAIMER OF LIABILITY
-
-EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
-CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
-LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
-EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
-OF SUCH DAMAGES.
-
-7. GENERAL
-
-If any provision of this Agreement is invalid or unenforceable under
-applicable law, it shall not affect the validity or enforceability of the
-remainder of the terms of this Agreement, and without further action by the
-parties hereto, such provision shall be reformed to the minimum extent
-necessary to make such provision valid and enforceable.
-
-If Recipient institutes patent litigation against any entity (including a
-cross-claim or counterclaim in a lawsuit) alleging that the Program itself
-(excluding combinations of the Program with other software or hardware)
-infringes such Recipient's patent(s), then such Recipient's rights granted
-under Section 2(b) shall terminate as of the date such litigation is filed.
-
-All Recipient's rights under this Agreement shall terminate if it fails to
-comply with any of the material terms or conditions of this Agreement and does
-not cure such failure in a reasonable period of time after becoming aware of
-such noncompliance. If all Recipient's rights under this Agreement terminate,
-Recipient agrees to cease use and distribution of the Program as soon as
-reasonably practicable. However, Recipient's obligations under this Agreement
-and any licenses granted by Recipient relating to the Program shall continue
-and survive.
-
-Everyone is permitted to copy and distribute copies of this Agreement, but in
-order to avoid inconsistency the Agreement is copyrighted and may only be
-modified in the following manner. The Agreement Steward reserves the right to
-publish new versions (including revisions) of this Agreement from time to
-time. No one other than the Agreement Steward has the right to modify this
-Agreement. The Eclipse Foundation is the initial Agreement Steward. The
-Eclipse Foundation may assign the responsibility to serve as the Agreement
-Steward to a suitable separate entity. Each new version of the Agreement will
-be given a distinguishing version number. The Program (including
-Contributions) may always be distributed subject to the version of the
-Agreement under which it was received. In addition, after a new version of the
-Agreement is published, Contributor may elect to distribute the Program
-(including its Contributions) under the new version. Except as expressly
-stated in Sections 2(a) and 2(b) above, Recipient receives no rights or
-licenses to the intellectual property of any Contributor under this Agreement,
-whether expressly, by implication, estoppel or otherwise. All rights in the
-Program not expressly granted under this Agreement are reserved.
-
-This Agreement is governed by the laws of the State of New York and the
-intellectual property laws of the United States of America. No party to this
-Agreement will bring a legal action under this Agreement more than one year
-after the cause of action arose. Each party waives its rights to a jury trial in
-any resulting litigation.
-
-
diff --git a/README.md b/README.md
deleted file mode 100644
index 032abfb..0000000
--- a/README.md
+++ /dev/null
@@ -1,217 +0,0 @@
-# data.avl
-
-Persistent sorted maps and sets with support for the full clojure.core
-sorted collections API (in particular `clojure.core/(r)?(sub)?seq`),
-transients and additional logarithmic time operations: rank queries
-(via `clojure.core/nth` and `clojure.data.avl/rank-of`), "nearest key"
-lookups, splits by index or key and subsets/submaps.
-
-Persistent AVL trees are used as the underlying data structure.
-
-## Synopsis
-
-data.avl supports both Clojure and ClojureScript. It exports a single
-namespace with nine public functions, four of which are constructor
-functions which can be used as drop-in replacements for `clojure.core`
-/ `cljs.core` functions of the same names, while the remaining five
-expose data.avl-specific functionality:
-
- (require '[clojure.data.avl :as avl])
-
- ;; drop-in replacements for clojure.core counterparts
- (doc avl/sorted-map)
- (doc avl/sorted-map-by)
- (doc avl/sorted-set)
- (doc avl/sorted-set-by)
-
- ;; find rank of element as primitive long, -1 if not found
- (doc avl/rank-of)
-
- ;; find element closest to the given key and <=/>=/> according
- ;; to coll's comparator
- (doc avl/nearest)
-
- ;; split the given collection at the given key returning
- ;; [left entry? right]
- (doc avl/split-key)
-
- ;; split the given collection at the given index; similar to
- ;; clojure.core/split-at, but operates on and returns data.avl
- ;; collections
- (doc avl/split-at)
-
- ;; return subset/submap of the given collection; accepts arguments
- ;; reminiscent of clojure.core/{subseq,rsubseq}
- (doc avl/subrange)
-
-All data.avl collection-returning public functions return first-class
-collections (see below for a discussion).
-
-## Description
-
-data.avl maps and sets behave like the core Clojure variants, with the
-following differences:
-
-1. They have transient counterparts:
-
- (persistent! (assoc! (transient (avl/sorted-map)) 0 0))
- ;= {0 0}
-
- and use transients during construction:
-
- (apply avl/sorted-map (interleave (range 32) (range 32)))
- ;; ^- uses transients
-
-2. They are typically noticeably faster during lookups and somewhat
- slower during non-transient "updates" (`assoc`, `dissoc`) than the
- built-in sorted collections. Note that batch "updates" using
- transients typically perform better than batch "updates" on the
- non-transient-enabled built-ins.
-
-3. They add some memory overhead -- a reference and two `int`s per
- key. The additional node fields are used to support transients (one
- reference field per key), rank queries (one `int`) and the
- rebalancing algorithm itself (the final `int`).
-
-Additionally, data.avl collections support several features that the
-built-ins do not:
-
-1. Logarithmic time rank queries via `clojure.core/nth` and
- `clojure.data.avl/rank-of`:
-
- (nth (avl/sorted-map 0 0 1 1 2 2) 1)
- ;= [1 1]
- (nth (avl/sorted-set 0 1 2) 1)
- ;= 1
-
- (avl/rank-of (avl/sorted-map-by > 0 0 1 1 2 2) 0)
- 2
- (avl/rank-of (avl/sorted-set-by > 0 1 2) 0)
- 2
-
-2. Logarithmic time lookups of "nearest entries" via
- `clojure.data.avl/nearest`:
-
- (avl/nearest (avl/sorted-set 0 1 2) < 1)
- ;= 0
- (avl/nearest (avl/sorted-set 0 1 2) <= 1) ; or >=
- ;= 1
- (avl/nearest (avl/sorted-set 0 1 2) > 1)
- ;= 2
- (avl/nearest (avl/sorted-set 0 1 2) > 2)
- ;= nil
-
-3. Logarithmic time splitting by key:
-
- (avl/split-key 3 (avl/sorted-set 0 1 2 3 4 5))
- ;= [#{0 1 2} 3 #{4 5 6}]
- (avl/split-key 1 (avl/sorted-map 0 0 1 1 2 2))
- ;= [{0 0} [1 1] {2 2}]
- (avl/split-key 2 (avl/sorted-set 0 1 3 4))
- ;= [#{0 1} nil #{3 4}]
-
- The middle element of the returned vector is the entry at the given
- key for maps, stored copy of the key for sets and `nil` if the key
- is absent from the collection.
-
- The remaining two elements are the "left" and "right"
- subcollections of the original collection argument when split with
- the given key, comprising, respectively, the keys preceding and
- succeeding the given key in the order determined by the input
- collection's comparator.
-
-4. Logarithmic time splitting by index:
-
- (avl/split-at 2 (avl/sorted-set 0 1 2 3 4 5))
- ;= [#{0 1} #{2 3 4 5}]
-
-5. Logarithmic time slicing:
-
- (avl/subrange (avl/sorted-set 0 1 2 3 4 5) > 1)
- ;= #{2 3 4 5}
- (avl/subrange (avl/sorted-set 0 1 2 3 4 5) <= 4)
- ;= #{0 1 2 3 4}
- (avl/subrange (avl/sorted-set 0 1 2 3 4 5) >= 2 < 5)
- ;= #{2 3 4}
-
-6. `clojure.data.avl/split-key`, `clojure.data.avl/split-at` and
- `clojure.data.avl/subrange` all return first-class data.avl
- collections, completely independent of the originals. In
- particular, they do not prevent the originals from being garbage
- collected and they support insertion of arbitrary keys, including
- outside original `subrange` bounds.
-
-## Documentation
-
-* [API Reference](https://clojure.github.io/data.avl/) (Autogenerated)
-
-## Releases and dependency information
-
-data.avl requires Clojure >= 1.5.0. The ClojureScript version is
-regularly tested against the most recent ClojureScript release.
-
-data.avl releases are available from Maven Central. Development
-snapshots are available from the Sonatype OSS repository.
-
- * [Released versions](https://search.maven.org/#search%7Cga%7C1%7Corg.clojure%2Fdata.avl)
-
- * [Development snapshots](https://oss.sonatype.org/index.html#nexus-search;gav~org.clojure~data.avl~~~)
-
-Follow the first link above to discover the current release number.
-
-[CLI/`deps.edn`](https://clojure.org/reference/deps_and_cli) dependency information:
-```clojure
-org.clojure/data.avl {:mvn/version "${version}"}
-```
-
-[Leiningen](https://leiningen.org/) dependency information:
-
- [org.clojure/data.avl "${version}"]
-
-[Maven](https://maven.apache.org/) dependency information:
-
-
- org.clojure
- data.avl
- ${version}
-
-
-[Gradle](https://www.gradle.org/) dependency information:
-
- compile "org.clojure:data.avl:${version}"
-
-## Developer information
-
-data.avl is being developed as a Clojure Contrib project, see the
-[What is Clojure Contrib](https://clojure.org/dev/contrib_libs)
-page for details. Patches will only be accepted from developers who
-have signed the Clojure Contributor Agreement.
-
-* [GitHub project](https://github.com/clojure/data.avl)
-* [Bug Tracker](https://clojure.atlassian.net/browse/DAVL)
-* [Continuous Integration](https://github.com/clojure/data.avl/actions/workflows/test.yml)
-
-## Clojure(Script) code reuse
-
-data.avl sorted maps and sets support the same basic functionality
-regular Clojure's sorted maps and sets do (with the additions listed
-above). Some of the code supporting various Clojure(Script) interfaces
-and protocols is adapted from the ClojureScript implementations of the
-red-black-tree-based sorted collections, which themselves are ports of
-Clojure's implementations written in Java. The Clojure(Script) source
-files containing the relevant code carry the following copyright
-notice:
-
- Copyright (c) Rich Hickey. All rights reserved.
- The use and distribution terms for this software are covered by the
- Eclipse Public License 1.0 (https://opensource.org/licenses/eclipse-1.0.php)
- which can be found in the file epl-v10.html at the root of this distribution.
- By using this software in any fashion, you are agreeing to be bound by
- the terms of this license.
- You must not remove this notice, or any other, from this software.
-
-## Licence
-
-Copyright © Michał Marczyk, Rich Hickey and contributors
-
-Distributed under the Eclipse Public License, the same as Clojure.
diff --git a/api-index.html b/api-index.html
new file mode 100644
index 0000000..e739f26
--- /dev/null
+++ b/api-index.html
@@ -0,0 +1,239 @@
+
+
+
+ Index - data.avl 0.2.0-SNAPSHOT API documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index of Public Functions and Variables -
+This page has an alphabetical index of all the documented functions and variables
+in
data.avl .
+
+
+
+
+
+
+
A
+
+ AVLMap type clojure.data.avl
+ AVLMapSeq type clojure.data.avl
+ AVLNode type clojure.data.avl
+ AVLSet type clojure.data.avl
+ AVLTransientMap type clojure.data.avl
+ AVLTransientSet type clojure.data.avl
+
+
+
+
N
+
+ nearest function clojure.data.avl (alpha) Equivalent to, but more efficient than, (...
+
+
+
+
R
+
+ rank-of function clojure.data.avl Returns the rank of x in coll or -1 if not present...
+
+
+
+
S
+
+ sorted-map function clojure.data.avl keyval => key val Returns a new AVL map with suppl...
+ sorted-map-by function clojure.data.avl keyval => key val Returns a new sorted map with su...
+ sorted-set function clojure.data.avl Returns a new sorted set with supplied keys..
+ sorted-set-by function clojure.data.avl Returns a new sorted set with supplied keys, using...
+ split-at function clojure.data.avl (alpha) Equivalent to, but more efficient than, [...
+ split-key function clojure.data.avl (alpha) Returns [left e? right], where left and r...
+ subrange function clojure.data.avl (alpha) Returns an AVL collection comprising the ...
+
+
+
+
+
+
+
+
+
+
+
+
Logo & site design by
Tom Hickey .
+ Clojure auto-documentation system by Tom Faulhaber.
+
+
+
+
+
\ No newline at end of file
diff --git a/epl.html b/epl.html
deleted file mode 100644
index fd39122..0000000
--- a/epl.html
+++ /dev/null
@@ -1,261 +0,0 @@
-
-
-
-
-
-
-Eclipse Public License - Version 1.0
-
-
-
-
-
-
-Eclipse Public License - v 1.0
-
-THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
-PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR
-DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS
-AGREEMENT.
-
-1. DEFINITIONS
-
-"Contribution" means:
-
-a) in the case of the initial Contributor, the initial
-code and documentation distributed under this Agreement, and
-b) in the case of each subsequent Contributor:
-i) changes to the Program, and
-ii) additions to the Program;
-where such changes and/or additions to the Program
-originate from and are distributed by that particular Contributor. A
-Contribution 'originates' from a Contributor if it was added to the
-Program by such Contributor itself or anyone acting on such
-Contributor's behalf. Contributions do not include additions to the
-Program which: (i) are separate modules of software distributed in
-conjunction with the Program under their own license agreement, and (ii)
-are not derivative works of the Program.
-
-"Contributor" means any person or entity that distributes
-the Program.
-
-"Licensed Patents" mean patent claims licensable by a
-Contributor which are necessarily infringed by the use or sale of its
-Contribution alone or when combined with the Program.
-
-"Program" means the Contributions distributed in accordance
-with this Agreement.
-
-"Recipient" means anyone who receives the Program under
-this Agreement, including all Contributors.
-
-2. GRANT OF RIGHTS
-
-a) Subject to the terms of this Agreement, each
-Contributor hereby grants Recipient a non-exclusive, worldwide,
-royalty-free copyright license to reproduce, prepare derivative works
-of, publicly display, publicly perform, distribute and sublicense the
-Contribution of such Contributor, if any, and such derivative works, in
-source code and object code form.
-
-b) Subject to the terms of this Agreement, each
-Contributor hereby grants Recipient a non-exclusive, worldwide,
-royalty-free patent license under Licensed Patents to make, use, sell,
-offer to sell, import and otherwise transfer the Contribution of such
-Contributor, if any, in source code and object code form. This patent
-license shall apply to the combination of the Contribution and the
-Program if, at the time the Contribution is added by the Contributor,
-such addition of the Contribution causes such combination to be covered
-by the Licensed Patents. The patent license shall not apply to any other
-combinations which include the Contribution. No hardware per se is
-licensed hereunder.
-
-c) Recipient understands that although each Contributor
-grants the licenses to its Contributions set forth herein, no assurances
-are provided by any Contributor that the Program does not infringe the
-patent or other intellectual property rights of any other entity. Each
-Contributor disclaims any liability to Recipient for claims brought by
-any other entity based on infringement of intellectual property rights
-or otherwise. As a condition to exercising the rights and licenses
-granted hereunder, each Recipient hereby assumes sole responsibility to
-secure any other intellectual property rights needed, if any. For
-example, if a third party patent license is required to allow Recipient
-to distribute the Program, it is Recipient's responsibility to acquire
-that license before distributing the Program.
-
-d) Each Contributor represents that to its knowledge it
-has sufficient copyright rights in its Contribution, if any, to grant
-the copyright license set forth in this Agreement.
-
-3. REQUIREMENTS
-
-A Contributor may choose to distribute the Program in object code
-form under its own license agreement, provided that:
-
-a) it complies with the terms and conditions of this
-Agreement; and
-
-b) its license agreement:
-
-i) effectively disclaims on behalf of all Contributors
-all warranties and conditions, express and implied, including warranties
-or conditions of title and non-infringement, and implied warranties or
-conditions of merchantability and fitness for a particular purpose;
-
-ii) effectively excludes on behalf of all Contributors
-all liability for damages, including direct, indirect, special,
-incidental and consequential damages, such as lost profits;
-
-iii) states that any provisions which differ from this
-Agreement are offered by that Contributor alone and not by any other
-party; and
-
-iv) states that source code for the Program is available
-from such Contributor, and informs licensees how to obtain it in a
-reasonable manner on or through a medium customarily used for software
-exchange.
-
-When the Program is made available in source code form:
-
-a) it must be made available under this Agreement; and
-
-b) a copy of this Agreement must be included with each
-copy of the Program.
-
-Contributors may not remove or alter any copyright notices contained
-within the Program.
-
-Each Contributor must identify itself as the originator of its
-Contribution, if any, in a manner that reasonably allows subsequent
-Recipients to identify the originator of the Contribution.
-
-4. COMMERCIAL DISTRIBUTION
-
-Commercial distributors of software may accept certain
-responsibilities with respect to end users, business partners and the
-like. While this license is intended to facilitate the commercial use of
-the Program, the Contributor who includes the Program in a commercial
-product offering should do so in a manner which does not create
-potential liability for other Contributors. Therefore, if a Contributor
-includes the Program in a commercial product offering, such Contributor
-("Commercial Contributor") hereby agrees to defend and
-indemnify every other Contributor ("Indemnified Contributor")
-against any losses, damages and costs (collectively "Losses")
-arising from claims, lawsuits and other legal actions brought by a third
-party against the Indemnified Contributor to the extent caused by the
-acts or omissions of such Commercial Contributor in connection with its
-distribution of the Program in a commercial product offering. The
-obligations in this section do not apply to any claims or Losses
-relating to any actual or alleged intellectual property infringement. In
-order to qualify, an Indemnified Contributor must: a) promptly notify
-the Commercial Contributor in writing of such claim, and b) allow the
-Commercial Contributor to control, and cooperate with the Commercial
-Contributor in, the defense and any related settlement negotiations. The
-Indemnified Contributor may participate in any such claim at its own
-expense.
-
-For example, a Contributor might include the Program in a commercial
-product offering, Product X. That Contributor is then a Commercial
-Contributor. If that Commercial Contributor then makes performance
-claims, or offers warranties related to Product X, those performance
-claims and warranties are such Commercial Contributor's responsibility
-alone. Under this section, the Commercial Contributor would have to
-defend claims against the other Contributors related to those
-performance claims and warranties, and if a court requires any other
-Contributor to pay any damages as a result, the Commercial Contributor
-must pay those damages.
-
-5. NO WARRANTY
-
-EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
-PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
-OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION,
-ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
-OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
-responsible for determining the appropriateness of using and
-distributing the Program and assumes all risks associated with its
-exercise of rights under this Agreement , including but not limited to
-the risks and costs of program errors, compliance with applicable laws,
-damage to or loss of data, programs or equipment, and unavailability or
-interruption of operations.
-
-6. DISCLAIMER OF LIABILITY
-
-EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
-NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
-WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
-DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
-HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
-
-7. GENERAL
-
-If any provision of this Agreement is invalid or unenforceable under
-applicable law, it shall not affect the validity or enforceability of
-the remainder of the terms of this Agreement, and without further action
-by the parties hereto, such provision shall be reformed to the minimum
-extent necessary to make such provision valid and enforceable.
-
-If Recipient institutes patent litigation against any entity
-(including a cross-claim or counterclaim in a lawsuit) alleging that the
-Program itself (excluding combinations of the Program with other
-software or hardware) infringes such Recipient's patent(s), then such
-Recipient's rights granted under Section 2(b) shall terminate as of the
-date such litigation is filed.
-
-All Recipient's rights under this Agreement shall terminate if it
-fails to comply with any of the material terms or conditions of this
-Agreement and does not cure such failure in a reasonable period of time
-after becoming aware of such noncompliance. If all Recipient's rights
-under this Agreement terminate, Recipient agrees to cease use and
-distribution of the Program as soon as reasonably practicable. However,
-Recipient's obligations under this Agreement and any licenses granted by
-Recipient relating to the Program shall continue and survive.
-
-Everyone is permitted to copy and distribute copies of this
-Agreement, but in order to avoid inconsistency the Agreement is
-copyrighted and may only be modified in the following manner. The
-Agreement Steward reserves the right to publish new versions (including
-revisions) of this Agreement from time to time. No one other than the
-Agreement Steward has the right to modify this Agreement. The Eclipse
-Foundation is the initial Agreement Steward. The Eclipse Foundation may
-assign the responsibility to serve as the Agreement Steward to a
-suitable separate entity. Each new version of the Agreement will be
-given a distinguishing version number. The Program (including
-Contributions) may always be distributed subject to the version of the
-Agreement under which it was received. In addition, after a new version
-of the Agreement is published, Contributor may elect to distribute the
-Program (including its Contributions) under the new version. Except as
-expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
-rights or licenses to the intellectual property of any Contributor under
-this Agreement, whether expressly, by implication, estoppel or
-otherwise. All rights in the Program not expressly granted under this
-Agreement are reserved.
-
-This Agreement is governed by the laws of the State of New York and
-the intellectual property laws of the United States of America. No party
-to this Agreement will bring a legal action under this Agreement more
-than one year after the cause of action arose. Each party waives its
-rights to a jury trial in any resulting litigation.
-
-
-
-
diff --git a/index-0.0.18.clj b/index-0.0.18.clj
new file mode 100644
index 0000000..8e04cf1
--- /dev/null
+++ b/index-0.0.18.clj
@@ -0,0 +1,196 @@
+{:namespaces
+ ({:doc
+ "An implementation of persistent sorted maps and sets based on AVL\ntrees which can be used as drop-in replacements for Clojure's\nbuilt-in sorted maps and sets based on red-black trees. Apart from\nthe standard sorted collection API, the provided map and set types\nsupport the transients API and several additional logarithmic time\noperations: rank queries via clojure.core/nth (select element by\nrank) and clojure.data.avl/rank-of (discover rank of element),\n\"nearest key\" lookups via clojure.data.avl/nearest, splits by key\nand index via clojure.data.avl/split-key and\nclojure.data.avl/split-at, respectively, and subsets/submaps using\nclojure.data.avl/subrange.",
+ :author "Michał Marczyk",
+ :name "clojure.data.avl",
+ :wiki-url "http://clojure.github.io/data.avl/index.html",
+ :source-url
+ "https://github.com/clojure/data.avl/blob/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj"}),
+ :vars
+ ({:raw-source-url
+ "https://github.com/clojure/data.avl/raw/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj",
+ :added "0.0.12",
+ :name "nearest",
+ :file "src/main/clojure/clojure/data/avl.clj",
+ :source-url
+ "https://github.com/clojure/data.avl/blob/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj#L1919",
+ :line 1919,
+ :var-type "function",
+ :arglists ([coll test x]),
+ :doc
+ "(alpha)\n\nEquivalent to, but more efficient than, (first (subseq* coll test x)),\nwhere subseq* is clojure.core/subseq for test in #{>, >=} and\nclojure.core/rsubseq for test in #{<, <=}.",
+ :namespace "clojure.data.avl",
+ :wiki-url
+ "http://clojure.github.io/data.avl//index.html#clojure.data.avl/nearest"}
+ {:raw-source-url
+ "https://github.com/clojure/data.avl/raw/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj",
+ :added "0.0.6",
+ :name "rank-of",
+ :file "src/main/clojure/clojure/data/avl.clj",
+ :source-url
+ "https://github.com/clojure/data.avl/blob/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj#L1913",
+ :line 1913,
+ :var-type "function",
+ :arglists ([coll x]),
+ :doc "Returns the rank of x in coll or -1 if not present.",
+ :namespace "clojure.data.avl",
+ :wiki-url
+ "http://clojure.github.io/data.avl//index.html#clojure.data.avl/rank-of"}
+ {:raw-source-url
+ "https://github.com/clojure/data.avl/raw/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj",
+ :added "0.0.1",
+ :name "sorted-map",
+ :file "src/main/clojure/clojure/data/avl.clj",
+ :source-url
+ "https://github.com/clojure/data.avl/blob/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj#L1865",
+ :line 1865,
+ :var-type "function",
+ :arglists ([& keyvals]),
+ :doc
+ "keyval => key val\nReturns a new AVL map with supplied mappings.",
+ :namespace "clojure.data.avl",
+ :wiki-url
+ "http://clojure.github.io/data.avl//index.html#clojure.data.avl/sorted-map"}
+ {:raw-source-url
+ "https://github.com/clojure/data.avl/raw/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj",
+ :added "0.0.1",
+ :name "sorted-map-by",
+ :file "src/main/clojure/clojure/data/avl.clj",
+ :source-url
+ "https://github.com/clojure/data.avl/blob/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj#L1880",
+ :line 1880,
+ :var-type "function",
+ :arglists ([comparator & keyvals]),
+ :doc
+ "keyval => key val\nReturns a new sorted map with supplied mappings, using the supplied\ncomparator.",
+ :namespace "clojure.data.avl",
+ :wiki-url
+ "http://clojure.github.io/data.avl//index.html#clojure.data.avl/sorted-map-by"}
+ {:raw-source-url
+ "https://github.com/clojure/data.avl/raw/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj",
+ :added "0.0.1",
+ :name "sorted-set",
+ :file "src/main/clojure/clojure/data/avl.clj",
+ :source-url
+ "https://github.com/clojure/data.avl/blob/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj#L1898",
+ :line 1898,
+ :var-type "function",
+ :arglists ([& keys]),
+ :doc "Returns a new sorted set with supplied keys.",
+ :namespace "clojure.data.avl",
+ :wiki-url
+ "http://clojure.github.io/data.avl//index.html#clojure.data.avl/sorted-set"}
+ {:raw-source-url
+ "https://github.com/clojure/data.avl/raw/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj",
+ :added "0.0.1",
+ :name "sorted-set-by",
+ :file "src/main/clojure/clojure/data/avl.clj",
+ :source-url
+ "https://github.com/clojure/data.avl/blob/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj#L1904",
+ :line 1904,
+ :var-type "function",
+ :arglists ([comparator & keys]),
+ :doc
+ "Returns a new sorted set with supplied keys, using the supplied comparator.",
+ :namespace "clojure.data.avl",
+ :wiki-url
+ "http://clojure.github.io/data.avl//index.html#clojure.data.avl/sorted-set-by"}
+ {:raw-source-url
+ "https://github.com/clojure/data.avl/raw/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj",
+ :added "0.0.12",
+ :name "split-at",
+ :file "src/main/clojure/clojure/data/avl.clj",
+ :source-url
+ "https://github.com/clojure/data.avl/blob/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj#L1959",
+ :line 1959,
+ :var-type "function",
+ :arglists ([n coll]),
+ :doc
+ "(alpha)\n\nEquivalent to, but more efficient than,\n[(into (empty coll) (take n coll))\n (into (empty coll) (drop n coll))].",
+ :namespace "clojure.data.avl",
+ :wiki-url
+ "http://clojure.github.io/data.avl//index.html#clojure.data.avl/split-at"}
+ {:raw-source-url
+ "https://github.com/clojure/data.avl/raw/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj",
+ :added "0.0.12",
+ :name "split-key",
+ :file "src/main/clojure/clojure/data/avl.clj",
+ :source-url
+ "https://github.com/clojure/data.avl/blob/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj#L1929",
+ :line 1929,
+ :var-type "function",
+ :arglists ([k coll]),
+ :doc
+ "(alpha)\n\nReturns [left e? right], where left and right are collections of\nthe same type as coll and containing, respectively, the keys below\nand above k in the ordering determined by coll's comparator, while\ne? is the entry at key k for maps, the stored copy of the key k for\nsets, nil if coll does not contain k.",
+ :namespace "clojure.data.avl",
+ :wiki-url
+ "http://clojure.github.io/data.avl//index.html#clojure.data.avl/split-key"}
+ {:raw-source-url
+ "https://github.com/clojure/data.avl/raw/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj",
+ :added "0.0.12",
+ :name "subrange",
+ :file "src/main/clojure/clojure/data/avl.clj",
+ :source-url
+ "https://github.com/clojure/data.avl/blob/579118e7572234ab619b4e9105761f90d4453730/src/main/clojure/clojure/data/avl.clj#L1974",
+ :line 1974,
+ :var-type "function",
+ :arglists ([coll test limit] [coll start-test start end-test end]),
+ :doc
+ "(alpha)\n\nReturns an AVL collection comprising the entries of coll between\nstart and end (in the sense determined by coll's comparator) in\nlogarithmic time. Whether the endpoints are themselves included in\nthe returned collection depends on the provided tests; start-test\nmust be either > or >=, end-test must be either < or <=.\n\nWhen passed a single test and limit, subrange infers the other end\nof the range from the test: > / >= mean to include items up to the\nend of coll, < / <= mean to include items taken from the beginning\nof coll.\n\n(subrange coll >= start <= end) is equivalent to, but more efficient\nthan, (into (empty coll) (subseq coll >= start <= end)).",
+ :namespace "clojure.data.avl",
+ :wiki-url
+ "http://clojure.github.io/data.avl//index.html#clojure.data.avl/subrange"}
+ {:name "AVLMap",
+ :var-type "type",
+ :namespace "clojure.data.avl",
+ :arglists nil,
+ :wiki-url
+ "http://clojure.github.io/data.avl//index.html#clojure.data.avl/AVLMap",
+ :source-url nil,
+ :raw-source-url nil,
+ :file nil}
+ {:name "AVLMapSeq",
+ :var-type "type",
+ :namespace "clojure.data.avl",
+ :arglists nil,
+ :wiki-url
+ "http://clojure.github.io/data.avl//index.html#clojure.data.avl/AVLMapSeq",
+ :source-url nil,
+ :raw-source-url nil,
+ :file nil}
+ {:name "AVLNode",
+ :var-type "type",
+ :namespace "clojure.data.avl",
+ :arglists nil,
+ :wiki-url
+ "http://clojure.github.io/data.avl//index.html#clojure.data.avl/AVLNode",
+ :source-url nil,
+ :raw-source-url nil,
+ :file nil}
+ {:name "AVLSet",
+ :var-type "type",
+ :namespace "clojure.data.avl",
+ :arglists nil,
+ :wiki-url
+ "http://clojure.github.io/data.avl//index.html#clojure.data.avl/AVLSet",
+ :source-url nil,
+ :raw-source-url nil,
+ :file nil}
+ {:name "AVLTransientMap",
+ :var-type "type",
+ :namespace "clojure.data.avl",
+ :arglists nil,
+ :wiki-url
+ "http://clojure.github.io/data.avl//index.html#clojure.data.avl/AVLTransientMap",
+ :source-url nil,
+ :raw-source-url nil,
+ :file nil}
+ {:name "AVLTransientSet",
+ :var-type "type",
+ :namespace "clojure.data.avl",
+ :arglists nil,
+ :wiki-url
+ "http://clojure.github.io/data.avl//index.html#clojure.data.avl/AVLTransientSet",
+ :source-url nil,
+ :raw-source-url nil,
+ :file nil})}
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..6694d33
--- /dev/null
+++ b/index.html
@@ -0,0 +1,353 @@
+
+
+
+ clojure.data.avl - data.avl 0.2.0-SNAPSHOT API documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
API for clojure.data.avl
+ -
+
+
by Michał Marczyk
+
Full namespace name:
clojure.data.avl
+
+
Overview
+
+
An implementation of persistent sorted maps and sets based on AVL
+trees which can be used as drop-in replacements for Clojure's
+built-in sorted maps and sets based on red-black trees. Apart from
+the standard sorted collection API, the provided map and set types
+support the transients API and several additional logarithmic time
+operations: rank queries via clojure.core/nth (select element by
+rank) and clojure.data.avl/rank-of (discover rank of element),
+"nearest key" lookups via clojure.data.avl/nearest, splits by key
+and index via clojure.data.avl/split-key and
+clojure.data.avl/split-at, respectively, and subsets/submaps using
+clojure.data.avl/subrange.
+
+
+
+
+
+
+
+
Types
+
+
+
+
AVLMap
+
type
+
+ Fields:
[comp tree cnt _meta _hash _hasheq]
+ Protocols:
clojure.core.protocols/IKVReduce
+ Interfaces:
clojure.data.avl.IAVLTree, clojure.data.avl.INavigableTree, clojure.lang.Associative, clojure.lang.Counted, clojure.lang.IEditableCollection, clojure.lang.IFn, clojure.lang.IHashEq, clojure.lang.ILookup, clojure.lang.IMeta, clojure.lang.IObj, clojure.lang.IPersistentCollection, clojure.lang.IPersistentMap, clojure.lang.IReduce, clojure.lang.Indexed, clojure.lang.MapEquivalence, clojure.lang.Reversible, clojure.lang.Seqable, clojure.lang.Sorted, java.io.Serializable, java.lang.Iterable, java.util.Map
+
+
+
+
AVLMapSeq
+
type
+
+ Fields:
[_meta stack ascending? cnt _hash _hasheq]
+ Protocols:
+ Interfaces:
clojure.lang.Counted, clojure.lang.IHashEq, clojure.lang.IMeta, clojure.lang.IObj, clojure.lang.IPersistentCollection, clojure.lang.ISeq, clojure.lang.Seqable, clojure.lang.Sequential, java.io.Serializable, java.util.List
+
+
+
+
AVLNode
+
type
+
+ Fields:
[edit key val left right height rank]
+ Protocols:
+ Interfaces:
clojure.data.avl.IAVLNode, clojure.lang.Associative, clojure.lang.Counted, clojure.lang.IEditableCollection, clojure.lang.IFn, clojure.lang.IHashEq, clojure.lang.ILookup, clojure.lang.IMapEntry, clojure.lang.IMeta, clojure.lang.IObj, clojure.lang.IPersistentCollection, clojure.lang.IPersistentStack, clojure.lang.IPersistentVector, clojure.lang.Indexed, clojure.lang.Reversible, clojure.lang.Seqable, clojure.lang.Sequential, java.io.Serializable, java.lang.Comparable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.Map$Entry, java.util.RandomAccess
+
+
+
+
AVLSet
+
type
+
+ Fields:
[_meta avl-map _hash _hasheq]
+ Protocols:
+ Interfaces:
clojure.data.avl.IAVLTree, clojure.data.avl.INavigableTree, clojure.lang.Counted, clojure.lang.IEditableCollection, clojure.lang.IFn, clojure.lang.IHashEq, clojure.lang.ILookup, clojure.lang.IMeta, clojure.lang.IObj, clojure.lang.IPersistentCollection, clojure.lang.IPersistentSet, clojure.lang.IReduce, clojure.lang.Indexed, clojure.lang.Reversible, clojure.lang.Seqable, clojure.lang.Sorted, java.io.Serializable, java.util.Set
+
+
+
+
AVLTransientMap
+
type
+
+ Fields:
[edit comp tree cnt]
+ Protocols:
+ Interfaces:
clojure.data.avl.ITransientAssociative2Impl, clojure.lang.Counted, clojure.lang.IFn, clojure.lang.ILookup, clojure.lang.ITransientAssociative, clojure.lang.ITransientCollection, clojure.lang.ITransientMap
+
+
+
+
AVLTransientSet
+
type
+
+ Fields:
[transient-avl-map]
+ Protocols:
+ Interfaces:
clojure.lang.Counted, clojure.lang.IFn, clojure.lang.ITransientCollection, clojure.lang.ITransientSet
+
+
+
+
+
Public Variables and Functions
+
+
+
+
nearest
+
function
+
Usage: (nearest coll test x)
+
+
(alpha)
+
+Equivalent to, but more efficient than, (first (subseq* coll test x)),
+where subseq* is clojure.core/subseq for test in #{>, >=} and
+clojure.core/rsubseq for test in #{<, <=}.
+
+
Added in data.avl version 0.0.12
+
+
Source
+
+
+
+
rank-of
+
function
+
Usage: (rank-of coll x)
+
+
Returns the rank of x in coll or -1 if not present.
+
+
Added in data.avl version 0.0.6
+
+
Source
+
+
+
+
sorted-map
+
function
+
Usage: (sorted-map & keyvals)
+
+
keyval => key val
+Returns a new AVL map with supplied mappings.
+
+
Added in data.avl version 0.0.1
+
+
Source
+
+
+
+
sorted-map-by
+
function
+
Usage: (sorted-map-by comparator & keyvals)
+
+
keyval => key val
+Returns a new sorted map with supplied mappings, using the supplied
+comparator.
+
+
Added in data.avl version 0.0.1
+
+
Source
+
+
+
+
sorted-set
+
function
+
Usage: (sorted-set & keys)
+
+
Returns a new sorted set with supplied keys.
+
+
Added in data.avl version 0.0.1
+
+
Source
+
+
+
+
sorted-set-by
+
function
+
Usage: (sorted-set-by comparator & keys)
+
+
Returns a new sorted set with supplied keys, using the supplied comparator.
+
+
Added in data.avl version 0.0.1
+
+
Source
+
+
+
+
split-at
+
function
+
Usage: (split-at n coll)
+
+
(alpha)
+
+Equivalent to, but more efficient than,
+[(into (empty coll) (take n coll))
+ (into (empty coll) (drop n coll))].
+
+
Added in data.avl version 0.0.12
+
+
Source
+
+
+
+
split-key
+
function
+
Usage: (split-key k coll)
+
+
(alpha)
+
+Returns [left e? right], where left and right are collections of
+the same type as coll and containing, respectively, the keys below
+and above k in the ordering determined by coll's comparator, while
+e? is the entry at key k for maps, the stored copy of the key k for
+sets, nil if coll does not contain k.
+
+
Added in data.avl version 0.0.12
+
+
Source
+
+
+
+
subrange
+
function
+
Usage: (subrange coll test limit)
+ (subrange coll start-test start end-test end)
+
+
(alpha)
+
+Returns an AVL collection comprising the entries of coll between
+start and end (in the sense determined by coll's comparator) in
+logarithmic time. Whether the endpoints are themselves included in
+the returned collection depends on the provided tests; start-test
+must be either > or >=, end-test must be either < or <=.
+
+When passed a single test and limit, subrange infers the other end
+of the range from the test: > / >= mean to include items up to the
+end of coll, < / <= mean to include items taken from the beginning
+of coll.
+
+(subrange coll >= start <= end) is equivalent to, but more efficient
+than, (into (empty coll) (subseq coll >= start <= end)).
+
+
Added in data.avl version 0.0.12
+
+
Source
+
+
+
+
+
+
+
+
+
+
+
+
Logo & site design by
Tom Hickey .
+ Clojure auto-documentation system by Tom Faulhaber.
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
deleted file mode 100644
index ce23297..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,66 +0,0 @@
-
-
- 4.0.0
- data.avl
- 0.2.2-SNAPSHOT
- data.avl
- Persistent sorted maps and sets with log-time rank queries
-
-
-
- Eclipse Public License 1.0
- http://opensource.org/licenses/eclipse-1.0.php
- repo
-
-
-
-
- org.clojure
- pom.contrib
- 1.4.0
-
-
-
-
- Michał Marczyk
- https://github.com/michalmarczyk
-
-
-
-
- scm:git:git://github.com/clojure/data.avl.git
- scm:git:git://github.com/clojure/data.avl.git
- https://github.com/clojure/data.avl
- HEAD
-
-
-
- 1.11.4
- true
-
-
-
-
-
- org.codehaus.mojo
- build-helper-maven-plugin
-
-
- add-clojurescript-source-dirs
- generate-sources
-
- add-resource
-
-
-
-
- src/main/cljs
-
-
-
-
-
-
-
-
-
diff --git a/project.clj b/project.clj
deleted file mode 100644
index 28a837a..0000000
--- a/project.clj
+++ /dev/null
@@ -1,37 +0,0 @@
-(defproject org.clojure/data.avl "0.0.18-SNAPSHOT"
- :description "Persistent sorted maps and sets with log-time rank queries"
- :url "https://github.com/clojure/data.avl"
- :license {:name "Eclipse Public License"
- :url "http://www.eclipse.org/legal/epl-v10.html"}
- :min-lein-version "2.6.1"
- :parent [org.clojure/pom.contrib "1.4.0"]
- :dependencies [[org.clojure/clojure "1.11.4"]]
- :jvm-opts ^:replace ["-Dorg.clojure.data.avl.test.large-tree-size=100000"
- "-Dorg.clojure.data.avl.test.medium-tree-size=100000"
- "-Dorg.clojure.data.avl.test.small-tree-size=300"]
- :source-paths ["src/main/clojure" "src/main/cljs"]
- :test-paths ["src/test/clojure"]
- :aliases {"all" ["with-profile" "dev:dev,1.6:dev,1.7:dev,1.8:dev,1.9"]}
- :profiles {:dbg {:jvm-opts ["-XX:-OmitStackTraceInFastThrow"]}
- :cljs {:dependencies [[org.clojure/clojure "1.11.4"]
- [org.clojure/clojurescript "1.10.520"]
- [org.clojure/test.check "1.1.3"]
- [collection-check "0.1.7"]]
- :hooks [leiningen.cljsbuild]
- :plugins [[lein-cljsbuild "1.1.4"]]
- :cljsbuild
- {:test-commands {"phantom" ["phantomjs" "out/test.js"]}
- :builds {:test
- {:source-paths ["src/main/cljs"
- "src/test/clojure"
- "src/test_local/cljc"
- "src/test/cljs"]
- :compiler {:output-to "out/test.js"
- :main clojure.data.avl-test-runner
- :optimizations :advanced
- :pretty-print false
- :static-fns true}}}}}
- :1.9 {:dependencies [[org.clojure/clojure "1.9.0"]
- [org.clojure/test.check "1.1.3"]
- [collection-check "0.1.7"]]
- :test-paths ["src/test_local/cljc"]}})
diff --git a/script/test b/script/test
deleted file mode 100755
index cc81b02..0000000
--- a/script/test
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/bash
-
-if [ "${V8_HOME}" = "" -a "${SPIDERMONKEY_HOME}" = "" ]; then
- echo "Neither V8_HOME nor SPIDERMONKEY_HOME is set, cannot run tests"
- exit 1
-fi
-
-rm -rf out
-mkdir -p out
-lein with-profile +cljs cljsbuild once test
-echo "Launching test runner..."
-
-if [ "${V8_HOME}" != "" ]; then
- echo "Testing with V8:"
- "${V8_HOME}/d8" out/test.js
-fi
-
-if [ "${SPIDERMONKEY_HOME}" != "" ]; then
- echo "Testing with SpiderMonkey:"
- "${SPIDERMONKEY_HOME}/js" -f out/test.js
-fi
diff --git a/src/main/cljs/clojure/data/avl.cljs b/src/main/cljs/clojure/data/avl.cljs
deleted file mode 100644
index e4618a5..0000000
--- a/src/main/cljs/clojure/data/avl.cljs
+++ /dev/null
@@ -1,1377 +0,0 @@
-; Copyright (c) Rich Hickey and contributors. All rights reserved.
-; The use and distribution terms for this software are covered by the
-; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
-; which can be found in the file epl-v10.html at the root of this distribution.
-; By using this software in any fashion, you are agreeing to be bound by
-; the terms of this license.
-; You must not remove this notice, or any other, from this software.
-
-(ns clojure.data.avl
-
- "An implementation of persistent sorted maps and sets based on AVL
- trees which can be used as drop-in replacements for Clojure's
- built-in sorted maps and sets based on red-black trees. Apart from
- the standard sorted collection API, the provided map and set types
- support the transients API and several additional logarithmic time
- operations: rank queries via clojure.core/nth (select element by
- rank) and clojure.data.avl/rank-of (discover rank of element),
- \"nearest key\" lookups via clojure.data.avl/nearest, splits by key
- and index via clojure.data.avl/split-key and
- clojure.data.avl/split-at, respectively, and subsets/submaps using
- clojure.data.avl/subrange."
-
- {:author "Michał Marczyk"}
-
- (:refer-clojure :exclude [sorted-map sorted-map-by sorted-set sorted-set-by
- range split-at]))
-
-(deftype AVLNode [edit
- ^:mutable key
- ^:mutable val
- ^:mutable left
- ^:mutable right
- ^:mutable height
- ^:mutable rank]
- Object
- (getKey [this]
- key)
-
- (setKey [this k]
- (set! key k)
- this)
-
- (getVal [this]
- val)
-
- (setVal [this v]
- (set! val v)
- this)
-
- (getLeft [this]
- left)
-
- (setLeft [this l]
- (set! left l)
- this)
-
- (getRight [this]
- right)
-
- (setRight [this r]
- (set! right r)
- this)
-
- (getHeight [this]
- height)
-
- (setHeight [this h]
- (set! height h)
- this)
-
- (getRank [this]
- rank)
-
- (setRank [this r]
- (set! rank r)
- this))
-
-(defn ^:private height [node]
- (if (nil? node)
- 0
- (.-height node)))
-
-(defn ^:private ensure-editable
- ([edit]
- (if-not edit
- (throw (ex-info "Transient used after persistent! call" {}))))
- ([edit node]
- (if (identical? edit (.-edit node))
- node
- (AVLNode. edit
- (.getKey node) (.getVal node)
- (.getLeft node)
- (.getRight node)
- (.getHeight node)
- (.getRank node)))))
-
-(defn ^:private rotate-left [node]
- (let [l (.getLeft node)
- r (.getRight node)
- rl (.getLeft r)
- rr (.getRight r)
- lh (height l)
- rlh (height rl)
- rrh (height rr)
- rnk (.getRank node)
- rnkr (.getRank r)]
- (AVLNode. nil
- (.getKey r) (.getVal r)
- (AVLNode. nil
- (.getKey node) (.getVal node)
- l
- rl
- (inc (max lh rlh))
- rnk)
- rr
- (max (+ lh 2)
- (+ rlh 2)
- (inc rrh))
- (inc (+ rnk rnkr)))))
-
-(defn ^:private rotate-left! [edit node]
- (let [node (ensure-editable edit node)
- l (.getLeft node)
- r (ensure-editable edit (.getRight node))
- rl (.getLeft r)
- rr (.getRight r)
- lh (height l)
- rlh (height rl)
- rrh (height rr)
- rnk (.getRank node)
- rnkr (.getRank r)]
- (.setLeft r node)
- (.setHeight r (max (+ lh 2) (+ rlh 2) (inc rrh)))
- (.setRank r (inc (+ rnk rnkr)))
- (.setRight node rl)
- (.setHeight node (inc (max lh rlh)))
- r))
-
-(defn ^:private rotate-right [node]
- (let [r (.getRight node)
- l (.getLeft node)
- lr (.getRight l)
- ll (.getLeft l)
- rh (height r)
- lrh (height lr)
- llh (height ll)
- rnk (.getRank node)
- rnkl (.getRank l)]
- (AVLNode. nil
- (.getKey l) (.getVal l)
- ll
- (AVLNode. nil
- (.getKey node) (.getVal node)
- lr
- r
- (inc (max rh lrh))
- (dec (- rnk rnkl)))
- (max (+ rh 2)
- (+ lrh 2)
- (inc llh))
- rnkl)))
-
-(defn ^:private rotate-right! [edit node]
- (let [node (ensure-editable edit node)
- r (.getRight node)
- l (ensure-editable edit (.getLeft node))
- lr (.getRight l)
- ll (.getLeft l)
- rh (height r)
- lrh (height lr)
- llh (height ll)
- rnk (.getRank node)
- rnkl (.getRank l)]
- (.setRight l node)
- (.setHeight l (max (+ rh 2) (+ lrh 2) (inc llh)))
- (.setLeft node lr)
- (.setHeight node (inc (max rh lrh)))
- (.setRank node (dec (- rnk rnkl)))
- l))
-
-(defn ^:private lookup [comp node k]
- (if (nil? node)
- nil
- (let [c (comp k (.getKey node))]
- (cond
- (zero? c) node
- (neg? c) (recur comp (.getLeft node) k)
- :else (recur comp (.getRight node) k)))))
-
-(defn ^:private lookup-nearest [comp node test k]
- (let [below? (or (identical? < test) (identical? <= test))
- equal? (or (identical? <= test) (identical? >= test))
- back? (if below? neg? pos?)
- backward (if below?
- #(.getLeft %)
- #(.getRight %))
- forward (if below?
- #(.getRight %)
- #(.getLeft %))]
- (loop [prev nil
- node node]
- (if (nil? node)
- prev
- (let [c (comp k (.getKey node))]
- (cond
- (zero? c) (if equal?
- node
- (recur prev (backward node)))
- (back? c) (recur prev (backward node))
- :else (recur node (forward node))))))))
-
-(defn ^:private select [node rank]
- (if (nil? node)
- nil
- (let [node-rank (.getRank node)]
- (cond
- (== node-rank rank) node
- (< node-rank rank) (recur (.getRight node) (dec (- rank node-rank)))
- :else (recur (.getLeft node) rank)))))
-
-(defn ^:private rank [comp node k]
- (if (nil? node)
- -1
- (let [c (comp k (.getKey node))]
- (cond
- (zero? c) (.getRank node)
- (neg? c) (recur comp (.getLeft node) k)
- :else (let [r (rank comp (.getRight node) k)]
- (if (== -1 r)
- -1
- (inc (+ (.getRank node) r))))))))
-
-(defn ^:private maybe-rebalance [node]
- (let [l (.getLeft node)
- r (.getRight node)
- lh (height l)
- rh (height r)
- b (- lh rh)]
- (cond
- ;; right-heavy
- (< b -1)
- (let [rl (.getLeft r)
- rr (.getRight r)
- rlh (height rl)
- rrh (height rr)]
- (if (== (- rlh rrh) 1)
- ;; left-heavy
- (let [new-right (rotate-right r)]
- (rotate-left (AVLNode. nil
- (.getKey node) (.getVal node)
- (.getLeft node)
- new-right
- (inc (max lh (height new-right)))
- (.getRank node))))
- (rotate-left node)))
-
- ;; left-heavy
- (> b 1)
- (let [ll (.getLeft l)
- lr (.getRight l)
- llh (height ll)
- lrh (height lr)]
- ;; right-heavy
- (if (== (- lrh llh) 1)
- (let [new-left (rotate-left l)]
- (rotate-right (AVLNode. nil
- (.getKey node) (.getVal node)
- new-left
- (.getRight node)
- (inc (max rh (height new-left)))
- (.getRank node))))
- (rotate-right node)))
-
- :else
- node)))
-
-(defn ^:private maybe-rebalance! [edit node]
- (let [l (.getLeft node)
- r (.getRight node)
- lh (height l)
- rh (height r)
- b (- lh rh)]
- (cond
- ;; right-heavy
- (< b -1)
- (let [node (ensure-editable edit node)
- rl (.getLeft r)
- rr (.getRight r)
- rlh (height rl)
- rrh (height rr)]
- (if (== (- rlh rrh) 1)
- ;; left-heavy
- (let [new-right (rotate-right! edit r)]
- (.setRight node new-right)
- (.setHeight node (inc (max lh (height new-right))))
- (rotate-left! edit node))
- (rotate-left! edit node)))
-
- ;; left-heavy
- (> b 1)
- (let [node (ensure-editable edit node)
- ll (.getLeft l)
- lr (.getRight l)
- llh (height ll)
- lrh (height lr)]
- ;; right-heavy
- (if (== (- lrh llh) 1)
- (let [new-left (rotate-left! edit l)]
- (.setLeft node new-left)
- (.setHeight node (inc (max rh (height new-left))))
- (rotate-right! edit node))
- (rotate-right! edit node)))
-
- :else
- node)))
-
-(defn ^:private insert [comp node k v found?]
- (if (nil? node)
- (AVLNode. nil k v nil nil 1 0)
- (let [nk (.getKey node)
- c (comp k nk)]
- (cond
- (zero? c)
- (do
- (set! (.-val found?) true)
- (AVLNode. nil
- k v
- (.getLeft node)
- (.getRight node)
- (.getHeight node)
- (.getRank node)))
-
- (neg? c)
- (let [new-child (insert comp (.getLeft node) k v found?)]
- (maybe-rebalance
- (AVLNode. nil
- nk (.getVal node)
- new-child
- (.getRight node)
- (inc (max (.getHeight new-child)
- (height (.getRight node))))
- (if (.-val found?)
- (.getRank node)
- (inc (.getRank node))))))
-
- :else
- (let [new-child (insert comp (.getRight node) k v found?)]
- (maybe-rebalance
- (AVLNode. nil
- nk (.getVal node)
- (.getLeft node)
- new-child
- (inc (max (.getHeight new-child)
- (height (.getLeft node))))
- (.getRank node))))))))
-
-(defn ^:private insert! [edit comp node k v found?]
- (if (nil? node)
- (AVLNode. edit k v nil nil 1 0)
- (let [node (ensure-editable edit node)
- nk (.getKey node)
- c (comp k nk)]
- (cond
- (zero? c)
- (do
- (set! (.-val found?) true)
- (.setKey node k)
- (.setVal node v)
- node)
-
- (neg? c)
- (let [new-child (insert! edit comp (.getLeft node) k v found?)]
- (.setLeft node new-child)
- (.setHeight node
- (inc (max (.getHeight new-child)
- (height (.getRight node)))))
- (if-not (.-val found?)
- (.setRank node (unchecked-inc-int (.getRank node))))
- (maybe-rebalance! edit node))
-
- :else
- (let [new-child (insert! edit comp (.getRight node) k v found?)]
- (.setRight node new-child)
- (.setHeight node
- (inc (max (.getHeight new-child)
- (height (.getLeft node)))))
- (maybe-rebalance! edit node))))))
-
-(defn ^:private get-rightmost [node]
- (if-let [r (.getRight node)]
- (recur r)
- node))
-
-(defn ^:private get-leftmost [node]
- (if-let [l (.getLeft node)]
- (recur l)
- node))
-
-(defn ^:private delete-rightmost [node]
- (if-let [r (.getRight node)]
- (let [l (.getLeft node)
- new-right (delete-rightmost r)]
- (maybe-rebalance
- (AVLNode. nil
- (.getKey node) (.getVal node)
- l
- new-right
- (inc (max (height l) (height new-right)))
- (.getRank node))))
- (.getLeft node)))
-
-(defn ^:private delete-rightmost! [edit node]
- (if-not (nil? node)
- (let [node (ensure-editable edit node)
- r (.getRight node)]
- (cond
- (nil? r)
- (if-let [l (.getLeft node)]
- (ensure-editable edit l))
-
- (nil? (.getRight r))
- (do
- (.setRight node (.getLeft r))
- (.setHeight node
- (inc (max (height (.getLeft node))
- (height (.getLeft r)))))
- (maybe-rebalance! edit node))
-
- :else
- (let [new-right (delete-rightmost! edit r)]
- (.setRight node new-right)
- (.setHeight node
- (inc (max (height (.getLeft node))
- (height new-right))))
- (maybe-rebalance! edit node))))))
-
-(defn ^:private delete [comp node k found?]
- (if (nil? node)
- nil
- (let [nk (.getKey node)
- c (comp k nk)]
- (cond
- (zero? c)
- (let [l (.getLeft node)
- r (.getRight node)]
- (set! (.-val found?) true)
- (if (and l r)
- (let [p (get-rightmost l)
- l' (delete-rightmost l)]
- (maybe-rebalance
- (AVLNode. nil
- (.getKey p) (.getVal p)
- l'
- r
- (inc (max (height l') (height r)))
- (unchecked-dec-int (.getRank node)))))
- (or l r)))
-
- (neg? c)
- (let [new-child (delete comp (.getLeft node) k found?)]
- (if (identical? new-child (.getLeft node))
- node
- (maybe-rebalance
- (AVLNode. nil
- nk (.getVal node)
- new-child
- (.getRight node)
- (inc (max (height new-child)
- (height (.getRight node))))
- (if (.-val found?)
- (unchecked-dec-int (.getRank node))
- (.getRank node))))))
-
- :else
- (let [new-child (delete comp (.getRight node) k found?)]
- (if (identical? new-child (.getRight node))
- node
- (maybe-rebalance
- (AVLNode. nil
- nk (.getVal node)
- (.getLeft node)
- new-child
- (inc (max (height new-child)
- (height (.getLeft node))))
- (.getRank node)))))))))
-
-(defn ^:private delete! [edit comp node k found?]
- (if (nil? node)
- nil
- (let [nk (.getKey node)
- c (comp k nk)]
- (cond
- (zero? c)
- (let [l (.getLeft node)
- r (.getRight node)]
- (set! (.-val found?) true)
- (cond
- (and l r)
- (let [node (ensure-editable edit node)
- p (get-rightmost l)
- l' (delete-rightmost! edit l)]
- (.setKey node (.getKey p))
- (.setVal node (.getVal p))
- (.setLeft node l')
- (.setHeight node (inc (max (height l') (height r))))
- (.setRank node (unchecked-dec-int (.getRank node)))
- (maybe-rebalance! edit node))
-
- l l
- r r
- :else nil))
-
- (neg? c)
- (let [new-child (delete! edit comp (.getLeft node) k found?)]
- (if (.-val found?)
- (let [node (ensure-editable edit node)]
- (.setLeft node new-child)
- (.setHeight node
- (inc (max (height new-child)
- (height (.getRight node)))))
- (.setRank node (unchecked-dec-int (.getRank node)))
- (maybe-rebalance! edit node))
- node))
-
- :else
- (let [new-child (delete! edit comp (.getRight node) k found?)]
- (if (.-val found?)
- (let [node (ensure-editable edit node)]
- (.setRight node new-child)
- (.setHeight node
- (inc (max (height new-child)
- (height (.getLeft node)))))
- (maybe-rebalance! edit node))
- node))))))
-
-(defn ^:private join [comp left-count left right]
- (cond
- (nil? left) right
- (nil? right) left
- :else
- (let [lh (.getHeight left)
- rh (.getHeight right)]
- (cond
- (== lh rh)
- (let [left-min (get-rightmost left)
- new-left (delete comp left (.getKey left-min) (Box. false))]
- (AVLNode. nil
- (.getKey left-min) (.getVal left-min)
- new-left
- right
- (inc rh)
- (dec left-count)))
-
- (< lh rh)
- (letfn [(step [current lvl]
- (cond
- (zero? lvl)
- (join comp left-count left current)
-
- (nil? (.getLeft current))
- (AVLNode. nil
- (.getKey current) (.getVal current)
- left
- (.getRight current)
- 2
- left-count)
-
- :else
- (let [new-child (step (.getLeft current) (dec lvl))
- current-r (.getRight current)]
- (maybe-rebalance
- (AVLNode. nil
- (.getKey current) (.getVal current)
- new-child
- current-r
- (inc (max (.getHeight new-child)
- (if current-r
- (.getHeight current-r)
- 0)))
- (+ left-count (.getRank current)))))))]
- (step right (- rh lh)))
-
- :else
- (letfn [(step [current cnt lvl]
- (cond
- (zero? lvl)
- (join comp cnt current right)
-
- (nil? (.getRight current))
- (AVLNode. nil
- (.getKey current) (.getVal current)
- (.getLeft current)
- right
- 2
- (.getRank current))
-
- :else
- (let [new-child (step (.getRight current)
- (dec (- cnt (.getRank current)))
- (dec lvl))
- current-l (.getLeft current)]
- (maybe-rebalance
- (AVLNode. nil
- (.getKey current) (.getVal current)
- current-l
- new-child
- (inc (max (.getHeight new-child)
- (if current-l
- (.getHeight current-l)
- 0)))
- (.getRank current))))))]
- (step left left-count (- lh rh)))))))
-
-(defn ^:private split [comp node k]
- (letfn [(step [node]
- (if (nil? node)
- [nil nil nil]
- (let [c (comp k (.getKey node))]
- (cond
- (zero? c)
- [(.getLeft node)
- (MapEntry. (.getKey node) (.getVal node) nil)
- (.getRight node)]
-
- (neg? c)
- (let [[l e r] (step (.getLeft node))]
- [l
- e
- (join comp
- (- (.getRank node)
- (cond
- e
- (unchecked-inc-int
- (rank comp
- (.getLeft node)
- (key e)))
- r
- (rank comp
- (.getLeft node)
- (.getKey (get-leftmost r)))
- :else
- (.getRank node)))
- r
- (insert comp
- (.getRight node)
- (.getKey node)
- (.getVal node)
- (Box. false)))])
-
- :else
- (let [[l e r] (step (.getRight node))]
- [(join comp
- (unchecked-inc-int (.getRank node))
- (insert comp
- (.getLeft node)
- (.getKey node)
- (.getVal node)
- (Box. false))
- l)
- e
- r])))))]
- (step node)))
-
-(defn ^:private range [comp node low high]
- (let [[_ low-e r] (split comp node low)
- [l high-e _] (split comp r high)]
- (cond-> l
- low-e (as-> node
- (insert comp node
- (key low-e) (val low-e)
- (Box. false)))
- high-e (as-> node
- (insert comp node
- (key high-e) (val high-e)
- (Box. false))))))
-
-(defn ^:private seq-push [node stack ascending?]
- (loop [node node stack stack]
- (if (nil? node)
- stack
- (recur (if ascending? (.-left node) (.-right node))
- (conj stack node)))))
-
-(declare ->AVLMapSeq)
-
-(defn ^:private create-seq [node ascending? cnt]
- (->AVLMapSeq nil (seq-push node nil ascending?) ascending? cnt nil))
-
-(defn ^:private avl-map-kv-reduce [node f init]
- (let [init (if (nil? (.getLeft node))
- init
- (avl-map-kv-reduce (.getLeft node) f init))]
- (if (reduced? init)
- init
- (let [init (f init (.getKey node) (.getVal node))]
- (if (reduced? init)
- init
- (if (nil? (.getRight node))
- init
- (recur (.getRight node) f init)))))))
-
-(defn ^:private avl-map-reduce [node f init]
- (let [init (if (nil? (.getLeft node))
- init
- (avl-map-reduce (.getLeft node) f init))]
- (if (reduced? init)
- init
- (let [init (f init (MapEntry. (.getKey node) (.getVal node) nil))]
- (if (reduced? init)
- init
- (if (nil? (.getRight node))
- init
- (recur (.getRight node) f init)))))))
-
-(defn ^:private avl-map-reduce-skip [node f init skip-node]
- (let [init (if (nil? (.getLeft node))
- init
- (avl-map-reduce-skip (.getLeft node) f init skip-node))]
- (if (reduced? init)
- init
- (if (identical? skip-node node)
- (if (nil? (.getRight node))
- init
- (avl-map-reduce (.getRight node) f init))
- (let [init (f init (MapEntry. (.getKey node) (.getVal node) nil))]
- (if (reduced? init)
- init
- (if (nil? (.getRight node))
- init
- (recur (.getRight node) f init skip-node))))))))
-
-(defn ^:private avl-set-reduce [node f init]
- (let [init (if (nil? (.getLeft node))
- init
- (avl-set-reduce (.getLeft node) f init))]
- (if (reduced? init)
- init
- (let [init (f init (.getKey node))]
- (if (reduced? init)
- init
- (if (nil? (.getRight node))
- init
- (recur (.getRight node) f init)))))))
-
-(defn ^:private avl-set-reduce-skip [node f init skip-node]
- (let [init (if (nil? (.getLeft node))
- init
- (avl-set-reduce-skip (.getLeft node) f init skip-node))]
- (if (reduced? init)
- init
- (if (identical? skip-node node)
- (if (nil? (.getRight node))
- init
- (avl-set-reduce (.getRight node) f init))
- (let [init (f init (.getKey node))]
- (if (reduced? init)
- init
- (if (nil? (.getRight node))
- init
- (avl-set-reduce (.getRight node) f init))))))))
-
-(deftype AVLMapSeq [_meta stack ascending? cnt ^:mutable _hash]
- Object
- (toString [this]
- (pr-str* this))
-
- IHash
- (-hash [this]
- (caching-hash this hash-coll _hash))
-
- ISeqable
- (-seq [this]
- this)
-
- ISequential
- ISeq
- (-first [this]
- (let [node (peek stack)]
- (MapEntry. (.-key node) (.-val node) nil)))
-
- (-rest [this]
- (let [node (first stack)
- next-stack (seq-push (if ascending? (.-right node) (.-left node))
- (next stack)
- ascending?)]
- (if (nil? next-stack)
- ()
- (AVLMapSeq. nil next-stack ascending? (dec cnt) nil))))
-
- INext
- (-next [this]
- (-seq (-rest this)))
-
- ICounted
- (-count [this]
- (if (neg? cnt)
- (inc (-count (-next this)))
- cnt))
-
- ICollection
- (-conj [this x]
- (cons x this))
-
- IEquiv
- (-equiv [this that]
- (equiv-sequential this that))
-
- IEmptyableCollection
- (-empty [this]
- (with-meta () _meta))
-
- IMeta
- (-meta [this]
- _meta)
-
- IWithMeta
- (-with-meta [this meta]
- (AVLMapSeq. meta stack ascending? cnt _hash))
-
- IReduce
- (-reduce [this f]
- (seq-reduce f this))
-
- (-reduce [this f start]
- (seq-reduce f start this)))
-
-(declare ->AVLTransientMap)
-
-(deftype AVLMap [comp tree cnt _meta ^:mutable _hash]
- Object
- (toString [this]
- (pr-str* this))
-
- (getTree [this]
- tree)
-
- (nearest [this test k]
- (if-let [node (lookup-nearest comp tree test k)]
- (MapEntry. (.getKey node) (.getVal node) nil)))
-
- IHash
- (-hash [this]
- (caching-hash this hash-unordered-coll _hash))
-
- IMeta
- (-meta [this]
- _meta)
-
- IWithMeta
- (-with-meta [this meta]
- (AVLMap. comp tree cnt meta _hash))
-
- ICounted
- (-count [this]
- cnt)
-
- IIndexed
- (-nth [this i]
- (if-let [n (select tree i)]
- (MapEntry. (.getKey n) (.getVal n) nil)
- (throw (ex-info "nth index out of bounds in AVL tree" {}))))
-
- (-nth [this i not-found]
- (if-let [n (select tree i)]
- (MapEntry. (.getKey n) (.getVal n) nil)
- not-found))
-
- ICollection
- (-conj [this entry]
- (if (vector? entry)
- (assoc this (-nth entry 0) (-nth entry 1))
- (reduce -conj this entry)))
-
- IEmptyableCollection
- (-empty [this]
- (AVLMap. comp nil 0 _meta 0))
-
- IEquiv
- (-equiv [this that]
- (equiv-map this that))
-
- IKVReduce
- (-kv-reduce [this f init]
- (if (nil? tree)
- init
- (let [init (avl-map-kv-reduce tree f init)]
- (if (reduced? init)
- @init
- init))))
-
- IReduce
- (-reduce [this f]
- (case cnt
- 0 (f)
- 1 (MapEntry. (.getKey tree) (.getVal tree) nil)
- (let [n0 (select tree 0)
- init (avl-map-reduce-skip tree f (MapEntry. (.getKey n0) (.getVal n0) nil) n0)]
- (if (reduced? init)
- (-deref init)
- init))))
-
- (-reduce [this f init]
- (if (nil? tree)
- init
- (let [init (avl-map-reduce tree f init)]
- (if (reduced? init)
- (-deref init)
- init))))
-
- IFn
- (-invoke [this k]
- (-lookup this k))
-
- (-invoke [this k not-found]
- (-lookup this k not-found))
-
- ISeqable
- (-seq [this]
- (if (pos? cnt)
- (create-seq tree true cnt)))
-
- IReversible
- (-rseq [this]
- (if (pos? cnt)
- (create-seq tree false cnt)))
-
- ILookup
- (-lookup [this k]
- (-lookup this k nil))
-
- (-lookup [this k not-found]
- (let [n (lookup comp tree k)]
- (if-not (nil? n)
- (.-val n)
- not-found)))
-
- IAssociative
- (-assoc [this k v]
- (let [found? (Box. false)
- new-tree (insert comp tree k v found?)]
- (AVLMap. comp
- new-tree
- (if (.-val found?) cnt (inc cnt))
- _meta nil)))
-
- (-contains-key? [this k]
- (not (nil? (lookup comp tree k))))
-
- IMap
- (-dissoc [this k]
- (let [found? (Box. false)
- new-tree (delete comp tree k found?)]
- (if (.-val found?)
- (AVLMap. comp
- new-tree
- (dec cnt)
- _meta nil)
- this)))
-
- ISorted
- (-sorted-seq [this ascending?]
- (if (pos? cnt)
- (create-seq tree ascending? cnt)))
-
- (-sorted-seq-from [this k ascending?]
- (if (pos? cnt)
- (loop [stack nil t tree]
- (if-not (nil? t)
- (let [c (comp k (.-key t))]
- (cond
- (zero? c) (AVLMapSeq. nil (conj stack t) ascending? -1 nil)
- ascending? (if (neg? c)
- (recur (conj stack t) (.-left t))
- (recur stack (.-right t)))
- :else (if (pos? c)
- (recur (conj stack t) (.-right t))
- (recur stack (.-left t)))))
- (if-not (nil? stack)
- (AVLMapSeq. nil stack ascending? -1 nil))))))
-
- (-entry-key [this entry]
- (key entry))
-
- (-comparator [this]
- comp)
-
- IEditableCollection
- (-as-transient [this]
- (->AVLTransientMap (js-obj) comp tree cnt)))
-
-(deftype AVLTransientMap [^:mutable edit comp ^:mutable tree ^:mutable cnt]
- ICounted
- (-count [this]
- cnt)
-
- ILookup
- (-lookup [this k]
- (-lookup this k nil))
-
- (-lookup [this k not-found]
- (let [n (lookup comp tree k)]
- (if-not (nil? n)
- (.getVal n)
- not-found)))
-
- IFn
- (-invoke [this k]
- (-lookup this k))
-
- (-invoke [this k not-found]
- (-lookup this k not-found))
-
- ITransientCollection
- (-conj! [this entry]
- (if (vector? entry)
- (assoc! this (nth entry 0) (nth entry 1))
- (reduce conj! this entry)))
-
- (-persistent! [this]
- (ensure-editable edit)
- (set! edit nil)
- (AVLMap. comp tree cnt nil nil))
-
- ITransientAssociative
- (-assoc! [this k v]
- (ensure-editable edit)
- (let [found? (Box. false)
- new-tree (insert! edit comp tree k v found?)]
- (set! tree new-tree)
- (if-not (.-val found?)
- (set! cnt (inc cnt)))
- this))
-
- ITransientMap
- (-dissoc! [this k]
- (ensure-editable edit)
- (let [found? (Box. false)
- new-tree (delete! edit comp tree k found?)]
- (when (.-val found?)
- (set! tree new-tree)
- (set! cnt (dec cnt)))
- this)))
-
-(declare ->AVLTransientSet)
-
-(deftype AVLSet [_meta avl-map ^:mutable _hash]
- Object
- (toString [this]
- (pr-str* this))
-
- (getTree [this]
- (.-tree avl-map))
-
- (nearest [this test k]
- (if-let [node (lookup-nearest (.-comp avl-map) (.getTree avl-map) test k)]
- (.getKey node)))
-
- IHash
- (-hash [this]
- (caching-hash this hash-unordered-coll _hash))
-
- IMeta
- (-meta [this]
- _meta)
-
- IWithMeta
- (-with-meta [this meta]
- (AVLSet. meta avl-map _hash))
-
- ICounted
- (-count [this]
- (-count avl-map))
-
- IIndexed
- (-nth [this i]
- (if-let [n (select (.-tree avl-map) i)]
- (.getVal n)
- (throw (ex-info "nth index out of bounds in AVL tree" {}))))
-
- (-nth [this i not-found]
- (if-let [n (select (.-tree avl-map) i)]
- (.getVal n)
- not-found))
-
- ICollection
- (-conj [this x]
- (AVLSet. _meta (assoc avl-map x x) nil))
-
- IEmptyableCollection
- (-empty [this]
- (AVLSet. _meta (empty avl-map) 0))
-
- IEquiv
- (-equiv [this that]
- (and
- (set? that)
- (== (count this) (count that))
- (every? #(contains? this %) that)))
-
- ISeqable
- (-seq [this]
- (keys avl-map))
-
- ISorted
- (-sorted-seq [this ascending?]
- (keys (-sorted-seq avl-map ascending?)))
-
- (-sorted-seq-from [this k ascending?]
- (keys (-sorted-seq-from avl-map k ascending?)))
-
- (-entry-key [this entry]
- entry)
-
- (-comparator [this]
- (-comparator avl-map))
-
- IReversible
- (-rseq [this]
- (map key (rseq avl-map)))
-
- ILookup
- (-lookup [this v]
- (-lookup this v nil))
-
- (-lookup [this v not-found]
- (let [n (lookup (.-comp avl-map) (.-tree avl-map) v)]
- (if-not (nil? n)
- (.-key n)
- not-found)))
-
- ISet
- (-disjoin [this v]
- (AVLSet. _meta (dissoc avl-map v) nil))
-
- IReduce
- (-reduce [this f]
- (case (-count avl-map)
- 0 (f)
- 1 (.getKey (.getTree avl-map))
- (let [tree (.getTree avl-map)
- n0 (select tree 0)
- init (avl-set-reduce-skip tree f (.getKey n0) n0)]
- (if (reduced? init)
- (-deref init)
- init))))
-
- (-reduce [this f init]
- (let [tree (.getTree avl-map)]
- (if (nil? tree)
- init
- (let [init (avl-set-reduce tree f init)]
- (if (reduced? init)
- (-deref init)
- init)))))
- IFn
- (-invoke [this k]
- (-lookup this k))
-
- (-invoke [this k not-found]
- (-lookup this k not-found))
-
- IEditableCollection
- (-as-transient [this]
- (->AVLTransientSet (-as-transient avl-map))))
-
-(deftype AVLTransientSet [^:mutable transient-avl-map]
- ITransientCollection
- (-conj! [this k]
- (set! transient-avl-map (-assoc! transient-avl-map k k))
- this)
-
- (-persistent! [this]
- (if (nil? (.-edit transient-avl-map))
- (throw (ex-info "persistent! used twice" {}))
- (AVLSet. nil (-persistent! transient-avl-map) nil)))
-
- ITransientSet
- (-disjoin! [this k]
- (set! transient-avl-map (-dissoc! transient-avl-map k))
- this)
-
- ICounted
- (-count [this]
- (-count transient-avl-map))
-
- ILookup
- (-lookup [this k]
- (-lookup this k nil))
-
- (-lookup [this k not-found]
- (if (identical? (-lookup transient-avl-map k lookup-sentinel)
- lookup-sentinel)
- not-found
- k))
-
- IFn
- (-invoke [this k]
- (-lookup transient-avl-map k))
-
- (-invoke [this k not-found]
- (-lookup transient-avl-map k not-found)))
-
-(def ^:private empty-map (AVLMap. compare nil 0 nil 0))
-
-(def ^:private empty-set (AVLSet. nil empty-map 0))
-
-(extend-protocol IPrintWithWriter
- AVLMapSeq
- (-pr-writer [this writer opts]
- (pr-sequential-writer writer pr-writer "(" " " ")" opts this))
-
- AVLMap
- (-pr-writer [this writer opts]
- (letfn [(pr-pair [keyval]
- (pr-sequential-writer writer pr-writer "" " " "" opts keyval))]
- (pr-sequential-writer writer pr-pair "{" ", " "}" opts this)))
-
- AVLSet
- (-pr-writer [this writer opts]
- (pr-sequential-writer writer pr-writer "#{" " " "}" opts this)))
-
-(defn sorted-map
- "keyval => key val
- Returns a new AVL map with supplied mappings."
- [& keyvals]
- (loop [in (seq keyvals) out (transient empty-map)]
- (if in
- (if-let [nin (next in)]
- (recur (next nin) (assoc! out (first in) (first nin)))
- (throw (ex-info
- (str "sorted-map: no value supplied for key: " (first in))
- {})))
- (persistent! out))))
-
-(defn sorted-map-by
- "keyval => key val
- Returns a new sorted map with supplied mappings, using the supplied
- comparator."
- [comparator & keyvals]
- (loop [in (seq keyvals)
- out (AVLTransientMap. (js-obj) (fn->comparator comparator) nil 0)]
- (if in
- (if-let [nin (next in)]
- (recur (next nin) (assoc! out (first in) (first nin)))
- (throw (ex-info
- (str "sorted-map-by: no value supplied for key: " (first in))
- {})))
- (persistent! out))))
-
-(defn sorted-set
- "Returns a new sorted set with supplied keys."
- [& keys]
- (persistent! (reduce conj! (transient empty-set) keys)))
-
-(defn sorted-set-by
- "Returns a new sorted set with supplied keys, using the supplied comparator."
- [comparator & keys]
- (persistent!
- (reduce conj!
- (AVLTransientSet.
- (-as-transient (sorted-map-by (fn->comparator comparator))))
- keys)))
-
-(defn rank-of
- "Returns the rank of x in coll or -1 if not present."
- [coll x]
- (rank (-comparator coll) (.getTree coll) x))
-
-(defn nearest
- "(alpha)
-
- Equivalent to, but more efficient than, (first (subseq* coll test x)),
- where subseq* is clojure.core/subseq for test in #{>, >=} and
- clojure.core/rsubseq for test in #{<, <=}."
- [coll test x]
- (.nearest coll test x))
-
-(defn split-key
- "(alpha)
-
- Returns [left e? right], where left and right are collections of
- the same type as coll and containing, respectively, the keys below
- and above k in the ordering determined by coll's comparator, while
- e? is the entry at key k for maps, the stored copy of the key k for
- sets, nil if coll does not contain k."
- [k coll]
- (let [comp (-comparator coll)
- [left e? right] (split comp (.getTree coll) k)
- keyfn (if (map? coll) key identity)
- wrap (if (map? coll)
- (fn wrap-map [tree cnt]
- (AVLMap. comp tree cnt nil -1))
- (fn wrap-set [tree cnt]
- (AVLSet. nil (AVLMap. comp tree cnt nil -1) -1)))]
- [(wrap left
- (if (or e? right)
- (rank-of coll (keyfn (nearest coll >= k)))
- (count coll)))
- (if (and e? (set? coll))
- (key e?)
- e?)
- (wrap right
- (if right
- (- (count coll) (rank-of coll (keyfn (nearest coll > k))))
- 0))]))
-
-(defn split-at
- "(alpha)
-
- Equivalent to, but more efficient than,
- [(into (empty coll) (take n coll))
- (into (empty coll) (drop n coll))]."
- [n coll]
- (if (>= n (count coll))
- [coll (empty coll)]
- (let [k (nth coll n)
- k (if (map? coll) (key k) k)
- [l e r] (split-key k coll)]
- [l (conj r e)])))
-
-(defn subrange
- "(alpha)
-
- Returns an AVL collection comprising the entries of coll between
- start and end (in the sense determined by coll's comparator) in
- logarithmic time. Whether the endpoints are themselves included in
- the returned collection depends on the provided tests; start-test
- must be either > or >=, end-test must be either < or <=.
-
- When passed a single test and limit, subrange infers the other end
- of the range from the test: > / >= mean to include items up to the
- end of coll, < / <= mean to include items taken from the beginning
- of coll.
-
- (subrange coll >= start <= end) is equivalent to, but more efficient
- than, (into (empty coll) (subseq coll >= start <= end)."
- ([coll test limit]
- (if (zero? (count coll))
- coll
- (let [comp (-comparator coll)]
- (if (#{> >=} test)
- (let [n (select (.getTree coll) (dec (count coll)))
- k (.getKey n)]
- (if (pos? (comp limit k))
- (empty coll)
- (subrange coll
- test limit
- <= k)))
- (let [n (select (.getTree coll) 0)
- k (.getKey n)]
- (if (neg? (comp limit k))
- (empty coll)
- (subrange coll
- >= k
- test limit)))))))
- ([coll start-test start end-test end]
- (if (zero? (count coll))
- coll
- (let [comp (-comparator coll)]
- (if (pos? (comp start end))
- (throw (ex-info "start greater than end in subrange" {}))
- (let [input-tree (.getTree coll)
- l (lookup-nearest comp input-tree start-test start)
- h (lookup-nearest comp input-tree end-test end)]
- (if (and l h)
- (let [lk (.getKey l)
- hk (.getKey h)]
- (if (neg? (comp hk lk))
- (empty coll)
- (let [tree (range comp (.getTree coll) lk hk)
- cnt (inc (- (rank-of coll hk)
- (rank-of coll lk)))
- m (AVLMap. comp tree cnt nil -1)]
- (if (map? coll)
- m
- (AVLSet. nil m -1)))))
- (empty coll))))))))
diff --git a/src/main/clojure/clojure/data/avl.clj b/src/main/clojure/clojure/data/avl.clj
deleted file mode 100644
index 0a8d9cd..0000000
--- a/src/main/clojure/clojure/data/avl.clj
+++ /dev/null
@@ -1,2070 +0,0 @@
-; Copyright (c) Rich Hickey and contributors. All rights reserved.
-; The use and distribution terms for this software are covered by the
-; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
-; which can be found in the file epl-v10.html at the root of this distribution.
-; By using this software in any fashion, you are agreeing to be bound by
-; the terms of this license.
-; You must not remove this notice, or any other, from this software.
-
-(ns clojure.data.avl
-
- "An implementation of persistent sorted maps and sets based on AVL
- trees which can be used as drop-in replacements for Clojure's
- built-in sorted maps and sets based on red-black trees. Apart from
- the standard sorted collection API, the provided map and set types
- support the transients API and several additional logarithmic time
- operations: rank queries via clojure.core/nth (select element by
- rank) and clojure.data.avl/rank-of (discover rank of element),
- \"nearest key\" lookups via clojure.data.avl/nearest, splits by key
- and index via clojure.data.avl/split-key and
- clojure.data.avl/split-at, respectively, and subsets/submaps using
- clojure.data.avl/subrange."
-
- {:author "Michał Marczyk"}
-
- (:refer-clojure :exclude [sorted-map sorted-map-by sorted-set sorted-set-by
- range split-at])
- (:import (clojure.lang RT Util APersistentMap APersistentSet
- IPersistentMap IPersistentSet IPersistentStack
- Box MapEntry SeqIterator)
- (java.util Comparator Collections ArrayList)
- (java.util.concurrent.atomic AtomicReference)))
-
-(set! *warn-on-reflection* true)
-(set! *unchecked-math* :warn-on-boxed)
-
-(defn ^:private throw-unsupported []
- (throw (UnsupportedOperationException.)))
-
-(defmacro ^:private caching-hash [coll hash-fn hash-key]
- `(let [h# ~hash-key]
- (if-not (== h# (int -1))
- h#
- (let [h# (~hash-fn ~coll)]
- (set! ~hash-key (int h#))
- h#))))
-
-(defmacro ^:private compile-if [test then else]
- (if (eval test)
- then
- else))
-
-(def ^:private ^:const empty-set-hashcode (.hashCode #{}))
-(def ^:private ^:const empty-set-hasheq (hash #{}))
-(def ^:private ^:const empty-map-hashcode (.hashCode {}))
-(def ^:private ^:const empty-map-hasheq (hash {}))
-
-(defn ^:private hash-imap
- [^IPersistentMap m]
- (APersistentMap/mapHash m))
-
-(defn ^:private hasheq-imap
- [^IPersistentMap m]
- (compile-if (resolve 'clojure.core/hash-unordered-coll)
- (hash-unordered-coll m)
- (APersistentMap/mapHasheq m)))
-
-(defn ^:private hash-iset [^IPersistentSet s]
- ;; a la clojure.lang.APersistentSet
- (loop [h (int 0) s (seq s)]
- (if s
- (let [e (first s)]
- (recur (unchecked-add-int h (if (nil? e) 0 (.hashCode ^Object e)))
- (next s)))
- h)))
-
-(defn ^:private hasheq-iset [^IPersistentSet s]
- (compile-if (resolve 'clojure.core/hash-unordered-coll)
- (hash-unordered-coll s)
- (loop [h (int 0) s (seq s)]
- (if s
- (recur (unchecked-add-int h (Util/hasheq (first s)))
- (next s))
- h))))
-
-(defn ^:private hash-seq
- [s]
- (loop [h (int 1) s (seq s)]
- (if s
- (recur (unchecked-add-int (unchecked-multiply-int (int 31) h)
- (if (nil? (first s))
- (int 0)
- (.hashCode ^Object (first s))))
- (next s))
- h)))
-
-(defn ^:private hasheq-seq
- [s]
- (compile-if (resolve 'clojure.core/hash-ordered-coll)
- (hash-ordered-coll s)
- (loop [h (int 1) s (seq s)]
- (if s
- (recur (unchecked-add-int (unchecked-multiply-int (int 31) h)
- (Util/hasheq (first s)))
- (next s))
- h))))
-
-(defn ^:private equiv-sequential
- "Assumes x is sequential. Returns true if x equals y, otherwise
- returns false."
- [x y]
- (boolean
- (when (or (sequential? y) (instance? java.util.List y))
- (loop [xs (seq x) ys (seq y)]
- (cond (nil? xs) (nil? ys)
- (nil? ys) false
- (= (first xs) (first ys)) (recur (next xs) (next ys))
- :else false)))))
-
-(def ^:private never-equiv (Object.))
-
-(defn ^:private equiv-map
- "Assumes x is a map. Returns true if y equals x, otherwise returns
- false."
- [^clojure.lang.IPersistentMap x y]
- (if-not (instance? java.util.Map y)
- false
- (if (and (instance? clojure.lang.IPersistentMap y)
- (not (instance? clojure.lang.MapEquivalence y)))
- false
- (let [m ^java.util.Map y]
- (if-not (== (.size ^java.util.Map x) (.size m))
- false
- (reduce-kv (fn [t k v]
- (if-not (.containsKey m k)
- (reduced false)
- (if-not (Util/equiv v (.get m k))
- (reduced false)
- t)))
- true
- x))))))
-
-(gen-interface
- :name clojure.data.avl.IAVLNode
- :methods
- [[getKey [] Object]
- [setKey [Object] clojure.data.avl.IAVLNode]
- [getVal [] Object]
- [setVal [Object] clojure.data.avl.IAVLNode]
- [getLeft [] clojure.data.avl.IAVLNode]
- [setLeft [clojure.data.avl.IAVLNode] clojure.data.avl.IAVLNode]
- [getRight [] clojure.data.avl.IAVLNode]
- [setRight [clojure.data.avl.IAVLNode] clojure.data.avl.IAVLNode]
- [getHeight [] int]
- [setHeight [int] clojure.data.avl.IAVLNode]
- [getRank [] int]
- [setRank [int] clojure.data.avl.IAVLNode]])
-
-(gen-interface
- :name clojure.data.avl.IAVLTree
- :methods [[getTree [] clojure.data.avl.IAVLNode]])
-
-(defmacro ^:private define-i-transient-associative-2-impl []
- (let [ita2-exists?
- (try (Class/forName "clojure.lang.ITransientAssociative2")
- true
- (catch ClassNotFoundException _
- false))]
- `(gen-interface
- :name ~'clojure.data.avl.ITransientAssociative2Impl
- ~@(if ita2-exists?
- '[:extends [clojure.lang.ITransientAssociative2]])
- :methods
- ~'[[containsKey [Object] boolean]
- [entryAt [Object] clojure.lang.IMapEntry]])))
-
-(define-i-transient-associative-2-impl)
-
-(import (clojure.data.avl IAVLNode IAVLTree ITransientAssociative2Impl))
-
-(definterface INavigableTree
- (nearest [test k]))
-
-(deftype AVLNode [^AtomicReference edit
- ^:unsynchronized-mutable key
- ^:unsynchronized-mutable val
- ^:unsynchronized-mutable ^IAVLNode left
- ^:unsynchronized-mutable ^IAVLNode right
- ^:unsynchronized-mutable ^int height
- ^:unsynchronized-mutable ^int rank]
- IAVLNode
- (getKey [this]
- key)
-
- (setKey [this k]
- (set! key k)
- this)
-
- (getVal [this]
- val)
-
- (setVal [this v]
- (set! val v)
- this)
-
- (getLeft [this]
- left)
-
- (setLeft [this l]
- (set! left l)
- this)
-
- (getRight [this]
- right)
-
- (setRight [this r]
- (set! right r)
- this)
-
- (getHeight [this]
- height)
-
- (setHeight [this h]
- (set! height h)
- this)
-
- (getRank [this]
- rank)
-
- (setRank [this r]
- (set! rank r)
- this)
-
- Object
- (equals [this that]
- (cond
- (identical? this that) true
-
- (or (instance? clojure.lang.IPersistentVector that)
- (instance? java.util.RandomAccess that))
- (and (== 2 (count that))
- (.equals key (nth that 0))
- (.equals val (nth that 1)))
-
- (or (instance? clojure.lang.Sequential that)
- (instance? java.util.List that))
- (and (== 2 (count that))
- (.equals key (first that))
- (.equals val (second that)))
-
- :else false))
-
- (hashCode [this]
- (-> (int 31)
- (unchecked-add-int (Util/hash key))
- (unchecked-multiply-int (int 31))
- (unchecked-add-int (Util/hash val))))
-
- (toString [this]
- (pr-str this))
-
- clojure.lang.IHashEq
- (hasheq [this]
- (compile-if (resolve 'clojure.core/hash-ordered-coll)
- (hash-ordered-coll this)
- (-> (int 31)
- (unchecked-add-int (Util/hasheq key))
- (unchecked-multiply-int (int 31))
- (unchecked-add-int (Util/hasheq val)))))
-
- clojure.lang.Indexed
- (nth [this n]
- (case n
- 0 key
- 1 val
- (throw
- (IndexOutOfBoundsException. "nth index out of bounds in AVLNode"))))
-
- (nth [this n not-found]
- (case n
- 0 key
- 1 val
- not-found))
-
- clojure.lang.Counted
- (count [this]
- 2)
-
- clojure.lang.IMeta
- (meta [this]
- nil)
-
- clojure.lang.IObj
- (withMeta [this m]
- (with-meta [key val] m))
-
- clojure.lang.IPersistentCollection
- (cons [this x]
- [key val x])
-
- (empty [this]
- [])
-
- (equiv [this that]
- (cond
- (or (instance? clojure.lang.IPersistentVector that)
- (instance? java.util.RandomAccess that))
- (and (== 2 (count that))
- (= key (nth that 0))
- (= val (nth that 1)))
-
- (or (instance? clojure.lang.Sequential that)
- (instance? java.util.List that))
- (and (== 2 (count that))
- (= key (first that))
- (= val (second that)))
-
- :else false))
-
- clojure.lang.IPersistentStack
- (peek [this]
- val)
-
- (pop [this]
- [key])
-
- clojure.lang.IPersistentVector
- (assocN [this i x]
- (case i
- 0 [x val]
- 1 [key x]
- (throw
- (IndexOutOfBoundsException. "assocN index out of bounds in AVLNode"))))
-
- (length [this]
- 2)
-
- clojure.lang.Reversible
- (rseq [this]
- (list val key))
-
- clojure.lang.Associative
- (assoc [this k v]
- (if (Util/isInteger k)
- (.assocN this k v)
- (throw (IllegalArgumentException. "key must be integer"))))
-
- (containsKey [this k]
- (if (Util/isInteger k)
- (case (int k)
- 0 true
- 1 true
- false)
- false))
-
- (entryAt [this k]
- (if (Util/isInteger k)
- (case (int k)
- 0 (MapEntry. 0 key)
- 1 (MapEntry. 1 val)
- nil)))
-
- clojure.lang.ILookup
- (valAt [this k not-found]
- (if (Util/isInteger k)
- (case (int k)
- 0 key
- 1 val
- not-found)
- not-found))
-
- (valAt [this k]
- (.valAt this k nil))
-
- clojure.lang.IFn
- (invoke [this k]
- (if (Util/isInteger k)
- (case (int k)
- 0 key
- 1 val
- (throw
- (IndexOutOfBoundsException.
- "invoke index out of bounds in AVLNode")))
- (throw (IllegalArgumentException. "key must be integer"))))
-
- (applyTo [this args]
- (let [n (RT/boundedLength args 1)]
- (case n
- 0 (throw (clojure.lang.ArityException.
- n (.. this (getClass) (getSimpleName))))
- 1 (.invoke this (first args))
- 2 (throw (clojure.lang.ArityException.
- n (.. this (getClass) (getSimpleName)))))))
-
- clojure.lang.Seqable
- (seq [this]
- (list key val))
-
- clojure.lang.Sequential
-
- clojure.lang.IEditableCollection
- (asTransient [this]
- (transient [key val]))
-
- clojure.lang.IMapEntry
- (key [this]
- key)
-
- (val [this]
- val)
-
- java.util.Map$Entry
- (getValue [this]
- val)
-
- (setValue [this x]
- (throw-unsupported))
-
- java.io.Serializable
-
- java.lang.Comparable
- (compareTo [this that]
- (if (identical? this that)
- 0
- (let [^clojure.lang.IPersistentVector v
- (cast clojure.lang.IPersistentVector that)
- vcnt (.count v)]
- (cond
- (< 2 vcnt) -1
- (> 2 vcnt) 1
- :else
- (let [comp (Util/compare key (.nth v 0))]
- (if (zero? comp)
- (Util/compare val (.nth v 1))
- comp))))))
-
- java.lang.Iterable
- (iterator [this]
- (.iterator ^java.lang.Iterable (list key val)))
-
- java.util.RandomAccess
- java.util.List
- (get [this i]
- (.nth this i))
-
- (indexOf [this x]
- (condp = x
- key 0
- val 1
- -1))
-
- (lastIndexOf [this x]
- (condp = x
- val 1
- key 0
- -1))
-
- (listIterator [this]
- (.listIterator this 0))
-
- (listIterator [this i]
- (.listIterator (doto (java.util.ArrayList.)
- (.add key)
- (.add val))
- i))
-
- (subList [this a z]
- (if (<= 0 a z 2)
- (cond
- (== a z) []
- (and (== a 0) (== z 2)) this
- :else (case a
- 0 [key]
- 1 [val]))
- (throw
- (IndexOutOfBoundsException. "subList index out of bounds in AVLNode"))))
-
- java.util.Collection
- (contains [this x]
- (or (= key x) (= val x)))
-
- (containsAll [this c]
- (every? #(.contains this %) c))
-
- (isEmpty [this]
- false)
-
- (toArray [this]
- (into-array Object this))
-
- (^objects toArray [this ^objects arr]
- (if (>= (count arr) 2)
- (doto arr
- (aset 0 key)
- (aset 1 val))
- (into-array Object this)))
-
- (size [this]
- 2)
-
- (add [this x] (throw-unsupported))
- (^boolean remove [this x] (throw-unsupported))
- (addAll [this c] (throw-unsupported))
- (clear [this] (throw-unsupported))
- (retainAll [this c] (throw-unsupported))
- (removeAll [this c] (throw-unsupported))
- (set [this i e] (throw-unsupported))
- (remove [this ^int i] (throw-unsupported))
- (add [this i e] (throw-unsupported)))
-
-(defn ^:private ensure-editable
- (^IAVLNode [^AtomicReference edit]
- (let [owner (.get edit)]
- (cond
- (identical? owner (Thread/currentThread))
- true
-
- (nil? owner)
- (throw (IllegalAccessError. "Transient used after persistent! call"))
-
- :else
- (throw (IllegalAccessError. "Transient used by non-owner thread")))))
- (^IAVLNode [^AtomicReference edit ^AVLNode node]
- (if (identical? edit (.-edit node))
- node
- (AVLNode. edit
- (.getKey node) (.getVal node)
- (.getLeft node)
- (.getRight node)
- (.getHeight node)
- (.getRank node)))))
-
-(defn ^:private height ^long [^IAVLNode node]
- (if (nil? node)
- 0
- (long (.getHeight node))))
-
-(defn ^:private rotate-left ^IAVLNode [^IAVLNode node]
- (let [l (.getLeft node)
- r (.getRight node)
- rl (.getLeft r)
- rr (.getRight r)
- lh (height l)
- rlh (height rl)
- rrh (height rr)
- rnk (.getRank node)
- rnkr (.getRank r)]
- (AVLNode. nil
- (.getKey r) (.getVal r)
- (AVLNode. nil
- (.getKey node) (.getVal node)
- l
- rl
- (inc (max lh rlh))
- rnk)
- rr
- (max (+ lh 2)
- (+ rlh 2)
- (inc rrh))
- (inc (+ rnk rnkr)))))
-
-(defn ^:private rotate-left! ^IAVLNode [edit ^IAVLNode node]
- (let [node (ensure-editable edit node)
- l (.getLeft node)
- r (ensure-editable edit (.getRight node))
- rl (.getLeft r)
- rr (.getRight r)
- lh (height l)
- rlh (height rl)
- rrh (height rr)
- rnk (.getRank node)
- rnkr (.getRank r)]
- (.setLeft r node)
- (.setHeight r (max (+ lh 2) (+ rlh 2) (inc rrh)))
- (.setRank r (inc (+ rnk rnkr)))
- (.setRight node rl)
- (.setHeight node (inc (max lh rlh)))
- r))
-
-(defn ^:private rotate-right ^IAVLNode [^IAVLNode node]
- (let [r (.getRight node)
- l (.getLeft node)
- lr (.getRight l)
- ll (.getLeft l)
- rh (height r)
- lrh (height lr)
- llh (height ll)
- rnk (.getRank node)
- rnkl (.getRank l)]
- (AVLNode. nil
- (.getKey l) (.getVal l)
- ll
- (AVLNode. nil
- (.getKey node) (.getVal node)
- lr
- r
- (inc (max rh lrh))
- (dec (- rnk rnkl)))
- (max (+ rh 2)
- (+ lrh 2)
- (inc llh))
- rnkl)))
-
-(defn ^:private rotate-right! ^IAVLNode [edit ^IAVLNode node]
- (let [node (ensure-editable edit node)
- r (.getRight node)
- l (ensure-editable edit (.getLeft node))
- lr (.getRight l)
- ll (.getLeft l)
- rh (height r)
- lrh (height lr)
- llh (height ll)
- rnk (.getRank node)
- rnkl (.getRank l)]
- (.setRight l node)
- (.setHeight l (max (+ rh 2) (+ lrh 2) (inc llh)))
- (.setLeft node lr)
- (.setHeight node (inc (max rh lrh)))
- (.setRank node (dec (- rnk rnkl)))
- l))
-
-(defn ^:private lookup ^IAVLNode [^Comparator comp ^IAVLNode node k]
- (if (nil? node)
- nil
- (let [c (.compare comp k (.getKey node))]
- (cond
- (zero? c) node
- (neg? c) (recur comp (.getLeft node) k)
- :else (recur comp (.getRight node) k)))))
-
-(defn ^:private lookup-nearest
- ^IAVLNode [^Comparator comp ^IAVLNode node test k]
- (let [below? (or (identical? < test) (identical? <= test))
- equal? (or (identical? <= test) (identical? >= test))
- back? (if below? neg? pos?)
- backward (if below?
- #(.getLeft ^IAVLNode %)
- #(.getRight ^IAVLNode %))
- forward (if below?
- #(.getRight ^IAVLNode %)
- #(.getLeft ^IAVLNode %))]
- (loop [prev nil
- node node]
- (if (nil? node)
- prev
- (let [c (.compare comp k (.getKey node))]
- (cond
- (zero? c) (if equal?
- node
- (recur prev (backward node)))
- (back? c) (recur prev (backward node))
- :else (recur node (forward node))))))))
-
-(defn ^:private select [^IAVLNode node ^long rank]
- (if (nil? node)
- nil
- (let [node-rank (.getRank node)]
- (cond
- (== node-rank rank) node
- (< node-rank rank) (recur (.getRight node) (dec (- rank node-rank)))
- :else (recur (.getLeft node) rank)))))
-
-(defn ^:private rank ^long [^Comparator comp ^IAVLNode node k]
- (if (nil? node)
- -1
- (let [c (.compare comp k (.getKey node))]
- (cond
- (zero? c) (.getRank node)
- (neg? c) (recur comp (.getLeft node) k)
- :else (let [r (rank comp (.getRight node) k)]
- (if (== -1 r)
- -1
- (inc (+ (.getRank node) r))))))))
-
-(defn ^:private maybe-rebalance ^IAVLNode [^IAVLNode node]
- (let [l (.getLeft node)
- r (.getRight node)
- lh (height l)
- rh (height r)
- b (- lh rh)]
- (cond
- ;; right-heavy
- (< b -1)
- (let [rl (.getLeft r)
- rr (.getRight r)
- rlh (height rl)
- rrh (height rr)]
- (if (== (- rlh rrh) 1)
- ;; left-heavy
- (let [new-right (rotate-right r)]
- (rotate-left (AVLNode. nil
- (.getKey node) (.getVal node)
- (.getLeft node)
- new-right
- (inc (max lh (height new-right)))
- (.getRank node))))
- (rotate-left node)))
-
- ;; left-heavy
- (> b 1)
- (let [ll (.getLeft l)
- lr (.getRight l)
- llh (height ll)
- lrh (height lr)]
- ;; right-heavy
- (if (== (- lrh llh) 1)
- (let [new-left (rotate-left l)]
- (rotate-right (AVLNode. nil
- (.getKey node) (.getVal node)
- new-left
- (.getRight node)
- (inc (max rh (height new-left)))
- (.getRank node))))
- (rotate-right node)))
-
- :else
- node)))
-
-(defn ^:private maybe-rebalance! ^IAVLNode [edit ^IAVLNode node]
- (let [l (.getLeft node)
- r (.getRight node)
- lh (height l)
- rh (height r)
- b (- lh rh)]
- (cond
- ;; right-heavy
- (< b -1)
- (let [node (ensure-editable edit node)
- rl (.getLeft r)
- rr (.getRight r)
- rlh (height rl)
- rrh (height rr)]
- (if (== (- rlh rrh) 1)
- ;; left-heavy
- (let [new-right (rotate-right! edit r)]
- (.setRight node new-right)
- (.setHeight node (inc (max lh (height new-right))))
- (rotate-left! edit node))
- (rotate-left! edit node)))
-
- ;; left-heavy
- (> b 1)
- (let [node (ensure-editable edit node)
- ll (.getLeft l)
- lr (.getRight l)
- llh (height ll)
- lrh (height lr)]
- ;; right-heavy
- (if (== (- lrh llh) 1)
- (let [new-left (rotate-left! edit l)]
- (.setLeft node new-left)
- (.setHeight node (inc (max rh (height new-left))))
- (rotate-right! edit node))
- (rotate-right! edit node)))
-
- :else
- node)))
-
-(defn ^:private insert
- ^IAVLNode [^Comparator comp ^IAVLNode node k v ^Box found?]
- (if (nil? node)
- (AVLNode. nil k v nil nil 1 0)
- (let [nk (.getKey node)
- c (.compare comp k nk)]
- (cond
- (zero? c)
- (do
- (set! (.-val found?) true)
- (AVLNode. nil
- k v
- (.getLeft node)
- (.getRight node)
- (.getHeight node)
- (.getRank node)))
-
- (neg? c)
- (let [new-child (insert comp (.getLeft node) k v found?)]
- (maybe-rebalance
- (AVLNode. nil
- nk (.getVal node)
- new-child
- (.getRight node)
- (inc (max (.getHeight new-child)
- (height (.getRight node))))
- (if (.-val found?)
- (.getRank node)
- (unchecked-inc-int (.getRank node))))))
-
- :else
- (let [new-child (insert comp (.getRight node) k v found?)]
- (maybe-rebalance
- (AVLNode. nil
- nk (.getVal node)
- (.getLeft node)
- new-child
- (inc (max (.getHeight new-child)
- (height (.getLeft node))))
- (.getRank node))))))))
-
-(defn ^:private insert!
- ^IAVLNode [edit ^Comparator comp ^IAVLNode node k v ^Box found?]
- (if (nil? node)
- (AVLNode. edit k v nil nil 1 0)
- (let [node (ensure-editable edit node)
- nk (.getKey node)
- c (.compare comp k nk)]
- (cond
- (zero? c)
- (do
- (set! (.-val found?) true)
- (.setKey node k)
- (.setVal node v)
- node)
-
- (neg? c)
- (let [new-child (insert! edit comp (.getLeft node) k v found?)]
- (.setLeft node new-child)
- (.setHeight node
- (inc (max (.getHeight new-child)
- (height (.getRight node)))))
- (if-not (.-val found?)
- (.setRank node (unchecked-inc-int (.getRank node))))
- (maybe-rebalance! edit node))
-
- :else
- (let [new-child (insert! edit comp (.getRight node) k v found?)]
- (.setRight node new-child)
- (.setHeight node
- (inc (max (.getHeight new-child)
- (height (.getLeft node)))))
- (maybe-rebalance! edit node))))))
-
-(defn ^:private get-rightmost ^IAVLNode [^IAVLNode node]
- (if-let [r (.getRight node)]
- (recur r)
- node))
-
-(defn ^:private get-leftmost ^IAVLNode [^IAVLNode node]
- (if-let [l (.getLeft node)]
- (recur l)
- node))
-
-(defn ^:private delete-rightmost ^IAVLNode [^IAVLNode node]
- (if-let [r (.getRight node)]
- (let [l (.getLeft node)
- new-right (delete-rightmost r)]
- (maybe-rebalance
- (AVLNode. nil
- (.getKey node) (.getVal node)
- l
- new-right
- (inc (max (height l) (height new-right)))
- (.getRank node))))
- (.getLeft node)))
-
-(defn ^:private delete-rightmost! ^IAVLNode [edit ^IAVLNode node]
- (if-not (nil? node)
- (let [node (ensure-editable edit node)
- r ^IAVLNode (.getRight node)]
- (cond
- (nil? r)
- (if-let [l (.getLeft node)]
- (ensure-editable edit l))
-
- (nil? (.getRight r))
- (do
- (.setRight node (.getLeft r))
- (.setHeight node
- (inc (max (height (.getLeft node))
- (height (.getLeft r)))))
- (maybe-rebalance! edit node))
-
- :else
- (let [new-right (delete-rightmost! edit r)]
- (.setRight node new-right)
- (.setHeight node
- (inc (max (height (.getLeft node))
- (height new-right))))
- (maybe-rebalance! edit node))))))
-
-(defn ^:private delete
- ^IAVLNode [^Comparator comp ^IAVLNode node k ^Box found?]
- (if (nil? node)
- nil
- (let [nk (.getKey node)
- c (.compare comp k nk)]
- (cond
- (zero? c)
- (let [l (.getLeft node)
- r (.getRight node)]
- (set! (.-val found?) true)
- (if (and l r)
- (let [p (get-rightmost l)
- l' (delete-rightmost l)]
- (maybe-rebalance
- (AVLNode. nil
- (.getKey p) (.getVal p)
- l'
- r
- (inc (max (height l') (height r)))
- (unchecked-dec-int (.getRank node)))))
- (or l r)))
-
- (neg? c)
- (let [new-child (delete comp (.getLeft node) k found?)]
- (if (identical? new-child (.getLeft node))
- node
- (maybe-rebalance
- (AVLNode. nil
- nk (.getVal node)
- new-child
- (.getRight node)
- (inc (max (height new-child)
- (height (.getRight node))))
- (if (.-val found?)
- (unchecked-dec-int (.getRank node))
- (.getRank node))))))
-
- :else
- (let [new-child (delete comp (.getRight node) k found?)]
- (if (identical? new-child (.getRight node))
- node
- (maybe-rebalance
- (AVLNode. nil
- nk (.getVal node)
- (.getLeft node)
- new-child
- (inc (max (height new-child)
- (height (.getLeft node))))
- (.getRank node)))))))))
-
-(defn ^:private delete!
- ^IAVLNode [edit ^Comparator comp ^IAVLNode node k ^Box found?]
- (if (nil? node)
- nil
- (let [nk (.getKey node)
- c (.compare comp k nk)]
- (cond
- (zero? c)
- (let [l (.getLeft node)
- r (.getRight node)]
- (set! (.-val found?) true)
- (cond
- (and l r)
- (let [node (ensure-editable edit node)
- p (get-rightmost l)
- l' (delete-rightmost! edit l)]
- (.setKey node (.getKey p))
- (.setVal node (.getVal p))
- (.setLeft node l')
- (.setHeight node (inc (max (height l') (height r))))
- (.setRank node (unchecked-dec-int (.getRank node)))
- (maybe-rebalance! edit node))
-
- l l
- r r
- :else nil))
-
- (neg? c)
- (let [new-child (delete! edit comp (.getLeft node) k found?)]
- (if (.-val found?)
- (let [node (ensure-editable edit node)]
- (.setLeft node new-child)
- (.setHeight node
- (inc (max (height new-child)
- (height (.getRight node)))))
- (.setRank node (unchecked-dec-int (.getRank node)))
- (maybe-rebalance! edit node))
- node))
-
- :else
- (let [new-child (delete! edit comp (.getRight node) k found?)]
- (if (.-val found?)
- (let [node (ensure-editable edit node)]
- (.setRight node new-child)
- (.setHeight node
- (inc (max (height new-child)
- (height (.getLeft node)))))
- (maybe-rebalance! edit node))
- node))))))
-
-(defn ^:private join
- [^Comparator comp ^long left-count ^IAVLNode left ^IAVLNode right]
- (cond
- (nil? left) right
- (nil? right) left
- :else
- (let [lh (.getHeight left)
- rh (.getHeight right)]
- (cond
- (== lh rh)
- (let [left-min (get-rightmost left)
- new-left (delete comp left (.getKey left-min) (Box. false))]
- (AVLNode. nil
- (.getKey left-min) (.getVal left-min)
- new-left
- right
- (unchecked-inc-int rh)
- (unchecked-dec-int left-count)))
-
- (< lh rh)
- (letfn [(step [^IAVLNode current ^long lvl]
- (cond
- (zero? lvl)
- (join comp left-count left current)
-
- (nil? (.getLeft current))
- (AVLNode. nil
- (.getKey current) (.getVal current)
- left
- (.getRight current)
- 2
- left-count)
-
- :else
- (let [new-child (step (.getLeft current) (dec lvl))
- current-r (.getRight current)]
- (maybe-rebalance
- (AVLNode. nil
- (.getKey current) (.getVal current)
- new-child
- current-r
- (inc (max (.getHeight ^IAVLNode new-child)
- (height current-r)))
- (+ left-count (.getRank current)))))))]
- (step right (- rh lh)))
-
- :else
- (letfn [(step [^IAVLNode current ^long cnt ^long lvl]
- (cond
- (zero? lvl)
- (join comp cnt current right)
-
- (nil? (.getRight current))
- (AVLNode. nil
- (.getKey current) (.getVal current)
- (.getLeft current)
- right
- 2
- (.getRank current))
-
- :else
- (let [new-child (step (.getRight current)
- (dec (- cnt (.getRank current)))
- (dec lvl))
- current-l (.getLeft current)]
- (maybe-rebalance
- (AVLNode. nil
- (.getKey current) (.getVal current)
- current-l
- new-child
- (inc (max (.getHeight ^IAVLNode new-child)
- (height current-l)))
- (.getRank current))))))]
- (step left left-count (- lh rh)))))))
-
-(defn ^:private split [^Comparator comp ^IAVLNode node k]
- (letfn [(step [^IAVLNode node]
- (if (nil? node)
- [nil nil nil]
- (let [c (.compare comp k (.getKey node))]
- (cond
- (zero? c)
- [(.getLeft node)
- (MapEntry. (.getKey node) (.getVal node))
- (.getRight node)]
-
- (neg? c)
- (let [[l e r] (step (.getLeft node))
- r' (insert comp
- (.getRight node)
- (.getKey node)
- (.getVal node)
- (Box. false))]
- [l
- e
- (cond
- e (join comp
- (- (.getRank node)
- (inc (rank comp
- (.getLeft node)
- (.key ^MapEntry e))))
- r
- r')
-
- r (join comp
- (- (.getRank node)
- (rank comp
- (.getLeft node)
- (.getKey (get-leftmost r))))
- r
- r')
-
- :else r')])
-
- :else
- (let [[l e r] (step (.getRight node))
- l' (insert comp
- (.getLeft node)
- (.getKey node)
- (.getVal node)
- (Box. false))]
- [(join comp
- (unchecked-inc-int (.getRank node))
- l'
- l)
- e
- r])))))]
- (step node)))
-
-(defn ^:private range ^IAVLNode [^Comparator comp ^IAVLNode node low high]
- (let [[_ ^MapEntry low-e r] (split comp node low)
- [l ^MapEntry high-e _] (split comp r high)]
- (cond-> l
- low-e (as-> node
- (insert comp node
- (.key low-e) (.val low-e)
- (Box. false)))
- high-e (as-> node
- (insert comp node
- (.key high-e) (.val high-e)
- (Box. false))))))
-
-(defn ^:private seq-push [^IAVLNode node stack ascending?]
- (loop [node node stack stack]
- (if (nil? node)
- stack
- (recur (if ascending? (.getLeft node) (.getRight node))
- (conj stack node)))))
-
-(defn ^:private avl-map-kv-reduce [^IAVLNode node f init]
- (let [init (if (nil? (.getLeft node))
- init
- (avl-map-kv-reduce (.getLeft node) f init))]
- (if (reduced? init)
- init
- (let [init (f init (.getKey node) (.getVal node))]
- (if (reduced? init)
- init
- (if (nil? (.getRight node))
- init
- (recur (.getRight node) f init)))))))
-
-(defn ^:private avl-map-reduce [^IAVLNode node f init]
- (let [init (if (nil? (.getLeft node))
- init
- (avl-map-reduce (.getLeft node) f init))]
- (if (reduced? init)
- init
- (let [init (f init (MapEntry. (.getKey node) (.getVal node)))]
- (if (reduced? init)
- init
- (if (nil? (.getRight node))
- init
- (recur (.getRight node) f init)))))))
-
-(defn ^:private avl-map-reduce-skip [^IAVLNode node f init skip-node]
- (let [init (if (nil? (.getLeft node))
- init
- (avl-map-reduce-skip (.getLeft node) f init skip-node))]
- (if (reduced? init)
- init
- (if (identical? skip-node node)
- (if (nil? (.getRight node))
- init
- (avl-map-reduce (.getRight node) f init))
- (let [init (f init (MapEntry. (.getKey node) (.getVal node)))]
- (if (reduced? init)
- init
- (if (nil? (.getRight node))
- init
- (recur (.getRight node) f init skip-node))))))))
-
-(defn ^:private avl-set-reduce [^IAVLNode node f init]
- (let [init (if (nil? (.getLeft node))
- init
- (avl-set-reduce (.getLeft node) f init))]
- (if (reduced? init)
- init
- (let [init (f init (.getKey node))]
- (if (reduced? init)
- init
- (if (nil? (.getRight node))
- init
- (recur (.getRight node) f init)))))))
-
-(defn ^:private avl-set-reduce-skip [^IAVLNode node f init skip-node]
- (let [init (if (nil? (.getLeft node))
- init
- (avl-set-reduce-skip (.getLeft node) f init skip-node))]
- (if (reduced? init)
- init
- (if (identical? skip-node node)
- (if (nil? (.getRight node))
- init
- (avl-set-reduce (.getRight node) f init))
- (let [init (f init (.getKey node))]
- (if (reduced? init)
- init
- (if (nil? (.getRight node))
- init
- (avl-set-reduce (.getRight node) f init))))))))
-
-(deftype AVLMapSeq [^IPersistentMap _meta
- ^IPersistentStack stack
- ^boolean ascending?
- ^int cnt
- ^:unsynchronized-mutable ^int _hash
- ^:unsynchronized-mutable ^int _hasheq]
- :no-print true
-
- Object
- (toString [this]
- (RT/printString this))
-
- (hashCode [this]
- (caching-hash this hash-seq _hash))
-
- clojure.lang.IHashEq
- (hasheq [this]
- (caching-hash this hasheq-seq _hasheq))
-
- clojure.lang.Seqable
- (seq [this]
- this)
-
- clojure.lang.Sequential
- clojure.lang.ISeq
- (first [this]
- (peek stack))
-
- (more [this]
- (let [node ^IAVLNode (first stack)
- next-stack (seq-push (if ascending? (.getRight node) (.getLeft node))
- (next stack)
- ascending?)]
- (if (nil? next-stack)
- ()
- (AVLMapSeq. nil next-stack ascending? (unchecked-dec-int cnt) -1 -1))))
-
- (next [this]
- (.seq (.more this)))
-
- clojure.lang.Counted
- (count [this]
- (if (neg? cnt)
- (unchecked-inc-int (count (next this)))
- cnt))
-
- clojure.lang.IPersistentCollection
- (cons [this x]
- (cons x this))
-
- (equiv [this that]
- (equiv-sequential this that))
-
- (empty [this]
- (with-meta () _meta))
-
- clojure.lang.IMeta
- (meta [this]
- _meta)
-
- clojure.lang.IObj
- (withMeta [this meta]
- (AVLMapSeq. meta stack ascending? cnt _hash _hasheq))
-
- java.io.Serializable
-
- java.util.List
- (toArray [this]
- (RT/seqToArray (seq this)))
-
- (^objects toArray [this ^objects arr]
- (RT/seqToPassedArray (seq this) arr))
-
- (containsAll [this c]
- (every? #(.contains this %) (iterator-seq (.iterator c))))
-
- (size [this]
- (count this))
-
- (isEmpty [this]
- (zero? cnt))
-
- (contains [this x]
- (or (some #(Util/equiv % x) this) false))
-
- (iterator [this]
- (SeqIterator. this))
-
- (subList [this from to]
- (.subList (Collections/unmodifiableList (ArrayList. this)) from to))
-
- (indexOf [this x]
- (loop [i (int 0) s (seq this)]
- (if s
- (if (Util/equiv (first s) x)
- i
- (recur (unchecked-inc-int i) (next s)))
- (int -1))))
-
- (lastIndexOf [this x]
- (.lastIndexOf (ArrayList. this) x))
-
- (listIterator [this]
- (.listIterator (Collections/unmodifiableList (ArrayList. this))))
-
- (listIterator [this i]
- (.listIterator (Collections/unmodifiableList (ArrayList. this)) i))
-
- (get [this i]
- (RT/nth this i))
-
- (add [this x] (throw-unsupported))
- (^boolean remove [this x] (throw-unsupported))
- (addAll [this c] (throw-unsupported))
- (clear [this] (throw-unsupported))
- (retainAll [this c] (throw-unsupported))
- (removeAll [this c] (throw-unsupported))
- (set [this i e] (throw-unsupported))
- (remove [this ^int i] (throw-unsupported))
- (add [this i e] (throw-unsupported)))
-
-(defn ^:private create-seq [node ascending? cnt]
- (AVLMapSeq. nil (seq-push node nil ascending?) ascending? cnt -1 -1))
-
-(declare ->AVLTransientMap)
-
-(deftype AVLMap [^Comparator comp
- ^IAVLNode tree
- ^int cnt
- ^IPersistentMap _meta
- ^:unsynchronized-mutable ^int _hash
- ^:unsynchronized-mutable ^int _hasheq]
- Object
- (toString [this]
- (RT/printString this))
-
- (hashCode [this]
- (caching-hash this hash-imap _hash))
-
- (equals [this that]
- (APersistentMap/mapEquals this that))
-
- IAVLTree
- (getTree [this]
- tree)
-
- INavigableTree
- (nearest [this test k]
- (if-let [node (lookup-nearest comp tree test k)]
- (MapEntry. (.getKey node) (.getVal node))))
-
- clojure.lang.IHashEq
- (hasheq [this]
- (caching-hash this hasheq-imap _hasheq))
-
- clojure.lang.IMeta
- (meta [this]
- _meta)
-
- clojure.lang.IObj
- (withMeta [this meta]
- (AVLMap. comp tree cnt meta _hash _hasheq))
-
- clojure.lang.Counted
- (count [this]
- cnt)
-
- clojure.lang.Indexed
- (nth [this i]
- (if-let [n (select tree i)]
- (MapEntry. (.getKey ^IAVLNode n) (.getVal ^IAVLNode n))
- (throw
- (IndexOutOfBoundsException. "nth index out of bounds in AVL tree"))))
-
- (nth [this i not-found]
- (if-let [n (select tree i)]
- (MapEntry. (.getKey ^IAVLNode n) (.getVal ^IAVLNode n))
- not-found))
-
- clojure.lang.IPersistentCollection
- (cons [this entry]
- (if (vector? entry)
- (assoc this (nth entry 0) (nth entry 1))
- (reduce conj this entry)))
-
- (empty [this]
- (AVLMap. comp nil 0 _meta empty-map-hashcode empty-map-hasheq))
-
- (equiv [this that]
- (equiv-map this that))
-
- clojure.lang.IFn
- (invoke [this k]
- (.valAt this k))
-
- (invoke [this k not-found]
- (.valAt this k not-found))
-
- (applyTo [this args]
- (let [n (RT/boundedLength args 2)]
- (case n
- 0 (throw (clojure.lang.ArityException.
- n (.. this (getClass) (getSimpleName))))
- 1 (.invoke this (first args))
- 2 (.invoke this (first args) (second args))
- 3 (throw (clojure.lang.ArityException.
- n (.. this (getClass) (getSimpleName)))))))
-
- clojure.lang.Seqable
- (seq [this]
- (if (pos? cnt)
- (create-seq tree true cnt)))
-
- clojure.lang.Reversible
- (rseq [this]
- (if (pos? cnt)
- (create-seq tree false cnt)))
-
- clojure.lang.ILookup
- (valAt [this k]
- (.valAt this k nil))
-
- (valAt [this k not-found]
- (let [n ^IAVLNode (lookup comp tree k)]
- (if-not (nil? n)
- (.getVal n)
- not-found)))
-
- clojure.lang.Associative
- (assoc [this k v]
- (let [found? (Box. false)
- new-tree (insert comp tree k v found?)]
- (AVLMap. comp
- new-tree
- (if (.-val found?) cnt (unchecked-inc-int cnt))
- _meta -1 -1)))
-
- (containsKey [this k]
- (not (nil? (.entryAt this k))))
-
- (entryAt [this k]
- (if-let [node (lookup comp tree k)]
- (MapEntry. (.getKey node) (.getVal node))))
-
- clojure.lang.MapEquivalence
- clojure.lang.IPersistentMap
- (without [this k]
- (let [found? (Box. false)
- new-tree (delete comp tree k found?)]
- (if (.-val found?)
- (AVLMap. comp
- new-tree
- (unchecked-dec-int cnt)
- _meta -1 -1)
- this)))
-
- (assocEx [this k v]
- (let [found? (Box. false)
- new-tree (insert comp tree k v found?)]
- (if (.-val found?)
- (throw (ex-info "key already present" {}))
- (AVLMap. comp
- new-tree
- (unchecked-inc-int cnt)
- _meta -1 -1))))
-
- clojure.lang.Sorted
- (seq [this ascending?]
- (if (pos? cnt)
- (create-seq tree ascending? cnt)))
-
- (seqFrom [this k ascending?]
- (if (pos? cnt)
- (loop [stack nil t tree]
- (if-not (nil? t)
- (let [c (.compare comp k (.getKey t))]
- (cond
- (zero? c) (AVLMapSeq. nil (conj stack t) ascending? -1 -1 -1)
- ascending? (if (neg? c)
- (recur (conj stack t) (.getLeft t))
- (recur stack (.getRight t)))
- :else (if (pos? c)
- (recur (conj stack t) (.getRight t))
- (recur stack (.getLeft t)))))
- (if-not (nil? stack)
- (AVLMapSeq. nil stack ascending? -1 -1 -1))))))
-
- (entryKey [this entry]
- (key entry))
-
- (comparator [this]
- comp)
-
- clojure.lang.IEditableCollection
- (asTransient [this]
- (->AVLTransientMap
- (AtomicReference. (Thread/currentThread)) comp tree cnt))
-
- clojure.core.protocols/IKVReduce
- (kv-reduce [this f init]
- (if (nil? tree)
- init
- (let [init (avl-map-kv-reduce tree f init)]
- (if (reduced? init)
- @init
- init))))
-
- clojure.lang.IReduce
- (reduce [this f]
- (case cnt
- 0 (f)
- 1 (MapEntry. (.getKey tree) (.getVal tree))
- (let [^IAVLNode n0 (select tree 0)
- init (avl-map-reduce-skip tree f (MapEntry. (.getKey n0) (.getVal n0)) n0)]
- (if (reduced? init)
- @init
- init))))
-
- (reduce [this f init]
- (if (nil? tree)
- init
- (let [init (avl-map-reduce tree f init)]
- (if (reduced? init)
- @init
- init))))
-
- java.io.Serializable
-
- Iterable
- (iterator [this]
- (SeqIterator. (seq this)))
-
- java.util.Map
- (get [this k]
- (.valAt this k))
-
- (clear [this]
- (throw-unsupported))
-
- (containsValue [this v]
- (.. this values (contains v)))
-
- (entrySet [this]
- (set (seq this)))
-
- (put [this k v]
- (throw-unsupported))
-
- (putAll [this m]
- (throw-unsupported))
-
- (remove [this k]
- (throw-unsupported))
-
- (size [this]
- cnt)
-
- (values [this]
- (vals this)))
-
-(deftype AVLTransientMap [^AtomicReference edit
- ^Comparator comp
- ^:unsynchronized-mutable ^IAVLNode tree
- ^:unsynchronized-mutable ^int cnt]
- clojure.lang.Counted
- (count [this]
- cnt)
-
- clojure.lang.ILookup
- (valAt [this k]
- (.valAt this k nil))
-
- (valAt [this k not-found]
- (let [n ^IAVLNode (lookup comp tree k)]
- (if-not (nil? n)
- (.getVal n)
- not-found)))
-
- clojure.lang.IFn
- (invoke [this k]
- (.valAt this k))
-
- (invoke [this k not-found]
- (.valAt this k not-found))
-
- (applyTo [this args]
- (let [n (RT/boundedLength args 2)]
- (case n
- 0 (throw (clojure.lang.ArityException.
- n (.. this (getClass) (getSimpleName))))
- 1 (.invoke this (first args))
- 2 (.invoke this (first args) (second args))
- 3 (throw (clojure.lang.ArityException.
- n (.. this (getClass) (getSimpleName)))))))
-
- clojure.lang.ITransientCollection
- (conj [this entry]
- (ensure-editable edit)
- (if (vector? entry)
- (assoc! this (nth entry 0) (nth entry 1))
- (reduce conj! this entry)))
-
- (persistent [this]
- (ensure-editable edit)
- (.set edit nil)
- (AVLMap. comp tree cnt nil -1 -1))
-
- clojure.lang.ITransientAssociative
- (assoc [this k v]
- (ensure-editable edit)
- (let [found? (Box. false)
- new-tree (insert! edit comp tree k v found?)]
- (set! tree new-tree)
- (if-not (.-val found?)
- (set! cnt (unchecked-inc-int cnt)))
- this))
-
- ITransientAssociative2Impl
- (containsKey [this k]
- (not (nil? (.entryAt this k))))
-
- (entryAt [this k]
- (if-let [node (lookup comp tree k)]
- (MapEntry. (.getKey node) (.getVal node))))
-
- clojure.lang.ITransientMap
- (without [this k]
- (ensure-editable edit)
- (let [found? (Box. false)
- new-tree (delete! edit comp tree k found?)]
- (when (.-val found?)
- (set! tree new-tree)
- (set! cnt (unchecked-dec-int cnt)))
- this)))
-
-(declare ->AVLTransientSet)
-
-(deftype AVLSet [^IPersistentMap _meta
- ^AVLMap avl-map
- ^:unsynchronized-mutable ^int _hash
- ^:unsynchronized-mutable ^int _hasheq]
- Object
- (toString [this]
- (RT/printString this))
-
- (hashCode [this]
- (caching-hash this hash-iset _hash))
-
- (equals [this that]
- (APersistentSet/setEquals this that))
-
- IAVLTree
- (getTree [this]
- (.getTree avl-map))
-
- INavigableTree
- (nearest [this test k]
- (if-let [node (lookup-nearest (.comparator avl-map)
- (.getTree avl-map)
- test
- k)]
- (.getKey node)))
-
- clojure.lang.IHashEq
- (hasheq [this]
- (caching-hash this hasheq-iset _hasheq))
-
- clojure.lang.IMeta
- (meta [this]
- _meta)
-
- clojure.lang.IObj
- (withMeta [this meta]
- (AVLSet. meta avl-map _hash _hasheq))
-
- clojure.lang.Counted
- (count [this]
- (count avl-map))
-
- clojure.lang.Indexed
- (nth [this i]
- (if-let [n (select (.-tree avl-map) i)]
- (.getVal ^IAVLNode n)
- (throw
- (IndexOutOfBoundsException. "nth index out of bounds in AVL tree"))))
-
- (nth [this i not-found]
- (if-let [n (select (.-tree avl-map) i)]
- (.getVal ^IAVLNode n)
- not-found))
-
- clojure.lang.IPersistentCollection
- (cons [this x]
- (AVLSet. _meta (assoc avl-map x x) -1 -1))
-
- (empty [this]
- (AVLSet. _meta (empty avl-map) empty-set-hashcode empty-set-hasheq))
-
- (equiv [this that]
- (and
- (set? that)
- (== (count this) (count that))
- (every? #(contains? this %) that)))
-
- clojure.lang.Seqable
- (seq [this]
- (keys avl-map))
-
- clojure.lang.Sorted
- (seq [this ascending?]
- (RT/keys (.seq avl-map ascending?)))
-
- (seqFrom [this k ascending?]
- (RT/keys (.seqFrom avl-map k ascending?)))
-
- (entryKey [this entry]
- entry)
-
- (comparator [this]
- (.comparator avl-map))
-
- clojure.lang.Reversible
- (rseq [this]
- (map key (rseq avl-map)))
-
- clojure.lang.ILookup
- (valAt [this v]
- (.valAt this v nil))
-
- (valAt [this v not-found]
- (let [n (.entryAt avl-map v)]
- (if-not (nil? n)
- (.getKey n)
- not-found)))
-
- clojure.lang.IPersistentSet
- (disjoin [this v]
- (AVLSet. _meta (dissoc avl-map v) -1 -1))
-
- (contains [this k]
- (contains? avl-map k))
-
- (get [this k]
- (.valAt this k nil))
-
- clojure.lang.IReduce
- (reduce [this f]
- (case (count avl-map)
- 0 (f)
- 1 (.getKey (.getTree avl-map))
- (let [tree (.getTree avl-map)
- ^IAVLNode n0 (select tree 0)
- init (avl-set-reduce-skip tree f (.getKey n0) n0)]
- (if (reduced? init)
- @init
- init))))
-
- (reduce [this f init]
- (let [tree (.getTree avl-map)]
- (if (nil? tree)
- init
- (let [init (avl-set-reduce tree f init)]
- (if (reduced? init)
- @init
- init)))))
-
- clojure.lang.IFn
- (invoke [this k]
- (.valAt this k))
-
- (applyTo [this args]
- (let [n (RT/boundedLength args 1)]
- (case n
- 0 (throw (clojure.lang.ArityException.
- n (.. this (getClass) (getSimpleName))))
- 1 (.invoke this (first args))
- 2 (throw (clojure.lang.ArityException.
- n (.. this (getClass) (getSimpleName)))))))
-
- clojure.lang.IEditableCollection
- (asTransient [this]
- (->AVLTransientSet (.asTransient avl-map)))
-
- java.io.Serializable
-
- java.util.Set
- (add [this o] (throw-unsupported))
- (remove [this o] (throw-unsupported))
- (addAll [this c] (throw-unsupported))
- (clear [this] (throw-unsupported))
- (retainAll [this c] (throw-unsupported))
- (removeAll [this c] (throw-unsupported))
-
- (containsAll [this c]
- (every? #(.contains this %) (iterator-seq (.iterator c))))
-
- (size [this]
- (count this))
-
- (isEmpty [this]
- (zero? (count this)))
-
- (iterator [this]
- (SeqIterator. (seq this)))
-
- (toArray [this]
- (RT/seqToArray (seq this)))
-
- (^objects toArray [this ^objects a]
- (RT/seqToPassedArray (seq this) a)))
-
-(deftype AVLTransientSet
- [^:unsynchronized-mutable ^AVLTransientMap transient-avl-map]
- clojure.lang.ITransientCollection
- (conj [this k]
- (set! transient-avl-map (.assoc transient-avl-map k k))
- this)
-
- (persistent [this]
- (AVLSet. nil (.persistent transient-avl-map) -1 -1))
-
- clojure.lang.ITransientSet
- (disjoin [this k]
- (set! transient-avl-map (.without transient-avl-map k))
- this)
-
- (contains [this k]
- (not (identical? this (.valAt transient-avl-map k this))))
-
- (get [this k]
- (.valAt transient-avl-map k))
-
- clojure.lang.IFn
- (invoke [this k]
- (.valAt transient-avl-map k))
-
- (invoke [this k not-found]
- (.valAt transient-avl-map k not-found))
-
- (applyTo [this args]
- (let [n (RT/boundedLength args 2)]
- (case n
- 0 (throw (clojure.lang.ArityException.
- n (.. this (getClass) (getSimpleName))))
- 1 (.invoke this (first args))
- 2 (.invoke this (first args) (second args))
- 3 (throw (clojure.lang.ArityException.
- n (.. this (getClass) (getSimpleName)))))))
-
- clojure.lang.Counted
- (count [this]
- (.count transient-avl-map)))
-
-(def ^:private empty-map
- (AVLMap. RT/DEFAULT_COMPARATOR nil 0 nil
- empty-map-hashcode empty-map-hasheq))
-
-(def ^:private empty-set
- (AVLSet. nil empty-map empty-set-hashcode empty-set-hasheq))
-
-(defmethod print-dup AVLMap [m ^java.io.Writer w]
- (if-let [[[k v] & more] (seq m)]
- (do
- (.write w "#=(clojure.data.avl/sorted-map ")
- (print-dup k w)
- (.write w " ")
- (print-dup v w)
- (doseq [[k v] more]
- (.write w ", ")
- (print-dup k w)
- (.write w " ")
- (print-dup v w))
- (.write w ")"))
- (.write w "#=(clojure.data.avl/sorted-map)")))
-
-(defmethod print-dup AVLSet [s ^java.io.Writer w]
- (if-let [[x & xs] (seq s)]
- (do
- (.write w "#=(clojure.data.avl/sorted-set ")
- (print-dup x w)
- (doseq [x xs]
- (.write w " ")
- (print-dup x w))
- (.write w ")"))
- (.write w "#=(clojure.data.avl/sorted-set)")))
-
-(doseq [v [#'->AVLMapSeq
- #'->AVLNode
- #'->AVLMap
- #'->AVLSet
- #'->AVLTransientMap
- #'->AVLTransientSet]]
- (alter-meta! v assoc :private true))
-
-(defn sorted-map
- "keyval => key val
- Returns a new AVL map with supplied mappings."
- {:added "0.0.1"}
- [& keyvals]
- (loop [in (seq keyvals) out (transient empty-map)]
- (if in
- (if-let [nin (next in)]
- (recur (next nin) (assoc! out (first in) (first nin)))
- (throw (IllegalArgumentException.
- (format
- "sorted-map: no value supplied for key: %s"
- (first in)))))
- (persistent! out))))
-
-(defn sorted-map-by
- "keyval => key val
- Returns a new sorted map with supplied mappings, using the supplied
- comparator."
- {:added "0.0.1"}
- [^Comparator comparator & keyvals]
- (loop [in (seq keyvals)
- out (AVLTransientMap.
- (AtomicReference. (Thread/currentThread)) comparator nil 0)]
- (if in
- (if-let [nin (next in)]
- (recur (next nin) (assoc! out (first in) (first nin)))
- (throw (IllegalArgumentException.
- (format
- "sorted-map-by: no value supplied for key: %s"
- (first in)))))
- (persistent! out))))
-
-(defn sorted-set
- "Returns a new sorted set with supplied keys."
- {:added "0.0.1"}
- [& keys]
- (persistent! (reduce conj! (transient empty-set) keys)))
-
-(defn sorted-set-by
- "Returns a new sorted set with supplied keys, using the supplied comparator."
- {:added "0.0.1"}
- [^Comparator comparator & keys]
- (persistent!
- (reduce conj!
- (AVLTransientSet. (transient (sorted-map-by comparator)))
- keys)))
-
-(defn rank-of
- "Returns the rank of x in coll or -1 if not present."
- {:added "0.0.6"}
- ^long [coll x]
- (rank (.comparator ^clojure.lang.Sorted coll) (.getTree ^IAVLTree coll) x))
-
-(defn nearest
- "(alpha)
-
- Equivalent to, but more efficient than, (first (subseq* coll test x)),
- where subseq* is clojure.core/subseq for test in #{>, >=} and
- clojure.core/rsubseq for test in #{<, <=}."
- {:added "0.0.12"}
- [coll test x]
- (.nearest ^INavigableTree coll test x))
-
-(defn split-key
- "(alpha)
-
- Returns [left e? right], where left and right are collections of
- the same type as coll and containing, respectively, the keys below
- and above k in the ordering determined by coll's comparator, while
- e? is the entry at key k for maps, the stored copy of the key k for
- sets, nil if coll does not contain k."
- {:added "0.0.12"}
- [k coll]
- (let [comp (.comparator ^clojure.lang.Sorted coll)
- [left e? right] (split comp (.getTree ^IAVLTree coll) k)
- keyfn (if (map? coll) key identity)
- wrap (if (map? coll)
- (fn wrap-map [tree cnt]
- (AVLMap. comp tree cnt nil -1 -1))
- (fn wrap-set [tree cnt]
- (AVLSet. nil (AVLMap. comp tree cnt nil -1 -1) -1 -1)))]
- [(wrap left
- (if (or e? right)
- (rank-of coll (keyfn (nearest coll >= k)))
- (count coll)))
- (if (and e? (set? coll))
- (.getKey ^MapEntry e?)
- e?)
- (wrap right
- (if right
- (- (count coll) (rank-of coll (keyfn (nearest coll > k))))
- 0))]))
-
-(defn split-at
- "(alpha)
-
- Equivalent to, but more efficient than,
- [(into (empty coll) (take n coll))
- (into (empty coll) (drop n coll))]."
- {:added "0.0.12"}
- [^long n coll]
- (if (>= n (count coll))
- [coll (empty coll)]
- (let [k (nth coll n)
- k (if (map? coll) (key k) k)
- [l e r] (split-key k coll)]
- [l (conj r e)])))
-
-(defn subrange
- "(alpha)
-
- Returns an AVL collection comprising the entries of coll between
- start and end (in the sense determined by coll's comparator) in
- logarithmic time. Whether the endpoints are themselves included in
- the returned collection depends on the provided tests; start-test
- must be either > or >=, end-test must be either < or <=.
-
- When passed a single test and limit, subrange infers the other end
- of the range from the test: > / >= mean to include items up to the
- end of coll, < / <= mean to include items taken from the beginning
- of coll.
-
- (subrange coll >= start <= end) is equivalent to, but more efficient
- than, (into (empty coll) (subseq coll >= start <= end))."
- {:added "0.0.12"}
- ([coll test limit]
- (cond
- (zero? (count coll))
- coll
-
- (#{> >=} test)
- (let [n (select (.getTree ^IAVLTree coll)
- (dec (count coll)))
- k (.getKey ^IAVLNode n)]
- (if (pos? (.compare (.comparator ^clojure.lang.Sorted coll)
- limit k))
- (empty coll)
- (subrange coll
- test limit
- <= k)))
-
- :else
- (let [n (select (.getTree ^IAVLTree coll) 0)
- k (.getKey ^IAVLNode n)]
- (if (neg? (.compare (.comparator ^clojure.lang.Sorted coll)
- limit k))
- (empty coll)
- (subrange coll
- >= k
- test limit)))))
- ([coll start-test start end-test end]
- (if (zero? (count coll))
- coll
- (let [comp (.comparator ^clojure.lang.Sorted coll)]
- (if (pos? (.compare comp start end))
- (throw
- (IndexOutOfBoundsException. "start greater than end in subrange"))
- (let [input-tree (.getTree ^IAVLTree coll)
- l (lookup-nearest comp input-tree start-test start)
- h (lookup-nearest comp input-tree end-test end)]
- (if (and l h)
- (let [lk (.getKey l)
- hk (.getKey h)]
- (if (neg? (.compare comp hk lk))
- (empty coll)
- (let [tree (range comp (.getTree ^IAVLTree coll) lk hk)
- cnt (inc (- (rank-of coll hk)
- (rank-of coll lk)))
- m (AVLMap. comp tree cnt nil -1 -1)]
- (if (map? coll)
- m
- (AVLSet. nil m -1 -1)))))
- (empty coll))))))))
diff --git a/src/test/cljs/clojure/data/avl_test.cljs b/src/test/cljs/clojure/data/avl_test.cljs
deleted file mode 100644
index 34a3ab2..0000000
--- a/src/test/cljs/clojure/data/avl_test.cljs
+++ /dev/null
@@ -1,279 +0,0 @@
-(ns clojure.data.avl-test
- (:require [cljs.test :refer-macros [deftest testing is]]
- [clojure.data.avl :as avl]))
-
-
-(def small-tree-size 150)
-(def medium-tree-size 2500)
-(def large-tree-size 10000)
-
-(defn validate-invariant [coll]
- (let [tree (.getTree coll)
- h (fn [node]
- (if node
- (.getHeight node)
- 0))]
- (or (nil? tree)
- (boolean
- (#{-1 0 1} (- (h (.getLeft tree)) (h (.getRight tree))))))))
-
-(defn twice [x]
- [x x])
-
-(def ks (range large-tree-size))
-(def ksks (doall (interleave ks ks)))
-(def ks' (doall (map first (partition 2 ks))))
-
-(def rb-map (apply sorted-map ksks))
-(def avl-map (apply avl/sorted-map ksks))
-
-(def rb-set (apply sorted-set ks))
-(def avl-set (apply avl/sorted-set ks))
-
-(def rb-map-by-> (apply sorted-map-by > ksks))
-(def avl-map-by-> (apply avl/sorted-map-by > ksks))
-
-(def rb-set-by-> (apply sorted-set-by > ks))
-(def avl-set-by-> (apply avl/sorted-set-by > ks))
-
-(def even-numbers (apply avl/sorted-set (range 0 large-tree-size 2)))
-
-(deftest sanity-checks
- (testing "AVL collections look like regular sorted collections"
- (is (= rb-map avl-map))
- (is (= rb-set avl-set)))
- (testing "AVL collections with custom comparators looks like regular ones"
- (is (= rb-map-by-> avl-map-by->))
- (is (= rb-set-by-> avl-set-by->)))
- (testing "AVL collection seqs look like regular sorted collection seqs"
- (is (= (seq rb-map) (seq avl-map)))
- (is (= (seq rb-set) (seq avl-set)))
- (is (= (subseq rb-map > 100 < 1000) (subseq avl-map > 100 < 1000)))
- (is (= (subseq rb-set > 100 < 1000) (subseq avl-set > 100 < 1000))))
- (testing "non-transient construction works as expected"
- (is (= avl-map (reduce-kv assoc (avl/sorted-map) rb-map))))
- (testing "dissoc/dissoc! work as expected"
- (is (= (reduce dissoc rb-map ks') (reduce dissoc avl-map ks')))
- (is (= (reduce dissoc rb-map ks')
- (persistent! (reduce dissoc! (transient avl-map) ks')))))
- (testing "disj/disj! work as expected"
- (is (= (reduce disj rb-set ks') (reduce disj avl-set ks')))
- (is (= (reduce disj rb-set ks')
- (persistent! (reduce disj! (transient avl-set) ks')))))
- (testing "*-by seqs look like they should"
- (is (= (seq rb-map-by->) (seq avl-map-by->)))
- (is (= (seq rb-set-by->) (seq avl-set-by->))))
- (testing "reduce-kv returns correct values"
- (is (= (reduce-kv + 0 rb-map) (reduce-kv + 0 avl-map)))
- (is (= (reduce-kv + 0 rb-map-by->) (reduce-kv + 0 avl-map-by->)))))
-
-(deftest standalone-checks
- (testing "seq"
- (is (= (seq avl-map) (map twice ks)))
- (is (= (seq avl-set) ks)))
- (testing "seq on *-by"
- (is (= (seq (apply avl/sorted-map-by > (interleave (range 32) (range 32))))
- (reverse (map (juxt identity identity) (range 32)))))
- (is (= (seq (apply avl/sorted-set-by > (range 32)))
- (reverse (range 32)))))
- (testing "reduce-kv short-circuits appropriately"
- (is (= (reduce-kv (fn [acc k v] (reduced acc)) :foo avl-map) :foo))
- (is (= (reduce-kv (fn [acc k v]
- (if (== (quot large-tree-size 3) k)
- (reduced k)
- acc))
- nil
- avl-map)
- (quot large-tree-size 3)))
- (is (= (let [counter (atom 0)]
- (reduce-kv (fn [acc k v]
- (if (== (quot large-tree-size 3) k)
- (reduced k)
- (swap! counter inc)))
- nil
- avl-map)
- @counter)
- (quot large-tree-size 3)))))
-
-(deftest rank-queries
- (testing "map rank queries work as expected"
- (is (every? true? (map = ks (map #(key (nth avl-map %)) ks))))
- (is (every? true?
- (map = (reverse ks) (map #(key (nth avl-map-by-> %)) ks))))
- (is (->> (map #(nth avl-map-by-> (avl/rank-of avl-map-by-> %)) ks)
- (map first)
- (map = ks)
- (every? true?)))
- (is (every? #(== % -1) (map #(avl/rank-of avl-map %) [-10 123.5 200000]))))
- (testing "set rank queries work as expected"
- (is (every? true? (map = ks (map #(nth avl-set %) ks))))
- (is (every? true? (map = (reverse ks) (map #(nth avl-set-by-> %) ks))))
- (is (->> (map #(nth avl-set-by-> (avl/rank-of avl-set-by-> %)) ks)
- (map = ks)
- (every? true?)))
- (is (every? #(== % -1) (map #(avl/rank-of avl-set %) [-10 123.5 200000]))))
- (testing "rank-of, nth and contains? agree on sets"
- (is (every? (fn [x]
- (or (and (not (contains? even-numbers x))
- (== -1 (avl/rank-of even-numbers x)))
- (and (contains? even-numbers x)
- (== (nth even-numbers (avl/rank-of even-numbers x))
- x))))
- (range (dec (apply min (seq even-numbers)))
- (+ 2 (apply max (seq even-numbers))))))))
-
-(def keys-for-nearest [-1 0 1 2 3 4 5 6 7 8 9])
-(def set-for-nearest (avl/sorted-set 0 2 4 6 8))
-(def rset-for-nearest (avl/sorted-set-by > 0 2 4 6 8))
-
-(defn subseq-nearest [coll test x]
- (let [subseq* (if (#{< <=} test) rsubseq subseq)]
- (first (subseq* coll test x))))
-
-(deftest nearest
- (testing "nearest should find the correct element or nil"
- (doseq [s [set-for-nearest rset-for-nearest]
- t [< <= >= >]]
- (is (= (map #(avl/nearest s t %) keys-for-nearest)
- (map #(subseq-nearest s t %) keys-for-nearest))))))
-
-(def small-ks (range small-tree-size))
-(def small-ksks (doall (interleave small-ks small-ks)))
-
-(def small-avl-set (apply avl/sorted-set small-ks))
-(def small-avl-map (apply avl/sorted-map small-ksks))
-(def small-avl-set-> (apply avl/sorted-set-by > small-ks))
-(def small-avl-map-> (apply avl/sorted-map-by > small-ksks))
-
-(defn subseq-subrange [coll low high]
- (into (empty coll) (subseq coll >= low <= high)))
-
-(deftest subrange
- (testing "subrange should return the correct result"
- (doseq [coll [small-avl-set small-avl-map]
- i (range -1 (inc small-tree-size))
- j (range i (inc small-tree-size))]
- (is (= (avl/subrange coll >= i <= j) (subseq-subrange coll i j))))
- (doseq [coll [small-avl-set-> small-avl-map->]
- i (range small-tree-size -2 -1)
- j (range i -2 -1)]
- (is (= (avl/subrange coll >= i <= j) (subseq-subrange coll i j)))))
- (testing "subrange with single small (<) / large (>) limit should be empty"
- (is (= #{} (avl/subrange small-avl-set <= -1)))
- (is (= #{} (avl/subrange small-avl-set < -1)))
- (is (= #{} (avl/subrange small-avl-set >= small-tree-size)))
- (is (= #{} (avl/subrange small-avl-set > small-tree-size)))
- (is (= {} (avl/subrange small-avl-map <= -1)))
- (is (= {} (avl/subrange small-avl-map < -1)))
- (is (= {} (avl/subrange small-avl-map >= small-tree-size)))
- (is (= {} (avl/subrange small-avl-map > small-tree-size)))))
-
-(defn subseq-split-key [x coll]
- (let [e (empty coll)]
- [(into e (subseq coll < x))
- (if (contains? coll x)
- (if (map? coll)
- (find coll x)
- (get coll x)))
- (into e (subseq coll > x))]))
-
-(defn subseq-split-at [n coll]
- [(into (empty coll) (take n coll))
- (into (empty coll) (drop n coll))])
-
-(deftest split
- (testing "split-key should return the correct result"
- (doseq [coll [small-avl-set small-avl-map
- small-avl-set-> small-avl-map->]
- i (range -1 (inc small-tree-size))]
- (is (= (avl/split-key i coll) (subseq-split-key i coll)))))
- (testing "split-at should return the correct result"
- (doseq [coll [small-avl-set small-avl-map
- small-avl-set-> small-avl-map->]
- i (range 0 (inc small-tree-size))]
- (is (= (avl/split-at i coll) (subseq-split-at i coll))))))
-
-(def midsize-ks (range medium-tree-size))
-
-(deftest avl-invariant
- (testing "AVL invariant is maintained at all times"
- (let [p (atom (avl/sorted-set))
- t (atom (avl/sorted-set))]
- (doseq [k midsize-ks]
- (let [s (swap! p conj k)
- t (swap! t (comp persistent! #(conj! % k) transient))]
- (is (validate-invariant s))
- (is (validate-invariant t))))
- (doseq [k midsize-ks]
- (let [[l _ r] (avl/split-key k @p)
- [l' r'] (avl/split-at k @p)]
- (is (validate-invariant l))
- (is (validate-invariant r))
- (is (validate-invariant l'))
- (is (validate-invariant r'))))
- (doseq [k midsize-ks]
- (let [s (swap! p disj k)
- t (swap! t (comp persistent! #(conj! % k) transient))]
- (is (validate-invariant s))
- (is (validate-invariant t)))))))
-
-(deftest navigable-queries
- (testing "nearest lookups are \"rounded\""
- (doseq [k (drop-last ks)]
- (is (= (avl/nearest even-numbers >= k) (if (odd? k) (inc k) k))))
- (doseq [k (next ks)]
- (is (= (avl/nearest even-numbers <= k) (if (odd? k) (dec k) k)))))
- (testing "out of range keys return nil"
- (is (nil? (avl/nearest avl-map < 0)))
- (is (nil? (avl/nearest avl-set < 0)))
- (is (nil? (avl/nearest avl-map > (key (first (rseq avl-map))))))
- (is (nil? (avl/nearest avl-set > (first (rseq avl-set))))))
- (testing "floor and ceil returns exact match if present"
- (doseq [k ks]
- (is (= (avl/nearest avl-set >= k) k))
- (is (= (avl/nearest avl-set <= k) k))
- (is (= (key (avl/nearest avl-map >= k)) k))
- (is (= (key (avl/nearest avl-map <= k)) k))))
- (testing "lower and higher match the next item"
- (doseq [k (drop-last ks)]
- (is (= (avl/nearest avl-set > k) (inc k)))
- (is (= (key (avl/nearest avl-map > k)) (inc k))))
- (doseq [k (next ks)]
- (is (= (avl/nearest avl-set < k) (dec k)))
- (is (= (key (avl/nearest avl-map < k)) (dec k))))))
-
-(deftest bad-args
- (testing "sorted-map and sorted-map-by expect val for every key"
- (is (= "sorted-map: no value supplied for key: :b"
- (try (avl/sorted-map :a 1 :b)
- (catch :default e
- (ex-message e)))))
- (is (= "sorted-map-by: no value supplied for key: :b"
- (try (avl/sorted-map-by < :a 1 :b)
- (catch :default e
- (ex-message e)))))))
-
-(deftest ireduce
- (testing "No-init sorted-map reduction works as expected"
- (is (= (reduce (fn [] :none) (avl/sorted-map)) :none)
- "0-Arity of reduction fn called for empty sorted-map")
- (is (= (reduce (fn []) (avl/sorted-map 1 2)) [1 2])
- "Reduction function not called for 1-element sorted-map, item returned")
- (is (= (reduce into (avl/sorted-map 1 2 3 4 5 6)) [1 2 3 4 5 6])
- "Reduction is in correct order with correct contents."))
- (testing "Init-ed sorted-map reduction works as expected"
- (is (= (reduce conj [] (avl/sorted-map))) [])
- (is (= (reduce conj [] (avl/sorted-map 1 2)) [[1 2]]))
- (is (= (reduce conj [] (avl/sorted-map 1 2 3 4 5 6)) [[1 2] [3 4] [5 6]])))
- (testing "No-init sorted-set reduction works as expected"
- (is (= (reduce (fn [] :none) (avl/sorted-set)) :none)
- "0-Arity of reduction fn called for empty sorted-set")
- (is (= (reduce (fn []) (avl/sorted-set 1)) 1)
- "Reduction function not called for 1-element sorted-set, item returned")
- (is (= (reduce (fn [a v] (conj (if (number? a) [a] a) v))
- (avl/sorted-set 1 2 3 4 5 6)) [1 2 3 4 5 6])
- "Reduction is in correct order with correct contents."))
- (testing "Init-ed sorted-set reduction works as expected"
- (is (= (reduce conj [] (avl/sorted-set)) []))
- (is (= (reduce conj [] (avl/sorted-set 1)) [1]))
- (is (= (reduce conj [] (avl/sorted-set 1 2 3 4 5 6)) [1 2 3 4 5 6]))))
diff --git a/src/test/cljs/clojure/data/avl_test_runner.cljs b/src/test/cljs/clojure/data/avl_test_runner.cljs
deleted file mode 100644
index 3b8268d..0000000
--- a/src/test/cljs/clojure/data/avl_test_runner.cljs
+++ /dev/null
@@ -1,12 +0,0 @@
-(ns clojure.data.avl-test-runner
- (:require [cljs.test :refer-macros [run-tests]]
- clojure.data.avl-check
- clojure.data.avl-split-key-test
- clojure.data.avl-test))
-
-
-(enable-console-print!)
-
-(run-tests 'clojure.data.avl-test
- 'clojure.data.avl-check
- 'clojure.data.avl-split-key-test)
diff --git a/src/test/clojure/clojure/data/avl/cljs_test_macros.clj b/src/test/clojure/clojure/data/avl/cljs_test_macros.clj
deleted file mode 100644
index 1eae197..0000000
--- a/src/test/clojure/clojure/data/avl/cljs_test_macros.clj
+++ /dev/null
@@ -1,27 +0,0 @@
-(ns clojure.data.avl.cljs-test-macros
- (:require [clojure.walk :as walk]))
-
-(def tests (atom []))
-
-(defmacro deftest [name & body]
- (swap! tests conj
- (symbol (clojure.core/name (.-name *ns*)) (clojure.core/name name)))
- `(defn ~name []
- ~@(walk/prewalk (fn [f]
- (if (seq? f)
- (condp = (first f)
- 'is (cons 'assert (next f))
- 'testing (list* 'do
- (list 'println (second f))
- (nnext f))
- f)
- f))
- body)))
-
-(defmacro run-tests []
- `(do ~'(set-print-fn! js/print)
- (~'this-as ~'this
- (let [tests# ~(deref tests)]
- (doseq [t# tests#]
- (t#))))
- (println "Tests completed without exception.")))
diff --git a/src/test/clojure/clojure/data/avl_test.clj b/src/test/clojure/clojure/data/avl_test.clj
deleted file mode 100644
index bbda758..0000000
--- a/src/test/clojure/clojure/data/avl_test.clj
+++ /dev/null
@@ -1,298 +0,0 @@
-(ns clojure.data.avl-test
- (:use clojure.test)
- (:require [clojure.data.avl :as avl]))
-
-
-(defmacro deftreesize [name default]
- `(def ~name
- (if-let [size# (System/getProperty
- ~(str "org.clojure.data.avl.test." name))]
- (Long/parseLong size#)
- ~default)))
-
-(deftreesize small-tree-size 150)
-(deftreesize medium-tree-size 2500)
-(deftreesize large-tree-size 10000)
-
-(defn validate-invariant [^clojure.data.avl.IAVLTree coll]
- (let [tree (.getTree coll)
- h (fn [^clojure.data.avl.IAVLNode node]
- (if node
- (.getHeight node)
- 0))]
- (or (nil? tree)
- (boolean
- (#{-1 0 1} (- (h (.getLeft tree)) (h (.getRight tree))))))))
-
-(defn twice [x]
- [x x])
-
-(def ks (range large-tree-size))
-(def ksks (doall (interleave ks ks)))
-(def ks' (doall (map first (partition 2 ks))))
-
-(def rb-map (apply sorted-map ksks))
-(def avl-map (apply avl/sorted-map ksks))
-
-(def rb-set (apply sorted-set ks))
-(def avl-set (apply avl/sorted-set ks))
-
-(def rb-map-by-> (apply sorted-map-by > ksks))
-(def avl-map-by-> (apply avl/sorted-map-by > ksks))
-
-(def rb-set-by-> (apply sorted-set-by > ks))
-(def avl-set-by-> (apply avl/sorted-set-by > ks))
-
-(def even-numbers (apply avl/sorted-set (range 0 large-tree-size 2)))
-
-(defn is-same-coll [a b]
- (let [msg (format "(class a)=%s (class b)=%s a=%s b=%s"
- (.getName (class a)) (.getName (class b)) a b)
- size (fn [x]
- (if (map? x)
- (.size ^java.util.Map x)
- (.size ^java.util.Set x)))]
- (is (= (count a) (count b) (size a) (size b)) msg)
- (is (= a b) msg)
- (is (= b a) msg)
- (is (.equals ^Object a b) msg)
- (is (.equals ^Object b a) msg)
- (is (= (hash a) (hash b)) msg)
- (is (= (.hashCode ^Object a) (.hashCode ^Object b)) msg)))
-
-(deftest sanity-checks
- (testing "AVL collections look like regular sorted collections"
- (is-same-coll rb-map avl-map)
- (is-same-coll rb-set avl-set)
- ;; Check empty maps are equal, and hashes equal
- (is-same-coll (empty rb-map) (empty avl-map))
- (is-same-coll (empty rb-set) (empty avl-set)))
- (testing "AVL collections with custom comparators looks like regular ones"
- (is-same-coll rb-map-by-> avl-map-by->)
- (is-same-coll rb-set-by-> avl-set-by->))
- (testing "AVL collection seqs look like regular sorted collection seqs"
- (is (= (seq rb-map) (seq avl-map)))
- (is (= (seq rb-set) (seq avl-set)))
- (is (= (subseq rb-map > 100 < 1000) (subseq avl-map > 100 < 1000)))
- (is (= (subseq rb-set > 100 < 1000) (subseq avl-set > 100 < 1000))))
- (testing "non-transient construction works as expected"
- (is-same-coll avl-map (reduce-kv assoc (avl/sorted-map) rb-map)))
- (testing "dissoc/dissoc! work as expected"
- (is-same-coll (reduce dissoc rb-map ks') (reduce dissoc avl-map ks'))
- (is-same-coll (reduce dissoc rb-map ks')
- (persistent! (reduce dissoc! (transient avl-map) ks'))))
- (testing "disj/disj! work as expected"
- (is-same-coll (reduce disj rb-set ks') (reduce disj avl-set ks'))
- (is-same-coll (reduce disj rb-set ks')
- (persistent! (reduce disj! (transient avl-set) ks'))))
- (testing "*-by seqs look like they should"
- (is (= (seq rb-map-by->) (seq avl-map-by->)))
- (is (= (seq rb-set-by->) (seq avl-set-by->))))
- (testing "reduce-kv returns correct values"
- (is (= (reduce-kv + 0 rb-map) (reduce-kv + 0 avl-map)))
- (is (= (reduce-kv + 0 rb-map-by->) (reduce-kv + 0 avl-map-by->)))))
-
-(deftest standalone-checks
- (testing "seq"
- (is (= (seq avl-map) (map twice ks)))
- (is (= (seq avl-set) ks)))
- (testing "seq on *-by"
- (is (= (seq (apply avl/sorted-map-by > (interleave (range 32) (range 32))))
- (reverse (map (juxt identity identity) (range 32)))))
- (is (= (seq (apply avl/sorted-set-by > (range 32)))
- (reverse (range 32)))))
- (testing "reduce-kv short-circuits appropriately"
- (is (= (reduce-kv (fn [acc k v] (reduced acc)) :foo avl-map) :foo))
- (is (= (reduce-kv (fn [acc k v]
- (if (== (quot large-tree-size 3) k)
- (reduced k)
- acc))
- nil
- avl-map)
- (quot large-tree-size 3)))
- (is (= (let [counter (atom 0)]
- (reduce-kv (fn [acc k v]
- (if (== (quot large-tree-size 3) k)
- (reduced k)
- (swap! counter inc)))
- nil
- avl-map)
- @counter)
- (quot large-tree-size 3)))))
-
-(deftest rank-queries
- (testing "map rank queries work as expected"
- (is (every? true? (map = ks (map #(key (nth avl-map %)) ks))))
- (is (every? true?
- (map = (reverse ks) (map #(key (nth avl-map-by-> %)) ks))))
- (is (->> (map #(nth avl-map-by-> (avl/rank-of avl-map-by-> %)) ks)
- (map first)
- (map = ks)
- (every? true?)))
- (is (every? #(== % -1) (map #(avl/rank-of avl-map %) [-10 123.5 200000]))))
- (testing "set rank queries work as expected"
- (is (every? true? (map = ks (map #(nth avl-set %) ks))))
- (is (every? true? (map = (reverse ks) (map #(nth avl-set-by-> %) ks))))
- (is (->> (map #(nth avl-set-by-> (avl/rank-of avl-set-by-> %)) ks)
- (map = ks)
- (every? true?)))
- (is (every? #(== % -1) (map #(avl/rank-of avl-set %) [-10 123.5 200000]))))
- (testing "rank-of, nth and contains? agree on sets"
- (is (every? (fn [x]
- (or (and (not (contains? even-numbers x))
- (== -1 (avl/rank-of even-numbers x)))
- (and (contains? even-numbers x)
- (== (nth even-numbers (avl/rank-of even-numbers x))
- x))))
- (range (dec (apply min (seq even-numbers)))
- (+ 2 (apply max (seq even-numbers))))))))
-
-(def keys-for-nearest [-1 0 1 2 3 4 5 6 7 8 9])
-(def set-for-nearest (avl/sorted-set 0 2 4 6 8))
-(def rset-for-nearest (avl/sorted-set-by > 0 2 4 6 8))
-
-(defn subseq-nearest [coll test x]
- (let [subseq* (if (#{< <=} test) rsubseq subseq)]
- (first (subseq* coll test x))))
-
-(deftest nearest
- (testing "nearest should find the correct element or nil"
- (doseq [s [set-for-nearest rset-for-nearest]
- t [< <= >= >]]
- (is (= (map #(avl/nearest s t %) keys-for-nearest)
- (map #(subseq-nearest s t %) keys-for-nearest))))))
-
-(def small-ks (range small-tree-size))
-(def small-ksks (doall (interleave small-ks small-ks)))
-
-(def small-avl-set (apply avl/sorted-set small-ks))
-(def small-avl-map (apply avl/sorted-map small-ksks))
-(def small-avl-set-> (apply avl/sorted-set-by > small-ks))
-(def small-avl-map-> (apply avl/sorted-map-by > small-ksks))
-
-(defn subseq-subrange [coll low high]
- (into (empty coll) (subseq coll >= low <= high)))
-
-(deftest subrange
- (testing "subrange should return the correct result"
- (doseq [coll [small-avl-set small-avl-map]
- i (range -1 (inc small-tree-size))
- j (range i (inc small-tree-size))]
- (is (= (avl/subrange coll >= i <= j) (subseq-subrange coll i j))))
- (doseq [coll [small-avl-set-> small-avl-map->]
- i (range small-tree-size -2 -1)
- j (range i -2 -1)]
- (is (= (avl/subrange coll >= i <= j) (subseq-subrange coll i j)))))
- (testing "subrange with single small (<) / large (>) limit should be empty"
- (is (= #{} (avl/subrange small-avl-set <= -1)))
- (is (= #{} (avl/subrange small-avl-set < -1)))
- (is (= #{} (avl/subrange small-avl-set >= small-tree-size)))
- (is (= #{} (avl/subrange small-avl-set > small-tree-size)))
- (is (= {} (avl/subrange small-avl-map <= -1)))
- (is (= {} (avl/subrange small-avl-map < -1)))
- (is (= {} (avl/subrange small-avl-map >= small-tree-size)))
- (is (= {} (avl/subrange small-avl-map > small-tree-size)))))
-
-(defn subseq-split-key [x coll]
- (let [e (empty coll)]
- [(into e (subseq coll < x))
- (if (contains? coll x)
- (if (map? coll)
- (find coll x)
- (get coll x)))
- (into e (subseq coll > x))]))
-
-(defn subseq-split-at [n coll]
- [(into (empty coll) (take n coll))
- (into (empty coll) (drop n coll))])
-
-(deftest split
- (testing "split-key should return the correct result"
- (doseq [coll [small-avl-set small-avl-map
- small-avl-set-> small-avl-map->]
- i (range -1 (inc small-tree-size))]
- (is (= (avl/split-key i coll) (subseq-split-key i coll)))))
- (testing "split-at should return the correct result"
- (doseq [coll [small-avl-set small-avl-map
- small-avl-set-> small-avl-map->]
- i (range 0 (inc small-tree-size))]
- (is (= (avl/split-at i coll) (subseq-split-at i coll))))))
-
-(def midsize-ks (range medium-tree-size))
-
-(deftest avl-invariant
- (testing "AVL invariant is maintained at all times"
- (let [p (atom (avl/sorted-set))
- t (atom (avl/sorted-set))]
- (doseq [k midsize-ks]
- (let [s (swap! p conj k)
- t (swap! t (comp persistent! #(conj! % k) transient))]
- (is (validate-invariant s))
- (is (validate-invariant t))))
- (doseq [k midsize-ks]
- (let [[l _ r] (avl/split-key k @p)
- [l' r'] (avl/split-at k @p)]
- (is (validate-invariant l))
- (is (validate-invariant r))
- (is (validate-invariant l'))
- (is (validate-invariant r'))))
- (doseq [k midsize-ks]
- (let [s (swap! p disj k)
- t (swap! t (comp persistent! #(conj! % k) transient))]
- (is (validate-invariant s))
- (is (validate-invariant t)))))))
-
-(deftest navigable-queries
- (testing "nearest lookups are \"rounded\""
- (doseq [k (drop-last ks)]
- (is (= (avl/nearest even-numbers >= k) (if (odd? k) (inc k) k))))
- (doseq [k (next ks)]
- (is (= (avl/nearest even-numbers <= k) (if (odd? k) (dec k) k)))))
- (testing "out of range keys return nil"
- (is (nil? (avl/nearest avl-map < 0)))
- (is (nil? (avl/nearest avl-set < 0)))
- (is (nil? (avl/nearest avl-map > (key (first (rseq avl-map))))))
- (is (nil? (avl/nearest avl-set > (first (rseq avl-set))))))
- (testing "floor and ceil returns exact match if present"
- (doseq [k ks]
- (is (= (avl/nearest avl-set >= k) k))
- (is (= (avl/nearest avl-set <= k) k))
- (is (= (key (avl/nearest avl-map >= k)) k))
- (is (= (key (avl/nearest avl-map <= k)) k))))
- (testing "lower and higher match the next item"
- (doseq [k (drop-last ks)]
- (is (= (avl/nearest avl-set > k) (inc k)))
- (is (= (key (avl/nearest avl-map > k)) (inc k))))
- (doseq [k (next ks)]
- (is (= (avl/nearest avl-set < k) (dec k)))
- (is (= (key (avl/nearest avl-map < k)) (dec k))))))
-
-(deftest bad-args
- (testing "sorted-map and sorted-map-by expect val for every key"
- (is (thrown? IllegalArgumentException (avl/sorted-map :a 1 :b)))
- (is (thrown? IllegalArgumentException (avl/sorted-map-by < :a 1 :b)))))
-
-(deftest coll-reduce
- (testing "No-init sorted-map reduction works as expected"
- (is (= (reduce (fn [] :none) (avl/sorted-map)) :none)
- "0-Arity of reduction fn called for empty sorted-map")
- (is (= (reduce (fn []) (avl/sorted-map 1 2)) [1 2])
- "Reduction function not called for 1-element sorted-map, item returned")
- (is (= (reduce into (avl/sorted-map 1 2 3 4 5 6)) [1 2 3 4 5 6])
- "Reduction is in correct order with correct contents."))
- (testing "Init-ed sorted-map reduction works as expected"
- (is (= (reduce conj [] (avl/sorted-map)) []))
- (is (= (reduce conj [] (avl/sorted-map 1 2)) [[1 2]]))
- (is (= (reduce conj [] (avl/sorted-map 1 2 3 4 5 6)) [[1 2] [3 4] [5 6]])))
- (testing "No-init sorted-set reduction works as expected"
- (is (= (reduce (fn [] :none) (avl/sorted-set)) :none)
- "0-Arity of reduction fn called for empty sorted-set")
- (is (= (reduce (fn []) (avl/sorted-set 1)) 1)
- "Reduction function not called for 1-element sorted-set, item returned")
- (is (= (reduce (fn [a v] (conj (if (number? a) [a] a) v))
- (avl/sorted-set 1 2 3 4 5 6)) [1 2 3 4 5 6])
- "Reduction is in correct order with correct contents."))
- (testing "Init-ed sorted-set reduction works as expected"
- (is (= (reduce conj [] (avl/sorted-set)) []))
- (is (= (reduce conj [] (avl/sorted-set 1)) [1]))
- (is (= (reduce conj [] (avl/sorted-set 1 2 3 4 5 6)) [1 2 3 4 5 6]))))
diff --git a/src/test_local/cljc/clojure/data/avl_check.cljc b/src/test_local/cljc/clojure/data/avl_check.cljc
deleted file mode 100644
index 0665662..0000000
--- a/src/test_local/cljc/clojure/data/avl_check.cljc
+++ /dev/null
@@ -1,219 +0,0 @@
-(ns clojure.data.avl-check
- (:require [clojure.data.avl :as avl]
- #?(:clj [collection-check.core
- :refer [assert-map-like assert-set-like
- assert-equivalent-maps assert-equivalent-sets]])
- #?(:cljs clojure.test.check)
- [clojure.test.check.clojure-test
- #?@(:clj [:refer [defspec]]
- :cljs [:refer-macros [defspec]])]
- [clojure.test.check.generators :as gen]
- [clojure.test.check.properties :as prop
- #?@(:cljs [:include-macros true])])
- (:use #?@(:clj [[clojure.template :only [do-template]]
- clojure.test]
- :cljs [[cljs.test :only [deftest testing are]]])))
-
-(def igen gen/int)
-
-#?(:clj
- (deftest collection-check
- (do-template [x] (assert-map-like x igen igen)
- (avl/sorted-map)
- (avl/sorted-map-by >))
- (do-template [x] (assert-set-like x igen)
- (avl/sorted-set)
- (avl/sorted-set-by >))))
-
-#?(:cljs
- (defn assert-equivalent-sets [s1 s2]
- (and (= s1 s2)
- (= s2 s1)
- (== (count s1) (count s2)))))
-
-(defn validate-tree
- ([tree]
- (if (or (map? tree) (set? tree))
- (do
- (assert (== (count tree)
- (peek (validate-tree
- #?(:clj (.comparator ^clojure.lang.Sorted tree)
- :cljs (-comparator tree))
- (.getTree #?(:clj ^clojure.data.avl.IAVLTree tree
- :cljs tree))))))
- true)
- (validate-tree #?(:clj clojure.lang.RT/DEFAULT_COMPARATOR
- :cljs compare)
- tree)))
- (#?(:clj [^java.util.Comparator comp ^clojure.data.avl.IAVLNode tree]
- :cljs [comp tree])
- (if (nil? tree)
- [0 0]
- (let [left (.getLeft tree)
- right (.getRight tree)
- [lh lcnt] (validate-tree comp left)
- [rh rcnt] (validate-tree comp right)
- h (inc (max lh rh))]
- (if left
- (assert (neg? (#?(:clj .compare) comp
- (.getKey left) (.getKey tree)))))
- (if right
- (assert (neg? (#?(:clj .compare) comp
- (.getKey tree) (.getKey right)))))
- (assert (#{-1 0 1} (- lh rh)))
- (assert (== lh (#?(:clj #'avl/height :cljs avl/height) left)))
- (assert (== rh (#?(:clj #'avl/height :cljs avl/height) right)))
- (assert (== lcnt (.getRank tree)))
- (assert (== h (.getHeight tree)))
- [h (inc (+ lcnt rcnt))]))))
-
-(defspec avl-invariant 100
- (testing "AVL invariant is maintained when inserting keys in random order"
- (prop/for-all [ks (gen/vector gen/int)]
- (try
- (validate-tree (apply avl/sorted-set ks))
- (validate-tree (apply avl/sorted-set-by > ks))
- (validate-tree (reduce conj (avl/sorted-set) ks))
- (validate-tree (reduce conj (avl/sorted-set-by >) ks))
- true
- (catch #?(:clj AssertionError :cljs :default) _
- false)))))
-
-(defspec avl-invariant-500 100
- (testing "AVL invariant is maintained when inserting 500 keys in random order"
- (prop/for-all [ks (gen/shuffle (range 500))]
- (try
- (validate-tree (apply avl/sorted-set ks))
- (validate-tree (apply avl/sorted-set-by > ks))
- (validate-tree (reduce conj (avl/sorted-set) ks))
- (validate-tree (reduce conj (avl/sorted-set-by >) ks))
- true
- (catch #?(:clj AssertionError :cljs :default) _
- false)))))
-
-(defn disj!-all [coll ks]
- (persistent! (reduce disj! (transient coll) ks)))
-
-(defn disj-all [coll ks]
- (reduce disj coll ks))
-
-(defspec avl-invariant-with-removals 100
- (testing "AVL invariant is maintained when inserting & removing keys"
- (prop/for-all [[ks ks']
- (gen/fmap (fn [ks]
- [ks (subvec ks (quot (count ks) 2))])
- (gen/vector gen/int))]
- (try
- (validate-tree (disj!-all (apply avl/sorted-set ks) ks'))
- (validate-tree (disj!-all (apply avl/sorted-set-by > ks) ks'))
- (validate-tree (disj-all (reduce conj (avl/sorted-set) ks) ks'))
- (validate-tree (disj-all (reduce conj (avl/sorted-set-by >) ks) ks'))
- true
- (catch #?(:clj AssertionError :cljs :default) _
- false)))))
-
-#?(:clj
- (defspec print-dup-map-round-trip 100
- (prop/for-all [xs (gen/vector gen/int)]
- (let [m1 (into (avl/sorted-map) (map #(vector % %) xs))
- m2 (read-string (with-out-str (print-dup m1 *out*)))]
- (try
- (assert-equivalent-maps m1 m2)
- true
- (catch AssertionError _
- false))))))
-
-#?(:clj
- (defspec print-dup-set-round-trip 100
- (prop/for-all [xs (gen/vector gen/int)]
- (let [s1 (into (avl/sorted-set) xs)
- s2 (read-string (with-out-str (print-dup s1 *out*)))]
- (try
- (assert-equivalent-sets s1 s2)
- true
- (catch AssertionError _
- false))))))
-
-(defspec reduce-set 100
- (prop/for-all [xs (gen/vector gen/int)]
- (let [s (into (avl/sorted-set) xs)]
- (= (reduce + s)
- (reduce + 0 s)
- (reduce + 0 (distinct xs))))))
-
-(defspec reduce-map 100
- (prop/for-all [xs (gen/vector gen/int)]
- (let [m (reduce (fn [out x] (assoc out x x)) (avl/sorted-map) xs)
- f (fn
- ([] [])
- ([out] out)
- ([out [k v]] (conj out k v)))]
- (= (reduce f m)
- (reduce f [] m)
- (reduce f [] (map #(vector % %) (sort (distinct xs))))))))
-
-(defspec subrange-subseq 100
- (prop/for-all [xs (gen/vector gen/int)
- i gen/int
- j gen/int]
- (let [low (min i j)
- high (max i j)
- s1 (into (avl/sorted-set) xs)
- s2 (into (sorted-set) xs)]
- (= (seq (avl/subrange s1 >= low <= high))
- (seq (subseq s1 >= low <= high))
- (seq (subseq s2 >= low <= high))))))
-
-(defspec subrange-low-reduce 100
- (prop/for-all [xs (gen/vector gen/int)
- low gen/int]
- (let [s1 (into (avl/sorted-set) xs)
- s2 (into (sorted-set) xs)
- sub1 (into #{}
- (map inc)
- (avl/subrange s1 >= low))
- sub2 (into #{}
- (map inc)
- (subseq s2 >= low))]
- (try
- (assert-equivalent-sets sub1 sub2)
- true
- (catch #?(:clj AssertionError :cljs :default) _
- false)))))
-
-(defspec subrange-high-reduce 100
- (prop/for-all [xs (gen/vector gen/int)
- high gen/int]
- (let [s1 (into (avl/sorted-set) xs)
- s2 (into (sorted-set) xs)
- sub1 (into #{}
- (map inc)
- (avl/subrange s1 <= high))
- sub2 (into #{}
- (map inc)
- (subseq s2 <= high))]
- (try
- (assert-equivalent-sets sub1 sub2)
- true
- (catch #?(:clj AssertionError :cljs :default) _
- false)))))
-
-(defspec subrange-low-high-reduce 100
- (prop/for-all [xs (gen/vector gen/int)
- i gen/int
- j gen/int]
- (let [low (min i j)
- high (max i j)
- s1 (into (avl/sorted-set) xs)
- s2 (into (sorted-set) xs)
- sub1 (into #{}
- (map inc)
- (avl/subrange s1 >= low <= high))
- sub2 (into #{}
- (map inc)
- (subseq s2 >= low <= high))]
- (try
- (assert-equivalent-sets sub1 sub2)
- true
- (catch #?(:clj AssertionError :cljs :default) _
- false)))))
diff --git a/src/test_local/cljc/clojure/data/avl_split_key_test.cljc b/src/test_local/cljc/clojure/data/avl_split_key_test.cljc
deleted file mode 100644
index 1ffc22b..0000000
--- a/src/test_local/cljc/clojure/data/avl_split_key_test.cljc
+++ /dev/null
@@ -1,45 +0,0 @@
-(ns clojure.data.avl-split-key-test
- (:require [clojure.data.avl :as avl]
- [clojure.test :refer [is]]
- [clojure.test.check.clojure-test :refer [defspec]]
- [clojure.test.check.generators :as gen]
- [clojure.test.check.properties :as prop]))
-
-(def gen-distinct-vec
- (gen/fmap (comp vec distinct) (gen/vector gen/int)))
-
-(def gen-sorted-map
- (->> gen-distinct-vec
- (gen/fmap #(apply avl/sorted-map
- (interleave (sort %) (range (count %)))))
- (gen/such-that #(not (empty? %)))))
-
-(defn range-low-high [from to m]
- (let [[_ eq1 gt] (avl/split-key from m)
- [lt eq2 _] (avl/split-key to gt)]
- (cond-> lt
- eq1 (conj eq1)
- eq2 (conj eq2))))
-
-(defn range-high-low [from to m]
- (let [[lt eq1 _] (avl/split-key to m)
- [_ eq2 gt] (avl/split-key from lt)]
- (cond-> gt
- eq1 (conj eq1)
- eq2 (conj eq2))))
-
-(defspec spec-range-low-high
- (prop/for-all
- [[from to] (gen/fmap sort (gen/tuple gen/int gen/int))
- m gen-sorted-map]
- (let [ks (vec (keys m))]
- (is (= (seq (filter #(<= from % to) (keys m)))
- (seq (keys (range-low-high from to m))))))))
-
-(defspec spec-range-high-low
- (prop/for-all
- [[from to] (gen/fmap sort (gen/tuple gen/int gen/int))
- m gen-sorted-map]
- (let [ks (vec (keys m))]
- (is (= (seq (filter #(<= from % to) (keys m)))
- (seq (keys (range-high-low from to m))))))))
diff --git a/static/clojure-icon.gif b/static/clojure-icon.gif
new file mode 100644
index 0000000..84eee16
Binary files /dev/null and b/static/clojure-icon.gif differ
diff --git a/static/clojure.css b/static/clojure.css
new file mode 100644
index 0000000..d40ea35
--- /dev/null
+++ b/static/clojure.css
@@ -0,0 +1,53 @@
+
+body {margin: 0;padding: 0;background-color: #e3e3e3;border-top: 4px solid #b3ccfe;color: #272727}
+body, .wiki, #Content, .wikipage {font-family: "Lucida Grande","Trebuchet MS","Bitstream Vera Sans",Verdana,Helvetica,sans-serif;font-size: 12px;line-height: 18px;}
+#leftcolumn .wiki_link, #toc, #toc a, .toc-header {font-size: 11px;line-height: 18px;text-decoration: none}
+img {border: 0;}
+#AllContentContainer {max-width: 96em;min-width: 663px;background: #fff url(space/content-background.gif) right repeat-y;padding: 0 40px 18px 0;}
+
+#Header {position: relative;clear: both;overflow: auto;height: 110px}
+#Logo {position: absolute;top: 0;left: 0;padding: 10px 0 0 62px;width: 138px;height: 100px}
+#Header h1 {float: left;border: 0;margin: 0;padding: 0;position: absolute;top: 50;left: 200px; height: 60px}
+#Header h1 a:link, #Header h1 a:visited, #Header h1 a:hover {color:#000000; text-decoration: none;}
+#Resources {min-height: 110px;width: 234px;padding: 5px 0;float: right;border-bottom: 1px solid #abc4e2;background: #e4eaf7 url(space/resources-background.gif) repeat-y;overflow: auto;}
+#Resources ul {margin: 0;padding: 0 25px;list-style: none;}
+#ResourcesB {float: right;}
+#Resources a {text-decoration: none;}
+#Resources a:link, #Resources a:visited, #Resources a:hover, #Resources a:active {color: #4c5770;}
+#Resources a:hover {text-decoration: underline;}
+
+#leftcolumn {margin: 0 0 0 22px;float: left;width: 168px;padding-bottom: 18px;background: #c5d2eb url(space/left-nav-bottom.gif) bottom no-repeat;}
+
+#leftcolumn ul {list-style: none;margin: 0;padding: 0;}
+
+#leftcolumn a, #leftcolumn .toc-header {font-weight: bold;display: block;background: transparent url(space/left-nav-divider.gif) repeat-x;padding: 6px 0 0 17px;margin: 12px 0 0 0;}
+#leftcolumn li a {font-weight: normal;background:none;margin: 0;padding: 0 0 0 17px;}
+#leftcolumn br {display: none;}
+#leftcolumn .menu {margin-top: 14px;background: #fff url(space/left-nav-background.gif) repeat-y;}
+
+#leftcolumn a:link , #leftcolumn a:visited , #leftcolumn a:active {color: #666;}
+#leftcolumn a:hover {text-decoration: underline;color: #222;}
+
+#rightcolumn {margin-left: 220px;}
+
+.wiki #toc {border: none;margin: 0 0 30px 18px;width: 222px;padding: 0 0 17px 12px;background: transparent url(space/toc-background.gif) repeat-y;border-bottom: 1px solid #d6d6d6;}
+.wiki #toc h1, .wiki #toc div {margin: 0;padding: 0;}
+.wiki #toc h1 {font-size: 14px;line-height: 18px;font-family: Georgia, "Times New Roman", Times, serif;font-style: italic;font-weight: normal;color: #969696;padding: 10px 0 8px 11px;}
+.wiki #toc a:link, .wiki #toc a:visited, .wiki #toc a:active {color: #646464;}
+.wiki #toc a:hover {background: none;color: #333333;}
+
+.wiki pre {font-family: Inconsolata, Monaco, Consolas, "Lucida Console", "Courier New", Courier, monospace;background-color: transparent;border: 0px;color: #000000}
+#DesignedBy { clear: both; text-align: right; margin-top: 18px;}
+#DesignedBy, #DesignedBy a, #DesignedBy a:link, #DesignedBy a:visited, #DesignedBy a:hover, #DesignedBy a:active { color: #999; }
+
+#WikiHeaderNavContainer { height: 36px; position: relative; }
+#leftcolumn .WikiActions a {display: inline;}
+
+.comment { color: gray; }
+.string { color: teal; }
+.function { color: #00c; }
+.macro, .specialops { color: #60c; }
+.parens { color: #000; }
+.keyword { color: #c09; }
+.brackets { color: #006; }
+.curlybrackets { color: #906; }
diff --git a/static/favicon.png b/static/favicon.png
new file mode 100644
index 0000000..b1653e8
Binary files /dev/null and b/static/favicon.png differ
diff --git a/static/internal.css b/static/internal.css
new file mode 100644
index 0000000..08ce7fb
--- /dev/null
+++ b/static/internal.css
@@ -0,0 +1,18 @@
+/* *** MISC STUFF USED ALL OVER *** */
+.nowrap { white-space: nowrap; }
+.hidden { display: none; }
+tr td .sm { font-size: 90%; }
+.grey { color: #666; }
+.smgrey { color: #666; font-size: 80%; }
+.grey a { color: #666; }
+.textentry { font-family: arial, helvetica, sans-serif; border: 1px solid #999; }
+.nopad { padding: 0; margin: 0; }
+.bblack { color: #000; font-size: 1.1em; font-weight: bold; }
+.bblacklight { color: #000; font-size: 1.1em; }
+
+/* IE6 min-height: http://www.dustindiaz.com/min-height-fast-hack */
+#content_view { display: block; padding-bottom: 2em; width: 100%; min-height: 600px; height: auto !important; height: 600px; }
+
+/* Used with .innerContentBox and #WikiAds to position the ad column */
+.contentBox { position: relative; min-height: 600px; height: auto !important; height: 600px; }
+
diff --git a/static/space/content-background.gif b/static/space/content-background.gif
new file mode 100644
index 0000000..0786c72
Binary files /dev/null and b/static/space/content-background.gif differ
diff --git a/static/space/left-nav-background.gif b/static/space/left-nav-background.gif
new file mode 100644
index 0000000..e6e5904
Binary files /dev/null and b/static/space/left-nav-background.gif differ
diff --git a/static/space/left-nav-bottom.gif b/static/space/left-nav-bottom.gif
new file mode 100644
index 0000000..061c089
Binary files /dev/null and b/static/space/left-nav-bottom.gif differ
diff --git a/static/space/left-nav-divider.gif b/static/space/left-nav-divider.gif
new file mode 100644
index 0000000..1854e56
Binary files /dev/null and b/static/space/left-nav-divider.gif differ
diff --git a/static/space/resources-background.gif b/static/space/resources-background.gif
new file mode 100644
index 0000000..9657769
Binary files /dev/null and b/static/space/resources-background.gif differ
diff --git a/static/space/toc-background.gif b/static/space/toc-background.gif
new file mode 100644
index 0000000..0b7c95b
Binary files /dev/null and b/static/space/toc-background.gif differ
diff --git a/static/wiki.css b/static/wiki.css
new file mode 100644
index 0000000..1cb1bdd
--- /dev/null
+++ b/static/wiki.css
@@ -0,0 +1,22 @@
+/* Wiki Rendered Styles */
+.wiki { line-height: 150%; font-family: arial, helvetica, sans-serif; font-size: small; }
+.wiki h1 { font-weight: bold; padding: 5px 0 0 0; margin: 0; font-size: 1.4em; }
+.wiki h2 { font-weight: bold; padding: 5px 0 0 0; margin: 0; font-size: 1.3em; }
+.wiki h3 { font-weight: bold; padding: 5px 0 0 0; margin: 0; font-size: 1.1em; }
+.wiki h4 { font-weight: normal; padding: 5px 0 0 0; margin: 0; font-size: 1.066em; }
+.wiki h5 { font-weight: normal; padding: 5px 0 0 0; margin: 0; font-size: 1.033em; }
+.wiki h6 { font-weight: normal; padding: 5px 0 0 0; margin: 0; font-size: 1.0em; }
+.wiki table { border-collapse: collapse; margin: 10px 0; font-size: small; }
+.wiki p { margin: 0; padding: 0; padding: 5px 0; }
+.wiki td { border: 1px solid #DDD; }
+.wiki #toc { border: 1px solid #AAA; background: #fff; padding: 5px; margin: 0 0 10px 10px; width: 25%; float: right; clear: right;}
+.wiki #toc h1 { font-weight: normal; font-size: 1.2em; padding: 0; }
+.wiki #toc a:hover { color: #00D; background: #FFD; }
+
+.wiki hr { height: 1px; color: #AAA; background-color: #AAA; border: 0; margin: 0 10px; }
+.wiki ul { padding: .5em 0 0 3em; margin: 0; }
+.wiki ol { padding: .5em 0 0 3em; margin: 0; }
+.wiki ul.quotelist { list-style: none; }
+.wiki tt { font-size: small; }
+.wiki img { border: 0; padding: 4px; }
+