25 | "License" shall mean the terms and conditions for use, reproduction,
26 | and distribution as defined by Sections 1 through 9 of this document.
27 |
28 |
29 |
30 | "Licensor" shall mean the copyright owner or entity authorized by
31 | the copyright owner that is granting the License.
32 |
33 |
34 |
35 | "Legal Entity" shall mean the union of the acting entity and all
36 | other entities that control, are controlled by, or are under common
37 | control with that entity. For the purposes of this definition,
38 | "control" means (i) the power, direct or indirect, to cause the
39 | direction or management of such entity, whether by contract or
40 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
41 | outstanding shares, or (iii) beneficial ownership of such entity.
42 |
43 |
44 |
45 | "You" (or "Your") shall mean an individual or Legal Entity
46 | exercising permissions granted by this License.
47 |
48 |
49 |
50 | "Source" form shall mean the preferred form for making modifications,
51 | including but not limited to software source code, documentation
52 | source, and configuration files.
53 |
54 |
55 |
56 | "Object" form shall mean any form resulting from mechanical
57 | transformation or translation of a Source form, including but
58 | not limited to compiled object code, generated documentation,
59 | and conversions to other media types.
60 |
61 |
62 |
63 | "Work" shall mean the work of authorship, whether in Source or
64 | Object form, made available under the License, as indicated by a
65 | copyright notice that is included in or attached to the work
66 | (an example is provided in the Appendix below).
67 |
68 |
69 |
70 | "Derivative Works" shall mean any work, whether in Source or Object
71 | form, that is based on (or derived from) the Work and for which the
72 | editorial revisions, annotations, elaborations, or other modifications
73 | represent, as a whole, an original work of authorship. For the purposes
74 | of this License, Derivative Works shall not include works that remain
75 | separable from, or merely link (or bind by name) to the interfaces of,
76 | the Work and Derivative Works thereof.
77 |
78 |
79 |
80 | "Contribution" shall mean any work of authorship, including
81 | the original version of the Work and any modifications or additions
82 | to that Work or Derivative Works thereof, that is intentionally
83 | submitted to Licensor for inclusion in the Work by the copyright owner
84 | or by an individual or Legal Entity authorized to submit on behalf of
85 | the copyright owner. For the purposes of this definition, "submitted"
86 | means any form of electronic, verbal, or written communication sent
87 | to the Licensor or its representatives, including but not limited to
88 | communication on electronic mailing lists, source code control systems,
89 | and issue tracking systems that are managed by, or on behalf of, the
90 | Licensor for the purpose of discussing and improving the Work, but
91 | excluding communication that is conspicuously marked or otherwise
92 | designated in writing by the copyright owner as "Not a Contribution."
93 |
94 |
95 |
96 | "Contributor" shall mean Licensor and any individual or Legal Entity
97 | on behalf of whom a Contribution has been received by Licensor and
98 | subsequently incorporated within the Work.
99 |
100 |
101 |
2. Grant of Copyright License.
102 | Subject to the terms and conditions of
103 | this License, each Contributor hereby grants to You a perpetual,
104 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
105 | copyright license to reproduce, prepare Derivative Works of,
106 | publicly display, publicly perform, sublicense, and distribute the
107 | Work and such Derivative Works in Source or Object form.
108 |
109 |
110 |
3. Grant of Patent License.
111 | Subject to the terms and conditions of
112 | this License, each Contributor hereby grants to You a perpetual,
113 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
114 | (except as stated in this section) patent license to make, have made,
115 | use, offer to sell, sell, import, and otherwise transfer the Work,
116 | where such license applies only to those patent claims licensable
117 | by such Contributor that are necessarily infringed by their
118 | Contribution(s) alone or by combination of their Contribution(s)
119 | with the Work to which such Contribution(s) was submitted. If You
120 | institute patent litigation against any entity (including a
121 | cross-claim or counterclaim in a lawsuit) alleging that the Work
122 | or a Contribution incorporated within the Work constitutes direct
123 | or contributory patent infringement, then any patent licenses
124 | granted to You under this License for that Work shall terminate
125 | as of the date such litigation is filed.
126 |
127 |
128 |
4. Redistribution.
129 | You may reproduce and distribute copies of the
130 | Work or Derivative Works thereof in any medium, with or without
131 | modifications, and in Source or Object form, provided that You
132 | meet the following conditions:
133 |
134 |
135 |
You must give any other recipients of the Work or
136 | Derivative Works a copy of this License; and
137 |
138 |
139 |
You must cause any modified files to carry prominent notices
140 | stating that You changed the files; and
141 |
142 |
143 |
You must retain, in the Source form of any Derivative Works
144 | that You distribute, all copyright, patent, trademark, and
145 | attribution notices from the Source form of the Work,
146 | excluding those notices that do not pertain to any part of
147 | the Derivative Works; and
148 |
149 |
150 |
If the Work includes a "NOTICE" text file as part of its
151 | distribution, then any Derivative Works that You distribute must
152 | include a readable copy of the attribution notices contained
153 | within such NOTICE file, excluding those notices that do not
154 | pertain to any part of the Derivative Works, in at least one
155 | of the following places: within a NOTICE text file distributed
156 | as part of the Derivative Works; within the Source form or
157 | documentation, if provided along with the Derivative Works; or,
158 | within a display generated by the Derivative Works, if and
159 | wherever such third-party notices normally appear. The contents
160 | of the NOTICE file are for informational purposes only and
161 | do not modify the License. You may add Your own attribution
162 | notices within Derivative Works that You distribute, alongside
163 | or as an addendum to the NOTICE text from the Work, provided
164 | that such additional attribution notices cannot be construed
165 | as modifying the License.
166 |
167 |
168 | You may add Your own copyright statement to Your modifications and
169 | may provide additional or different license terms and conditions
170 | for use, reproduction, or distribution of Your modifications, or
171 | for any such Derivative Works as a whole, provided Your use,
172 | reproduction, and distribution of the Work otherwise complies with
173 | the conditions stated in this License.
174 |
175 |
5. Submission of Contributions.
176 | Unless You explicitly state otherwise,
177 | any Contribution intentionally submitted for inclusion in the Work
178 | by You to the Licensor shall be under the terms and conditions of
179 | this License, without any additional terms or conditions.
180 | Notwithstanding the above, nothing herein shall supersede or modify
181 | the terms of any separate license agreement you may have executed
182 | with Licensor regarding such Contributions.
183 |
184 |
185 |
6. Trademarks.
186 | This License does not grant permission to use the trade
187 | names, trademarks, service marks, or product names of the Licensor,
188 | except as required for reasonable and customary use in describing the
189 | origin of the Work and reproducing the content of the NOTICE file.
190 |
191 |
192 |
7. Disclaimer of Warranty.
193 | Unless required by applicable law or
194 | agreed to in writing, Licensor provides the Work (and each
195 | Contributor provides its Contributions) on an "AS IS" BASIS,
196 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
197 | implied, including, without limitation, any warranties or conditions
198 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
199 | PARTICULAR PURPOSE. You are solely responsible for determining the
200 | appropriateness of using or redistributing the Work and assume any
201 | risks associated with Your exercise of permissions under this License.
202 |
203 |
204 |
8. Limitation of Liability.
205 | In no event and under no legal theory,
206 | whether in tort (including negligence), contract, or otherwise,
207 | unless required by applicable law (such as deliberate and grossly
208 | negligent acts) or agreed to in writing, shall any Contributor be
209 | liable to You for damages, including any direct, indirect, special,
210 | incidental, or consequential damages of any character arising as a
211 | result of this License or out of the use or inability to use the
212 | Work (including but not limited to damages for loss of goodwill,
213 | work stoppage, computer failure or malfunction, or any and all
214 | other commercial damages or losses), even if such Contributor
215 | has been advised of the possibility of such damages.
216 |
217 |
218 |
9. Accepting Warranty or Additional Liability.
219 | While redistributing
220 | the Work or Derivative Works thereof, You may choose to offer,
221 | and charge a fee for, acceptance of support, warranty, indemnity,
222 | or other liability obligations and/or rights consistent with this
223 | License. However, in accepting such obligations, You may act only
224 | on Your own behalf and on Your sole responsibility, not on behalf
225 | of any other Contributor, and only if You agree to indemnify,
226 | defend, and hold each Contributor harmless for any liability
227 | incurred by, or claims asserted against, such Contributor by reason
228 | of your accepting any such warranty or additional liability.
229 |
230 |
231 |
232 | END OF TERMS AND CONDITIONS
233 |
234 |
235 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | About
2 | =============================
3 |
4 | This is a Java port of a concurrent trie hash map implementation from the Scala collections library. It is almost a line-by-line
5 | conversion from Scala to Java.
6 |
7 | Idea + implementation techniques can be found in these reports written by Aleksandar Prokopec:
8 | * http://infoscience.epfl.ch/record/166908/files/ctries-techreport.pdf - this is a nice introduction to Ctries, along with a correctness proof
9 | * http://lamp.epfl.ch/~prokopec/ctries-snapshot.pdf - a more up-to-date writeup which describes the snapshot operation
10 |
11 | The original Scala implementation can be found here and is a part of scala.collection.concurrent:
12 | * [Scala implementation](https://github.com/scala/scala/blob/930c85d6c96507d798d1847ea078eebf93dc0acb/src/library/scala/collection/concurrent/TrieMap.scala)
13 |
14 | Some of the tests and implementation details were borrowed from this project:
15 | * https://github.com/flegall/concurrent-hash-trie
16 |
17 | Implementation status :
18 | * The given implementation is complete and implements all features of the original Scala implementation including support for
19 | snapshots.
20 | * Wherever necessary, code was adapted to be more easily usable in Java, e.g. it returns Objects instead of Option as
21 | many methods of Scala's collections do.
22 | * This class implements all the ConcurrentMap & Iterator methods and passes all the tests. Can be used as a drop-in replacement
23 | for usual Java maps, including ConcurrentHashMap.
24 |
25 |
26 | What is a concurrent trie hash map also known as ctrie?
27 | ========================================================
28 | ctrie is a lock-Free Concurrent Hash Array Mapped Trie.
29 |
30 | A concurrent hash-trie or Ctrie is a concurrent thread-safe lock-free implementation of a hash array mapped trie.
31 |
32 | It is used to implement the concurrent map abstraction. It has particularly scalable concurrent insert and remove operations
33 | and is memory-efficient.
34 |
35 | It supports O(1), atomic, lock-free snapshots which are used to implement linearizable lock-free size, iterator and clear operations.
36 | The cost of evaluating the (lazy) snapshot is distributed across subsequent updates, thus making snapshot evaluation horizontally scalable.
37 |
38 | The original Scala-based implementation of the Ctrie is a part of the Scala standard library since the version 2.10.
39 |
40 | More info about Ctries:
41 |
42 | - http://infoscience.epfl.ch/record/166908/files/ctries-techreport.pdf - this is a nice introduction to Ctries, along with a correctness proof
43 | - http://lamp.epfl.ch/~prokopec/ctries-snapshot.pdf - a more up-to-date writeup (more coherent with the current version of the code) which describes the snapshot operation
44 |
45 |
46 | License
47 | ===============================
48 |
49 | This library is licensed under the Apache 2.0 license.
50 |
51 |
52 | Usage
53 | ===============================
54 |
55 | Usage of this library is very simple. Simply import the class com.romix.scala.collection.concurrent.TrieMap and use it as a usual Map.
56 |
57 | import com.romix.scala.collection.concurrent.TrieMap;
58 |
59 | Map myMap = new TrieMap