├── .circleci └── config.yml ├── .gitignore ├── AUTHORS.txt ├── CHANGES.txt ├── DIFF.txt ├── LICENSE ├── README-idea-devel.txt ├── README-license.txt ├── README.md ├── README.txt ├── build.gradle ├── generator_src └── gnu │ └── trove │ └── generator │ └── Generator.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lib └── junit.jar ├── settings.gradle ├── src ├── main │ └── java │ │ └── gnu │ │ └── trove │ │ ├── Version.java │ │ ├── array │ │ └── AbstractOffheapArray.java │ │ ├── function │ │ └── TObjectFunction.java │ │ ├── impl │ │ ├── Constants.java │ │ ├── HashFunctions.java │ │ ├── PrimeFinder.java │ │ ├── hash │ │ │ ├── TCustomObjectHash.java │ │ │ ├── THash.java │ │ │ ├── THashIterator.java │ │ │ ├── THashPrimitiveIterator.java │ │ │ ├── THashPrimitiveOffheapIterator.java │ │ │ ├── TObjectHash.java │ │ │ ├── TPrimitiveHash.java │ │ │ └── TPrimitiveOffheapHash.java │ │ ├── package.html │ │ └── sync │ │ │ ├── SynchronizedCollection.java │ │ │ └── SynchronizedSet.java │ │ ├── iterator │ │ ├── TAdvancingIterator.java │ │ ├── TIterator.java │ │ ├── TPrimitiveIterator.java │ │ └── hash │ │ │ └── TObjectHashIterator.java │ │ ├── list │ │ ├── TLinkable.java │ │ ├── TLinkableAdapter.java │ │ └── linked │ │ │ └── TLinkedList.java │ │ ├── map │ │ ├── TMap.java │ │ └── hash │ │ │ ├── TCustomHashMap.java │ │ │ └── THashMap.java │ │ ├── procedure │ │ ├── TObjectObjectProcedure.java │ │ ├── TObjectProcedure.java │ │ └── array │ │ │ └── ToObjectArrayProceedure.java │ │ ├── set │ │ └── hash │ │ │ ├── TCustomHashSet.java │ │ │ ├── THashSet.java │ │ │ └── TLinkedHashSet.java │ │ └── strategy │ │ ├── HashingStrategy.java │ │ └── IdentityHashingStrategy.java └── test │ └── java │ └── gnu │ └── trove │ ├── TDecoratorsTest.java │ ├── array │ └── TPrimitiveOffheapArrayTest.java │ ├── decorator │ ├── TObjectPrimitiveMapDecoratorTest.java │ ├── TPrimitiveObjectMapDecoratorTest.java │ ├── TPrimitivePrimitiveMapDecoratorTest.java │ └── TPrimitiveSetDecoratorTest.java │ ├── impl │ ├── PrimeFinderTest.java │ └── hash │ │ ├── HashTestKit.java │ │ ├── THashTest.java │ │ └── TObjectHashTest.java │ ├── list │ ├── array │ │ ├── TArrayListTest.java │ │ ├── TPrimitiveArrayListTest.java │ │ └── TPrimitiveOffheapArrayListTest.java │ └── linked │ │ ├── TLinkableAdapterTest.java │ │ ├── TLinkedListTest.java │ │ └── TPrimitiveLinkedListTest.java │ ├── map │ └── hash │ │ ├── ArrayHashingStrategy.java │ │ ├── NoEntryValueTest.java │ │ ├── TCustomHashMapTest.java │ │ ├── THashMapTest.java │ │ ├── TObjectPrimitiveCustomHashMapTest.java │ │ ├── TObjectPrimitiveHashMapTest.java │ │ ├── TPrimitiveObjectHashMapTest.java │ │ ├── TPrimitivePrimitiveHashMapTest.java │ │ └── TPrimitivePrimitiveOffheapHashMapTest.java │ ├── set │ └── hash │ │ ├── TCustomHashSetTest.java │ │ ├── THashSetTest.java │ │ ├── TLinkedHashSetTest.java │ │ ├── TPrimitiveHashSetTest.java │ │ └── TPrimitiveOffheapHashSetTest.java │ ├── stack │ └── array │ │ └── TStackTest.java │ └── strategy │ └── IdentityHashingStrategyTest.java └── templates └── gnu └── trove ├── TCollections.template ├── TDecorators.template ├── _E_Collection.template ├── array └── _E_OffheapArray.template ├── decorator ├── Object_E_MapDecorator.template ├── _E_ListDecorator.template ├── _E_ObjectMapDecorator.template ├── _E_SetDecorator.template └── _K__V_MapDecorator.template ├── function └── _E_Function.template ├── impl ├── hash │ ├── _E_Hash.template │ ├── _E_OffheapHash.template │ ├── _K__V_Hash.template │ └── _K__V_OffheapHash.template ├── sync │ ├── SynchronizedObject_E_Map.template │ ├── SynchronizedRandomAccess_E_List.template │ ├── Synchronized_E_Collection.template │ ├── Synchronized_E_List.template │ ├── Synchronized_E_ObjectMap.template │ ├── Synchronized_E_Set.template │ └── Synchronized_K__V_Map.template └── unmodifiable │ ├── UnmodifiableObject_E_Map.template │ ├── UnmodifiableRandomAccess_E_List.template │ ├── Unmodifiable_E_Collection.template │ ├── Unmodifiable_E_List.template │ ├── Unmodifiable_E_ObjectMap.template │ ├── Unmodifiable_E_Set.template │ └── Unmodifiable_K__V_Map.template ├── iterator ├── Object_E_Iterator.template ├── _E_Iterator.template ├── _E_ObjectIterator.template └── _K__V_Iterator.template ├── list ├── _E_List.template ├── array │ ├── _E_ArrayList.template │ └── _E_OffheapArrayList.template └── linked │ └── _E_LinkedList.template ├── map ├── Object_E_Map.template ├── _E_ObjectMap.template ├── _K__V_Map.template ├── custom_hash │ └── Object_E_CustomHashMap.template └── hash │ ├── Object_E_HashMap.template │ ├── _E_ObjectHashMap.template │ ├── _K__V_HashMap.template │ └── _K__V_OffheapHashMap.template ├── procedure ├── Object_E_Procedure.template ├── _E_ObjectProcedure.template ├── _E_Procedure.template └── _K__V_Procedure.template ├── queue └── _E_Queue.template ├── set ├── _E_Set.template └── hash │ ├── _E_HashSet.template │ └── _E_OffheapHashSet.template └── stack ├── _E_Stack.template └── array └── _E_ArrayStack.template /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | jobs: 3 | unit-test-8: 4 | resource_class: large 5 | docker: 6 | - image: 'circleci/openjdk:8u222-stretch-node' 7 | environment: 8 | CIRCLE_TEST_REPORTS: /home/circleci/junit 9 | CIRCLE_ARTIFACTS: /home/circleci/artifacts 10 | GRADLE_OPTS: -Dorg.gradle.jvmargs='-Xms6144m -Xmx6144m' 11 | _JAVA_OPTIONS: -XX:ActiveProcessorCount=4 -XX:ErrorFile=/home/circleci/artifacts/hs_err_pid%p.log -XX:HeapDumpPath=/home/circleci/artifacts 12 | steps: 13 | - checkout 14 | - run: ./gradlew clean 15 | - run: ./gradlew test 16 | - store_test_results: { path: ~/junit } 17 | - store_artifacts: { path: ~/artifacts } 18 | unit-test-11: 19 | resource_class: large 20 | docker: 21 | - image: 'circleci/openjdk:11-node' 22 | environment: 23 | CIRCLE_TEST_REPORTS: /home/circleci/junit 24 | CIRCLE_ARTIFACTS: /home/circleci/artifacts 25 | GRADLE_OPTS: -Dorg.gradle.jvmargs='-Xms6144m -Xmx6144m' 26 | _JAVA_OPTIONS: -XX:ActiveProcessorCount=4 -XX:ErrorFile=/home/circleci/artifacts/hs_err_pid%p.log -XX:HeapDumpPath=/home/circleci/artifacts 27 | steps: 28 | - checkout 29 | - run: ./gradlew clean 30 | - run: ./gradlew test 31 | - store_test_results: { path: ~/junit } 32 | - store_artifacts: { path: ~/artifacts } 33 | publish: 34 | docker: 35 | - image: 'circleci/openjdk:8u222-stretch-node' 36 | environment: 37 | CIRCLE_TEST_REPORTS: /home/circleci/junit 38 | CIRCLE_ARTIFACTS: /home/circleci/artifacts 39 | GRADLE_OPTS: -Dorg.gradle.jvmargs='-Xms6144m -Xmx6144m' 40 | _JAVA_OPTIONS: -XX:ActiveProcessorCount=2 -XX:ErrorFile=/home/circleci/artifacts/hs_err_pid%p.log -XX:HeapDumpPath=/home/circleci/artifacts 41 | steps: 42 | - checkout 43 | - attach_workspace: { at: /home/circleci } 44 | - deploy: 45 | command: ./gradlew --parallel --stacktrace --continue publish 46 | - store_test_results: { path: ~/junit } 47 | - store_artifacts: { path: ~/artifacts } 48 | workflows: 49 | version: 2 50 | build: 51 | jobs: 52 | - unit-test-8: 53 | filters: { tags: { only: /.*/ } } 54 | - unit-test-11: 55 | filters: { tags: { only: /.*/ } } 56 | - publish: 57 | requires: [ unit-test-8, unit-test-11 ] 58 | filters: { tags: { only: /.*/ }, branches: { only: master } } 59 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | 3 | output/ 4 | out/ 5 | build/ 6 | 7 | .idea/ 8 | *.ipr 9 | *.iml 10 | *.iws 11 | 12 | .gradle 13 | -------------------------------------------------------------------------------- /AUTHORS.txt: -------------------------------------------------------------------------------- 1 | This version modified by Tim Wilson 2 | 3 | Original authors: 4 | 5 | Rob Eden 6 | Johan Parent 7 | Jeff Randall 8 | Eric D. Friedman 9 | 10 | Please do NOT email bug reports or feature requests. 11 | 12 | Instead use the very fine bug tracking system and feature request 13 | service on SourceForge: http://sourceforge.net/projects/trove4j/ 14 | We'll read your issue just as quickly, and the project's issues will 15 | remain out in the open where everyone can see them. We also monitor 16 | the project forums, so feel free to use those too. 17 | -------------------------------------------------------------------------------- /README-idea-devel.txt: -------------------------------------------------------------------------------- 1 | The project is built using gradle and has the gradle idea plugin already integrated. 2 | To do development in intellij, simply run: 3 | 4 | ./gradlew idea 5 | 6 | and open either the whole directory in intellij or the `.ipr` file. 7 | -------------------------------------------------------------------------------- /README-license.txt: -------------------------------------------------------------------------------- 1 | The Trove library is licensed under the Lesser GNU Public License, 2 | which is included with the distribution in a file called LICENSE.txt. 3 | 4 | Other license arrangements are possible, for a fee: contact 5 | ericdf@users.sourceforge.net for terms/pricing. 6 | 7 | The PrimeFinder and HashFunctions classes in Trove are subject to the 8 | following license restrictions: 9 | 10 | Copyright (c) 1999 CERN - European Organization for Nuclear Research. 11 | 12 | Permission to use, copy, modify, distribute and sell this software and 13 | its documentation for any purpose is hereby granted without fee, 14 | provided that the above copyright notice appear in all copies and that 15 | both that copyright notice and this permission notice appear in 16 | supporting documentation. CERN makes no representations about the 17 | suitability of this software for any purpose. It is provided "as is" 18 | without expressed or implied warranty. 19 | 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | trove-3.0.3 2 | =========== 3 | 4 | Patched version of the Trove library - changes the Collections semantics to match proper java.util.Map semantics 5 | 6 | 7 | This library has been patched by Palantir Technologies to make the following changes: 8 | 9 | Branch [palantir-gotham-3.12.x](https://github.com/palantirtech/trove-3.0.3/tree/palantir-gotham-3.12.x) - used by Palantir Gotham 3.12.x: 10 | * Trove implements of series of decorators that wrap their custom collections and implement the [standard Java Collections interfaces](http://docs.oracle.com/javase/6/docs/api/java/util/Collections.html). These decorators depart from the behavior specified in the [Map interface](http://docs.oracle.com/javase/6/docs/api/java/util/Map.html) by returning 0 when [put()][put] or [remove()][remove] is called with a key not in the map. This version returns null as specified by Map. 11 | * Trove collections use a magic primitive value to mean null when wrapped by a decorator. If this magic primitive value is actually added to the collection, decorators will treat it as null, the same way they would treat a missing value. This version distinguishes between these two cases and disallows adding null to decorators. 12 | 13 | Branch [palantir-gotham-4.x](https://github.com/palantirtech/trove-3.0.3/tree/palantir-gotham-4.x) - used by Palantir Gotham 4.x: 14 | * This version adds implementations of arrays, lists, sets, and maps that utilize offheap memory allocated by the sun.misc.Unsafe class. 15 | 16 | Original source code for this library available at: 17 | 18 | [http://sourceforge.net/projects/trove4j/files/trove/3.0.3/trove-3.0.3.tar.gz/download](http://sourceforge.net/projects/trove4j/files/trove/3.0.3/trove-3.0.3.tar.gz/download) 19 | 20 | [put]: http://docs.oracle.com/javase/6/docs/api/java/util/Map.html#put(K,%20V) 21 | [remove]: http://docs.oracle.com/javase/6/docs/api/java/util/Map.html#remove(java.lang.Object) 22 | 23 | This release made available under the LGPL version 2.1 - see [LICENSE](https://github.com/palantirtech/trove-3.0.3/blob/master/LICENSE) 24 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | 2 | GNU Trove: High performance collections for Java. 3 | 4 | Objectives 5 | 6 | The GNU Trove library has two objectives: 7 | 1. Provide "free" (as in "free speech" and "free beer"), fast, 8 | lightweight implementations of the java.util Collections API. 9 | These implementations are designed to be pluggable replacements 10 | for their JDK equivalents. 11 | 2. Whenever possible, provide the same collections support for 12 | primitive types. This gap in the JDK is often addressed by using 13 | the "wrapper" classes (java.lang.Integer, java.lang.Float, etc.) 14 | with Object-based collections. For most applications, however, 15 | collections which store primitives directly will require less 16 | space and yield significant performance gains. 17 | 18 | Hashtable techniques 19 | 20 | The Trove maps/sets use open addressing instead of the chaining 21 | approach taken by the JDK hashtables. This eliminates the need to 22 | create Map.Entry wrappper objects for every item in a table and so 23 | reduces the O (big-oh) in the performance of the hashtable algorithm. 24 | The size of the tables used in Trove's maps/sets is always a prime 25 | number, improving the probability of an optimal distribution of 26 | entries across the table, and so reducing the likelihood of 27 | performance-degrading collisions. Trove sets are not backed by maps, 28 | and so using a THashSet does not result in the allocation of an unused 29 | "values" array. 30 | 31 | Hashing strategies 32 | 33 | Trove's maps/sets support the use of custom hashing strategies, 34 | allowing you to tune collections based on characteristics of the input 35 | data. This feature also allows you to define hash functions when it is 36 | not feasible to override Object.hashCode(). For example, the 37 | java.lang.String class is final, and its implementation of hashCode() 38 | takes O(n) time to complete. In some applications, however, it may be 39 | possible for a custom hashing function to save time by skipping 40 | portions of the string that are invariant. 41 | 42 | Using java.util.HashMap, it is not possible to use Java language 43 | arrays as keys. For example, this code: 44 | char[] foo, bar; 45 | foo = new char[] {'a','b','c'}; 46 | bar = new char[] {'a','b','c'}; 47 | System.out.println(foo.hashCode() == bar.hashCode() ? 48 | "equal" : "not equal"); 49 | System.out.println(foo.equals(bar) ? "equal" : "not equal"); 50 | 51 | 52 | produces this output: 53 | not equal 54 | not equal 55 | 56 | 57 | And so an entry stored in a java.util.HashMap with foo as a key could 58 | not be retrieved with bar, since there is no way to override 59 | hashCode() or equals() on language array objects. 60 | 61 | In a gnu.trove.map.hash.TCustomHashMap, however, you can implement a 62 | gnu.trove.strategy.HashingStrategy to enable hashing on arrays: 63 | class CharArrayStrategy implements HashingStrategy { 64 | public int computeHashCode(Object o) { 65 | char[] c = (char[])o; 66 | // use the shift-add-xor class of string hashing functions 67 | // cf. Ramakrishna and Zobel, 68 | // "Performance in Practice of String Hashing Functions" 69 | int h = 31; // seed chosen at random 70 | for (int i = 0; i < c.length; i++) { // could skip invariants 71 | // L=5, R=2 works well for ASCII input 72 | h = h ^ ((h << 5) + (h >> 2) + c[i]); 73 | } 74 | return h; 75 | } 76 | 77 | public boolean equals(Object o1, Object o2) { 78 | char[] c1 = (char[])o1; 79 | char[] c2 = (char[])o2; 80 | // could drop this check for fixed-length keys 81 | if (c1.length != c2.length) { 82 | return false; 83 | } 84 | // could skip invariants 85 | for (int i = 0, len = c1.length; i < len; i++) { 86 | if (c1[i] != c2[i]) { 87 | return false; 88 | } 89 | } 90 | return true; 91 | } 92 | } 93 | 94 | 95 | Iterators in primitive collections 96 | 97 | Trove's primitive mappings include access through Iterators as well 98 | as procedures and functions. The API documentation on those classes 99 | contains several examples showing how these can be used effectively 100 | and explaining why their semantics differ from those of 101 | java.util.Iterator. 102 | 103 | _________________________________________________________________ 104 | 105 | Last modified: Sep 9, 2011 106 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | ///////////// 2 | // Plugins // 3 | ///////////// 4 | plugins { 5 | id 'com.palantir.git-version' version '0.12.3' 6 | id 'org.inferred.processors' version '3.3.0' 7 | id 'com.palantir.external-publish' version '1.2.1' 8 | id 'com.palantir.external-publish-jar' version '1.2.1' 9 | 10 | id 'java' 11 | id 'idea' 12 | } 13 | 14 | ///////////////////////// 15 | // Module Dependencies // 16 | ///////////////////////// 17 | repositories { 18 | mavenCentral() 19 | } 20 | 21 | dependencies { 22 | testCompile 'junit:junit:4.12' 23 | } 24 | 25 | // keep group/version info the same as from before 26 | group 'com.palantir.patches.sourceforge' 27 | version gitVersion() 28 | 29 | /////////////////////////////////////////////////// 30 | 31 | def outputDir = 'output' 32 | def outputGeneratorClasses = "${outputDir}/generator_classes" 33 | def outputGenerated = "${outputDir}/gen_src" 34 | def outputDest = "${outputDir}/classes" 35 | def outputTests = "${outputDir}/test_classes" 36 | def outputLib = "${outputDir}/lib" 37 | def distRoot = "${outputDir}/dist" 38 | 39 | def templates = "templates" 40 | def generatorSrc = "generator_src" 41 | 42 | //////////////////////// 43 | // Generating sources // 44 | //////////////////////// 45 | task generate(type: JavaExec, dependsOn: ':buildGenerator') { 46 | classpath = files(outputGeneratorClasses) 47 | main = 'gnu.trove.generator.Generator' 48 | args templates, outputGenerated 49 | } 50 | 51 | task buildGenerator(type: JavaCompile) { 52 | classpath = files(generatorSrc) 53 | source = generatorSrc 54 | destinationDirectory = file(outputGeneratorClasses) 55 | sourceCompatibility = 1.8 56 | targetCompatibility = 1.8 57 | } 58 | 59 | // add generated sources to classpath for compilation 60 | sourceSets.main.java.srcDirs += outputGenerated 61 | 62 | // setup intellij to work with generated files 63 | idea { 64 | module { 65 | // need to make sure generated source is a source dir first 66 | // before marking it as a generated source dir. 67 | sourceDirs += [file(generatorSrc), file(outputGenerated)] 68 | generatedSourceDirs += file(outputGenerated) 69 | } 70 | } 71 | 72 | /////////// 73 | // Tasks // 74 | /////////// 75 | clean.doFirst { 76 | delete outputDir 77 | } 78 | 79 | // turning off module metadata so that all consumers just use regular POMs 80 | tasks.withType(GenerateModuleMetadata) { 81 | enabled = false 82 | } 83 | 84 | // turning off javadocs task because there are too many errors 85 | tasks.withType(Javadoc) { 86 | enabled = false 87 | } 88 | 89 | tasks.idea.dependsOn generate 90 | tasks.compileJava.dependsOn generate 91 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.parallel=true 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/palantir/trove/42b55c6566e8943adbc9cc0c4ff7bba31b66b8f8/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | 88 | @rem Execute Gradle 89 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 90 | 91 | :end 92 | @rem End local scope for the variables with windows NT shell 93 | if "%ERRORLEVEL%"=="0" goto mainEnd 94 | 95 | :fail 96 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 97 | rem the _cmd.exe /c_ return code! 98 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 99 | exit /b 1 100 | 101 | :mainEnd 102 | if "%OS%"=="Windows_NT" endlocal 103 | 104 | :omega 105 | -------------------------------------------------------------------------------- /lib/junit.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/palantir/trove/42b55c6566e8943adbc9cc0c4ff7bba31b66b8f8/lib/junit.jar -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This settings file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * In a single project build this file can be empty or even removed. 6 | * 7 | * Detailed information about configuring a multi-project build in Gradle can be found 8 | * in the user guide at https://docs.gradle.org/4.4.1/userguide/multi_project_builds.html 9 | */ 10 | 11 | rootProject.name = 'trove3' 12 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/Version.java: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 4 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 5 | // 6 | // This library is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation; either 9 | // version 2.1 of the License, or (at your option) any later version. 10 | // 11 | // This library is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU Lesser General Public 17 | // License along with this program; if not, write to the Free Software 18 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | /////////////////////////////////////////////////////////////////////////////// 20 | 21 | package gnu.trove; 22 | 23 | /** 24 | * Simple class meant as a possible main class (via manifest) to report the 25 | * implementation version of the trove4j jar. 26 | *

27 | * This may be useful to ask feedback WITH build version information 28 | *

29 | * The Main-Class entry in the manifest.mf should be set during the build as well 30 | * as the Implementation-Version manifest attribute should be set as well. 31 | *

32 | * Created by IntelliJ IDEA. 33 | * User: Johan Parent 34 | * Date: 3/03/11 35 | * Time: 22:10 36 | */ 37 | public class Version { 38 | public static void main(String[] args) { 39 | System.out.println(getVersion()); 40 | } 41 | 42 | /** 43 | * Returns the implementation version of trove4j. Intended for applications 44 | * wanting to return the version of trove4j they are using 45 | *

46 | * NOTE: this method will only return a useful version when working 47 | * with a trove4j jar as it requires a manifest file 48 | * 49 | * @return 50 | */ 51 | public static String getVersion() { 52 | String version = Version.class.getPackage().getImplementationVersion(); 53 | // 54 | if (version != null) { 55 | return "trove4j version " + version; 56 | } 57 | 58 | return "Sorry no Implementation-Version manifest attribute available"; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/function/TObjectFunction.java: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.function; 20 | 21 | /** 22 | * Interface for functions that accept and return one Object reference. 23 | *

24 | * Created: Mon Nov 5 22:19:36 2001 25 | * 26 | * @author Eric D. Friedman 27 | * @version $Id: TObjectFunction.java,v 1.1.2.1 2009/09/06 17:02:19 upholderoftruth Exp $ 28 | */ 29 | 30 | public interface TObjectFunction { 31 | 32 | /** 33 | * Execute this function with value 34 | * 35 | * @param value an Object input 36 | * @return an Object result 37 | */ 38 | public R execute( T value ); 39 | }// TObjectFunction 40 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/impl/HashFunctions.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999 CERN - European Organization for Nuclear Research. 2 | 3 | // Permission to use, copy, modify, distribute and sell this software and 4 | // its documentation for any purpose is hereby granted without fee, 5 | // provided that the above copyright notice appear in all copies and that 6 | // both that copyright notice and this permission notice appear in 7 | // supporting documentation. CERN makes no representations about the 8 | // suitability of this software for any purpose. It is provided "as is" 9 | // without expressed or implied warranty. 10 | 11 | package gnu.trove.impl; 12 | 13 | /** 14 | * Provides various hash functions. 15 | * 16 | * @author wolfgang.hoschek@cern.ch 17 | * @version 1.0, 09/24/99 18 | */ 19 | public final class HashFunctions { 20 | /** 21 | * Returns a hashcode for the specified value. 22 | * 23 | * @return a hash code value for the specified value. 24 | */ 25 | public static int hash(double value) { 26 | assert !Double.isNaN(value) : "Values of NaN are not supported."; 27 | 28 | long bits = Double.doubleToLongBits(value); 29 | return (int)(bits ^ (bits >>> 32)); 30 | //return (int) Double.doubleToLongBits(value*663608941.737); 31 | //this avoids excessive hashCollisions in the case values are 32 | //of the form (1.0, 2.0, 3.0, ...) 33 | } 34 | 35 | /** 36 | * Returns a hashcode for the specified value. 37 | * 38 | * @return a hash code value for the specified value. 39 | */ 40 | public static int hash(float value) { 41 | assert !Float.isNaN(value) : "Values of NaN are not supported."; 42 | 43 | return Float.floatToIntBits(value*663608941.737f); 44 | // this avoids excessive hashCollisions in the case values are 45 | // of the form (1.0, 2.0, 3.0, ...) 46 | } 47 | 48 | /** 49 | * Returns a hashcode for the specified value. 50 | * 51 | * @return a hash code value for the specified value. 52 | */ 53 | public static int hash(int value) { 54 | return value; 55 | } 56 | 57 | /** 58 | * Returns a hashcode for the specified value. 59 | * 60 | * @return a hash code value for the specified value. 61 | */ 62 | public static int hash(long value) { 63 | return ((int)(value ^ (value >>> 32))); 64 | } 65 | 66 | /** 67 | * Returns a hashcode for the specified object. 68 | * 69 | * @return a hash code value for the specified object. 70 | */ 71 | public static int hash(Object object) { 72 | return object==null ? 0 : object.hashCode(); 73 | } 74 | 75 | 76 | /** 77 | * In profiling, it has been found to be faster to have our own local implementation 78 | * of "ceil" rather than to call to {@link Math#ceil(double)}. 79 | */ 80 | public static int fastCeil( float v ) { 81 | int possible_result = ( int ) v; 82 | if ( v - possible_result > 0 ) possible_result++; 83 | return possible_result; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/impl/PrimeFinder.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999 CERN - European Organization for Nuclear Research. 2 | 3 | // Permission to use, copy, modify, distribute and sell this software 4 | // and its documentation for any purpose is hereby granted without fee, 5 | // provided that the above copyright notice appear in all copies and 6 | // that both that copyright notice and this permission notice appear in 7 | // supporting documentation. CERN makes no representations about the 8 | // suitability of this software for any purpose. It is provided "as is" 9 | // without expressed or implied warranty. 10 | package gnu.trove.impl; 11 | 12 | import java.util.Arrays; 13 | 14 | /* 15 | * Modified for Trove to use the java.util.Arrays sort/search 16 | * algorithms instead of those provided with colt. 17 | */ 18 | 19 | /** 20 | * Used to keep hash table capacities prime numbers. 21 | * Not of interest for users; only for implementors of hashtables. 22 | * 23 | *

Choosing prime numbers as hash table capacities is a good idea 24 | * to keep them working fast, particularly under hash table 25 | * expansions. 26 | * 27 | *

However, JDK 1.2, JGL 3.1 and many other toolkits do nothing to 28 | * keep capacities prime. This class provides efficient means to 29 | * choose prime capacities. 30 | * 31 | *

Choosing a prime is O(log 300) (binary search in a list 32 | * of 300 ints). Memory requirements: 1 KB static memory. 33 | * 34 | * @author wolfgang.hoschek@cern.ch 35 | * @version 1.0, 09/24/99 36 | */ 37 | public final class PrimeFinder { 38 | /** 39 | * The largest prime this class can generate; currently equal to 40 | * Integer.MAX_VALUE. 41 | */ 42 | public static final int largestPrime = Integer.MAX_VALUE; //yes, it is prime. 43 | 44 | /** 45 | * The prime number list consists of 11 chunks. 46 | * 47 | * Each chunk contains prime numbers. 48 | * 49 | * A chunk starts with a prime P1. The next element is a prime 50 | * P2. P2 is the smallest prime for which holds: P2 >= 2*P1. 51 | * 52 | * The next element is P3, for which the same holds with respect 53 | * to P2, and so on. 54 | * 55 | * Chunks are chosen such that for any desired capacity >= 1000 56 | * the list includes a prime number <= desired capacity * 1.11. 57 | * 58 | * Therefore, primes can be retrieved which are quite close to any 59 | * desired capacity, which in turn avoids wasting memory. 60 | * 61 | * For example, the list includes 62 | * 1039,1117,1201,1277,1361,1439,1523,1597,1759,1907,2081. 63 | * 64 | * So if you need a prime >= 1040, you will find a prime <= 65 | * 1040*1.11=1154. 66 | * 67 | * Chunks are chosen such that they are optimized for a hashtable 68 | * growthfactor of 2.0; 69 | * 70 | * If your hashtable has such a growthfactor then, after initially 71 | * "rounding to a prime" upon hashtable construction, it will 72 | * later expand to prime capacities such that there exist no 73 | * better primes. 74 | * 75 | * In total these are about 32*10=320 numbers -> 1 KB of static 76 | * memory needed. 77 | * 78 | * If you are stingy, then delete every second or fourth chunk. 79 | */ 80 | 81 | private static final int[] primeCapacities = { 82 | //chunk #0 83 | largestPrime, 84 | 85 | //chunk #1 86 | 5,11,23,47,97,197,397,797,1597,3203,6421,12853,25717,51437,102877,205759, 87 | 411527,823117,1646237,3292489,6584983,13169977,26339969,52679969,105359939, 88 | 210719881,421439783,842879579,1685759167, 89 | 90 | //chunk #2 91 | 433,877,1759,3527,7057,14143,28289,56591,113189,226379,452759,905551,1811107, 92 | 3622219,7244441,14488931,28977863,57955739,115911563,231823147,463646329,927292699, 93 | 1854585413, 94 | 95 | //chunk #3 96 | 953,1907,3821,7643,15287,30577,61169,122347,244703,489407,978821,1957651,3915341, 97 | 7830701,15661423,31322867,62645741,125291483,250582987,501165979,1002331963, 98 | 2004663929, 99 | 100 | //chunk #4 101 | 1039,2081,4177,8363,16729,33461,66923,133853,267713,535481,1070981,2141977,4283963, 102 | 8567929,17135863,34271747,68543509,137087021,274174111,548348231,1096696463, 103 | 104 | //chunk #5 105 | 31,67,137,277,557,1117,2237,4481,8963,17929,35863,71741,143483,286973,573953, 106 | 1147921,2295859,4591721,9183457,18366923,36733847,73467739,146935499,293871013, 107 | 587742049,1175484103, 108 | 109 | //chunk #6 110 | 599,1201,2411,4831,9677,19373,38747,77509,155027,310081,620171,1240361,2480729, 111 | 4961459,9922933,19845871,39691759,79383533,158767069,317534141,635068283,1270136683, 112 | 113 | //chunk #7 114 | 311,631,1277,2557,5119,10243,20507,41017,82037,164089,328213,656429,1312867, 115 | 2625761,5251529,10503061,21006137,42012281,84024581,168049163,336098327,672196673, 116 | 1344393353, 117 | 118 | //chunk #8 119 | 3,7,17,37,79,163,331,673,1361,2729,5471,10949,21911,43853,87719,175447,350899, 120 | 701819,1403641,2807303,5614657,11229331,22458671,44917381,89834777,179669557, 121 | 359339171,718678369,1437356741, 122 | 123 | //chunk #9 124 | 43,89,179,359,719,1439,2879,5779,11579,23159,46327,92657,185323,370661,741337, 125 | 1482707,2965421,5930887,11861791,23723597,47447201,94894427,189788857,379577741, 126 | 759155483,1518310967, 127 | 128 | //chunk #10 129 | 379,761,1523,3049,6101,12203,24407,48817,97649,195311,390647,781301,1562611, 130 | 3125257,6250537,12501169,25002389,50004791,100009607,200019221,400038451,800076929, 131 | 1600153859 132 | }; 133 | 134 | static { //initializer 135 | // The above prime numbers are formatted for human readability. 136 | // To find numbers fast, we sort them once and for all. 137 | 138 | Arrays.sort(primeCapacities); 139 | } 140 | 141 | /** 142 | * Returns a prime number which is >= desiredCapacity 143 | * and very close to desiredCapacity (within 11% if 144 | * desiredCapacity >= 1000). 145 | * 146 | * @param desiredCapacity the capacity desired by the user. 147 | * @return the capacity which should be used for a hashtable. 148 | */ 149 | public static final int nextPrime(int desiredCapacity) { 150 | int i = Arrays.binarySearch(primeCapacities, desiredCapacity); 151 | if (i<0) { 152 | // desired capacity not found, choose next prime greater 153 | // than desired capacity 154 | i = -i -1; // remember the semantics of binarySearch... 155 | } 156 | return primeCapacities[i]; 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/impl/hash/TCustomObjectHash.java: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 4 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 5 | // 6 | // This library is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation; either 9 | // version 2.1 of the License, or (at your option) any later version. 10 | // 11 | // This library is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU Lesser General Public 17 | // License along with this program; if not, write to the Free Software 18 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | /////////////////////////////////////////////////////////////////////////////// 20 | 21 | package gnu.trove.impl.hash; 22 | 23 | import gnu.trove.strategy.HashingStrategy; 24 | 25 | import java.io.IOException; 26 | import java.io.ObjectInput; 27 | import java.io.ObjectOutput; 28 | 29 | 30 | /** 31 | * An open addressed hashing implementation for Object types. 32 | * 33 | * @author Rob Eden 34 | * @author Eric D. Friedman 35 | * @author Jeff Randall 36 | * @version $Id: TObjectHash.java,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ 37 | */ 38 | abstract public class TCustomObjectHash extends TObjectHash { 39 | static final long serialVersionUID = 8766048185963756400L; 40 | 41 | protected HashingStrategy strategy; 42 | 43 | 44 | /** FOR EXTERNALIZATION ONLY!!! */ 45 | public TCustomObjectHash() {} 46 | 47 | 48 | /** 49 | * Creates a new TManualObjectHash instance with the 50 | * default capacity and load factor. 51 | */ 52 | public TCustomObjectHash( HashingStrategy strategy ) { 53 | super(); 54 | 55 | this.strategy = strategy; 56 | } 57 | 58 | 59 | /** 60 | * Creates a new TManualObjectHash instance whose capacity 61 | * is the next highest prime above initialCapacity + 1 62 | * unless that value is already prime. 63 | * 64 | * @param initialCapacity an int value 65 | */ 66 | public TCustomObjectHash( HashingStrategy strategy, int initialCapacity ) { 67 | super( initialCapacity ); 68 | 69 | this.strategy = strategy; 70 | } 71 | 72 | 73 | /** 74 | * Creates a new TManualObjectHash instance with a prime 75 | * value at or near the specified capacity and load factor. 76 | * 77 | * @param initialCapacity used to find a prime capacity for the table. 78 | * @param loadFactor used to calculate the threshold over which 79 | * rehashing takes place. 80 | */ 81 | public TCustomObjectHash( HashingStrategy strategy, int initialCapacity, 82 | float loadFactor ) { 83 | 84 | super( initialCapacity, loadFactor ); 85 | 86 | this.strategy = strategy; 87 | } 88 | 89 | 90 | @Override 91 | protected int hash( Object obj ) { 92 | //noinspection unchecked 93 | return strategy.computeHashCode( ( T ) obj ); 94 | } 95 | 96 | @Override 97 | protected boolean equals( Object one, Object two ) { 98 | //noinspection unchecked 99 | return two != REMOVED && strategy.equals( ( T ) one, ( T ) two ); 100 | } 101 | 102 | 103 | @Override 104 | public void writeExternal( ObjectOutput out ) throws IOException { 105 | 106 | // VERSION 107 | out.writeByte( 0 ); 108 | 109 | // SUPER 110 | super.writeExternal( out ); 111 | 112 | // STRATEGY 113 | out.writeObject( strategy ); 114 | } 115 | 116 | 117 | @Override 118 | public void readExternal( ObjectInput in ) 119 | throws IOException, ClassNotFoundException { 120 | 121 | // VERSION 122 | in.readByte(); 123 | 124 | // SUPER 125 | super.readExternal( in ); 126 | 127 | // STRATEGY 128 | //noinspection unchecked 129 | strategy = ( HashingStrategy ) in.readObject(); 130 | } 131 | } // TCustomObjectHash 132 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/impl/hash/THashIterator.java: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.impl.hash; 20 | 21 | import gnu.trove.iterator.TIterator; 22 | 23 | import java.util.ConcurrentModificationException; 24 | import java.util.Iterator; 25 | import java.util.NoSuchElementException; 26 | 27 | 28 | 29 | /** 30 | * Implements all iterator functions for the hashed object set. 31 | * Subclasses may override objectAtIndex to vary the object 32 | * returned by calls to next() (e.g. for values, and Map.Entry 33 | * objects). 34 | *

35 | *

Note that iteration is fastest if you forego the calls to 36 | * hasNext in favor of checking the size of the structure 37 | * yourself and then call next() that many times: 38 | *

39 | *

 40 |  * Iterator i = collection.iterator();
 41 |  * for (int size = collection.size(); size-- > 0;) {
 42 |  *   Object o = i.next();
 43 |  * }
 44 |  * 
45 | *

46 | *

You may, of course, use the hasNext(), next() idiom too if 47 | * you aren't in a performance critical spot.

48 | */ 49 | public abstract class THashIterator implements TIterator, Iterator { 50 | 51 | 52 | private final TObjectHash _object_hash; 53 | 54 | /** the data structure this iterator traverses */ 55 | protected final THash _hash; 56 | 57 | /** 58 | * the number of elements this iterator believes are in the 59 | * data structure it accesses. 60 | */ 61 | protected int _expectedSize; 62 | 63 | /** the index used for iteration. */ 64 | protected int _index; 65 | 66 | 67 | /** 68 | * Create an instance of THashIterator over the values of the TObjectHash 69 | * 70 | * @param hash the object 71 | */ 72 | protected THashIterator( TObjectHash hash ) { 73 | _hash = hash; 74 | _expectedSize = _hash.size(); 75 | _index = _hash.capacity(); 76 | _object_hash = hash; 77 | } 78 | 79 | 80 | /** 81 | * Moves the iterator to the next Object and returns it. 82 | * 83 | * @return an Object value 84 | * @throws ConcurrentModificationException 85 | * if the structure 86 | * was changed using a method that isn't on this iterator. 87 | * @throws NoSuchElementException if this is called on an 88 | * exhausted iterator. 89 | */ 90 | @Override 91 | public V next() { 92 | moveToNextIndex(); 93 | return objectAtIndex( _index ); 94 | } 95 | 96 | 97 | /** 98 | * Returns true if the iterator can be advanced past its current 99 | * location. 100 | * 101 | * @return a boolean value 102 | */ 103 | @Override 104 | public boolean hasNext() { 105 | return nextIndex() >= 0; 106 | } 107 | 108 | 109 | /** 110 | * Removes the last entry returned by the iterator. 111 | * Invoking this method more than once for a single entry 112 | * will leave the underlying data structure in a confused 113 | * state. 114 | */ 115 | @Override 116 | public void remove() { 117 | if ( _expectedSize != _hash.size() ) { 118 | throw new ConcurrentModificationException(); 119 | } 120 | 121 | // Disable auto compaction during the remove. This is a workaround for bug 1642768. 122 | try { 123 | _hash.tempDisableAutoCompaction(); 124 | _hash.removeAt( _index ); 125 | } 126 | finally { 127 | _hash.reenableAutoCompaction( false ); 128 | } 129 | 130 | _expectedSize--; 131 | } 132 | 133 | 134 | /** 135 | * Sets the internal index so that the `next' object 136 | * can be returned. 137 | */ 138 | protected final void moveToNextIndex() { 139 | // doing the assignment && < 0 in one line shaves 140 | // 3 opcodes... 141 | if ( ( _index = nextIndex() ) < 0 ) { 142 | throw new NoSuchElementException(); 143 | } 144 | } 145 | 146 | 147 | /** 148 | * Returns the index of the next value in the data structure 149 | * or a negative value if the iterator is exhausted. 150 | * 151 | * @return an int value 152 | * @throws ConcurrentModificationException 153 | * if the underlying 154 | * collection's size has been modified since the iterator was 155 | * created. 156 | */ 157 | protected final int nextIndex() { 158 | if ( _expectedSize != _hash.size() ) { 159 | throw new ConcurrentModificationException(); 160 | } 161 | 162 | Object[] set = _object_hash._set; 163 | int i = _index; 164 | while ( i-- > 0 && ( set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED ) ) { 165 | ; 166 | } 167 | return i; 168 | } 169 | 170 | 171 | /** 172 | * Returns the object at the specified index. Subclasses should 173 | * implement this to return the appropriate object for the given 174 | * index. 175 | * 176 | * @param index the index of the value to return. 177 | * @return an Object value 178 | */ 179 | abstract protected V objectAtIndex( int index ); 180 | } // THashIterator 181 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/impl/hash/THashPrimitiveIterator.java: -------------------------------------------------------------------------------- 1 | // //////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | // //////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.impl.hash; 20 | 21 | import gnu.trove.iterator.TPrimitiveIterator; 22 | 23 | import java.util.ConcurrentModificationException; 24 | import java.util.NoSuchElementException; 25 | 26 | 27 | /** 28 | * Implements all iterator functions for the hashed object set. 29 | * Subclasses may override objectAtIndex to vary the object 30 | * returned by calls to next() (e.g. for values, and Map.Entry 31 | * objects). 32 | *

33 | *

Note that iteration is fastest if you forego the calls to 34 | * hasNext in favor of checking the size of the structure 35 | * yourself and then call next() that many times: 36 | *

37 | *

 38 |  * Iterator i = collection.iterator();
 39 |  * for (int size = collection.size(); size-- > 0;) {
 40 |  *   Object o = i.next();
 41 |  * }
 42 |  * 
43 | *

44 | *

You may, of course, use the hasNext(), next() idiom too if 45 | * you aren't in a performance critical spot.

46 | */ 47 | public abstract class THashPrimitiveIterator implements TPrimitiveIterator { 48 | 49 | /** the data structure this iterator traverses */ 50 | protected final TPrimitiveHash _hash; 51 | /** 52 | * the number of elements this iterator believes are in the 53 | * data structure it accesses. 54 | */ 55 | protected int _expectedSize; 56 | /** the index used for iteration. */ 57 | protected int _index; 58 | 59 | 60 | /** 61 | * Creates a TPrimitiveIterator for the specified collection. 62 | * 63 | * @param hash the TPrimitiveHash we want to iterate over. 64 | */ 65 | public THashPrimitiveIterator( TPrimitiveHash hash ) { 66 | _hash = hash; 67 | _expectedSize = _hash.size(); 68 | _index = _hash.capacity(); 69 | } 70 | 71 | 72 | /** 73 | * Returns the index of the next value in the data structure 74 | * or a negative value if the iterator is exhausted. 75 | * 76 | * @return an int value 77 | * @throws java.util.ConcurrentModificationException 78 | * if the underlying collection's 79 | * size has been modified since the iterator was created. 80 | */ 81 | protected final int nextIndex() { 82 | if ( _expectedSize != _hash.size() ) { 83 | throw new ConcurrentModificationException(); 84 | } 85 | 86 | byte[] states = _hash._states; 87 | int i = _index; 88 | while ( i-- > 0 && ( states[i] != TPrimitiveHash.FULL ) ) { 89 | ; 90 | } 91 | return i; 92 | } 93 | 94 | 95 | /** 96 | * Returns true if the iterator can be advanced past its current 97 | * location. 98 | * 99 | * @return a boolean value 100 | */ 101 | @Override 102 | public boolean hasNext() { 103 | return nextIndex() >= 0; 104 | } 105 | 106 | 107 | /** 108 | * Removes the last entry returned by the iterator. 109 | * Invoking this method more than once for a single entry 110 | * will leave the underlying data structure in a confused 111 | * state. 112 | */ 113 | @Override 114 | public void remove() { 115 | if (_expectedSize != _hash.size()) { 116 | throw new ConcurrentModificationException(); 117 | } 118 | 119 | // Disable auto compaction during the remove. This is a workaround for bug 1642768. 120 | try { 121 | _hash.tempDisableAutoCompaction(); 122 | _hash.removeAt(_index); 123 | } 124 | finally { 125 | _hash.reenableAutoCompaction( false ); 126 | } 127 | 128 | _expectedSize--; 129 | } 130 | 131 | 132 | /** 133 | * Sets the internal index so that the `next' object 134 | * can be returned. 135 | */ 136 | protected final void moveToNextIndex() { 137 | // doing the assignment && < 0 in one line shaves 138 | // 3 opcodes... 139 | if ( ( _index = nextIndex() ) < 0 ) { 140 | throw new NoSuchElementException(); 141 | } 142 | } 143 | 144 | 145 | } // TPrimitiveIterator 146 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/impl/hash/THashPrimitiveOffheapIterator.java: -------------------------------------------------------------------------------- 1 | // //////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | // //////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.impl.hash; 20 | 21 | import java.util.ConcurrentModificationException; 22 | import java.util.NoSuchElementException; 23 | 24 | import gnu.trove.array.TByteOffheapArray; 25 | import gnu.trove.iterator.TPrimitiveIterator; 26 | 27 | 28 | /** 29 | * Implements all iterator functions for the hashed object set. 30 | * Subclasses may override objectAtIndex to vary the object 31 | * returned by calls to next() (e.g. for values, and Map.Entry 32 | * objects). 33 | *

34 | *

Note that iteration is fastest if you forego the calls to 35 | * hasNext in favor of checking the size of the structure 36 | * yourself and then call next() that many times: 37 | *

38 | *

 39 |  * Iterator i = collection.iterator();
 40 |  * for (int size = collection.size(); size-- > 0;) {
 41 |  *   Object o = i.next();
 42 |  * }
 43 |  * 
44 | *

45 | *

You may, of course, use the hasNext(), next() idiom too if 46 | * you aren't in a performance critical spot.

47 | */ 48 | public abstract class THashPrimitiveOffheapIterator implements TPrimitiveIterator { 49 | 50 | /** the data structure this iterator traverses */ 51 | protected final TPrimitiveOffheapHash _hash; 52 | /** 53 | * the number of elements this iterator believes are in the 54 | * data structure it accesses. 55 | */ 56 | protected int _expectedSize; 57 | /** the index used for iteration. */ 58 | protected int _index; 59 | 60 | 61 | /** 62 | * Creates a TPrimitiveOffheapIterator for the specified collection. 63 | * 64 | * @param hash the TPrimitiveOffheapHash we want to iterate over. 65 | */ 66 | public THashPrimitiveOffheapIterator( TPrimitiveOffheapHash hash ) { 67 | _hash = hash; 68 | _expectedSize = _hash.size(); 69 | _index = _hash.capacity(); 70 | } 71 | 72 | 73 | /** 74 | * Returns the index of the next value in the data structure 75 | * or a negative value if the iterator is exhausted. 76 | * 77 | * @return an int value 78 | * @throws java.util.ConcurrentModificationException 79 | * if the underlying collection's 80 | * size has been modified since the iterator was created. 81 | */ 82 | protected final int nextIndex() { 83 | if ( _expectedSize != _hash.size() ) { 84 | throw new ConcurrentModificationException(); 85 | } 86 | 87 | TByteOffheapArray states = _hash._states; 88 | int i = _index; 89 | while ( i-- > 0 && ( states.get( i ) != TPrimitiveHash.FULL ) ) { 90 | ; 91 | } 92 | return i; 93 | } 94 | 95 | 96 | /** 97 | * Returns true if the iterator can be advanced past its current 98 | * location. 99 | * 100 | * @return a boolean value 101 | */ 102 | @Override 103 | public boolean hasNext() { 104 | return nextIndex() >= 0; 105 | } 106 | 107 | 108 | /** 109 | * Removes the last entry returned by the iterator. 110 | * Invoking this method more than once for a single entry 111 | * will leave the underlying data structure in a confused 112 | * state. 113 | */ 114 | @Override 115 | public void remove() { 116 | if (_expectedSize != _hash.size()) { 117 | throw new ConcurrentModificationException(); 118 | } 119 | 120 | // Disable auto compaction during the remove. This is a workaround for bug 1642768. 121 | try { 122 | _hash.tempDisableAutoCompaction(); 123 | _hash.removeAt(_index); 124 | } 125 | finally { 126 | _hash.reenableAutoCompaction( false ); 127 | } 128 | 129 | _expectedSize--; 130 | } 131 | 132 | 133 | /** 134 | * Sets the internal index so that the `next' object 135 | * can be returned. 136 | */ 137 | protected final void moveToNextIndex() { 138 | // doing the assignment && < 0 in one line shaves 139 | // 3 opcodes... 140 | if ( ( _index = nextIndex() ) < 0 ) { 141 | throw new NoSuchElementException(); 142 | } 143 | } 144 | 145 | 146 | } // TPrimitiveIterator 147 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/impl/hash/TPrimitiveHash.java: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 4 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 5 | // 6 | // This library is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation; either 9 | // version 2.1 of the License, or (at your option) any later version. 10 | // 11 | // This library is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU Lesser General Public 17 | // License along with this program; if not, write to the Free Software 18 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | /////////////////////////////////////////////////////////////////////////////// 20 | 21 | package gnu.trove.impl.hash; 22 | 23 | import gnu.trove.impl.HashFunctions; 24 | 25 | 26 | 27 | /** 28 | * The base class for hashtables of primitive values. Since there is 29 | * no notion of object equality for primitives, it isn't possible to 30 | * use a `REMOVED' object to track deletions in an open-addressed table. 31 | * So, we have to resort to using a parallel `bookkeeping' array of bytes, 32 | * in which flags can be set to indicate that a particular slot in the 33 | * hash table is FREE, FULL, or REMOVED. 34 | * 35 | * @author Eric D. Friedman, Rob Eden, Jeff Randall 36 | * @version $Id: TPrimitiveHash.java,v 1.1.2.6 2010/03/01 23:39:07 robeden Exp $ 37 | */ 38 | abstract public class TPrimitiveHash extends THash { 39 | @SuppressWarnings( { "UnusedDeclaration" } ) 40 | static final long serialVersionUID = 1L; 41 | 42 | /** 43 | * flags indicating whether each position in the hash is 44 | * FREE, FULL, or REMOVED 45 | */ 46 | public transient byte[] _states; 47 | 48 | /* constants used for state flags */ 49 | 50 | /** flag indicating that a slot in the hashtable is available */ 51 | public static final byte FREE = 0; 52 | 53 | /** flag indicating that a slot in the hashtable is occupied */ 54 | public static final byte FULL = 1; 55 | 56 | /** 57 | * flag indicating that the value of a slot in the hashtable 58 | * was deleted 59 | */ 60 | public static final byte REMOVED = 2; 61 | 62 | 63 | /** 64 | * Creates a new THash instance with the default 65 | * capacity and load factor. 66 | */ 67 | public TPrimitiveHash() { 68 | super(); 69 | } 70 | 71 | 72 | /** 73 | * Creates a new TPrimitiveHash instance with a prime 74 | * capacity at or near the specified capacity and with the default 75 | * load factor. 76 | * 77 | * @param initialCapacity an int value 78 | */ 79 | public TPrimitiveHash( int initialCapacity ) { 80 | this( initialCapacity, DEFAULT_LOAD_FACTOR ); 81 | } 82 | 83 | 84 | /** 85 | * Creates a new TPrimitiveHash instance with a prime 86 | * capacity at or near the minimum needed to hold 87 | * initialCapacity elements with load factor 88 | * loadFactor without triggering a rehash. 89 | * 90 | * @param initialCapacity an int value 91 | * @param loadFactor a float value 92 | */ 93 | public TPrimitiveHash( int initialCapacity, float loadFactor ) { 94 | super(); 95 | initialCapacity = Math.max( 1, initialCapacity ); 96 | _loadFactor = loadFactor; 97 | setUp( HashFunctions.fastCeil( initialCapacity / loadFactor ) ); 98 | } 99 | 100 | 101 | /** 102 | * Returns the capacity of the hash table. This is the true 103 | * physical capacity, without adjusting for the load factor. 104 | * 105 | * @return the physical capacity of the hash table. 106 | */ 107 | @Override 108 | public int capacity() { 109 | return _states.length; 110 | } 111 | 112 | 113 | /** 114 | * Delete the record at index. 115 | * 116 | * @param index an int value 117 | */ 118 | @Override 119 | protected void removeAt( int index ) { 120 | _states[index] = REMOVED; 121 | super.removeAt( index ); 122 | } 123 | 124 | 125 | /** 126 | * initializes the hashtable to a prime capacity which is at least 127 | * initialCapacity + 1. 128 | * 129 | * @param initialCapacity an int value 130 | * @return the actual capacity chosen 131 | */ 132 | @Override 133 | protected int setUp( int initialCapacity ) { 134 | int capacity; 135 | 136 | capacity = super.setUp( initialCapacity ); 137 | _states = new byte[capacity]; 138 | return capacity; 139 | } 140 | } // TPrimitiveHash 141 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/impl/hash/TPrimitiveOffheapHash.java: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 4 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 5 | // 6 | // This library is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation; either 9 | // version 2.1 of the License, or (at your option) any later version. 10 | // 11 | // This library is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU Lesser General Public 17 | // License along with this program; if not, write to the Free Software 18 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | /////////////////////////////////////////////////////////////////////////////// 20 | 21 | package gnu.trove.impl.hash; 22 | 23 | import gnu.trove.array.TByteOffheapArray; 24 | import gnu.trove.impl.HashFunctions; 25 | 26 | 27 | /** 28 | * The base class for hashtables of primitive values. Since there is 29 | * no notion of object equality for primitives, it isn't possible to 30 | * use a `REMOVED' object to track deletions in an open-addressed table. 31 | * So, we have to resort to using a parallel `bookkeeping' array of bytes, 32 | * in which flags can be set to indicate that a particular slot in the 33 | * hash table is FREE, FULL, or REMOVED. 34 | * 35 | * @author Eric D. Friedman, Rob Eden, Jeff Randall 36 | * @version $Id: TPrimitiveOffheapHash.java,v 1.1.2.6 2010/03/01 23:39:07 robeden Exp $ 37 | */ 38 | abstract public class TPrimitiveOffheapHash extends THash { 39 | static final long serialVersionUID = 1L; 40 | 41 | /** 42 | * flags indicating whether each position in the hash is 43 | * FREE, FULL, or REMOVED 44 | */ 45 | public transient TByteOffheapArray _states; 46 | 47 | /* constants used for state flags */ 48 | 49 | /** flag indicating that a slot in the hashtable is available */ 50 | public static final byte FREE = 0; 51 | 52 | /** flag indicating that a slot in the hashtable is occupied */ 53 | public static final byte FULL = 1; 54 | 55 | /** 56 | * flag indicating that the value of a slot in the hashtable 57 | * was deleted 58 | */ 59 | public static final byte REMOVED = 2; 60 | 61 | 62 | /** 63 | * Creates a new TPrimitiveOffheapHash instance with the default 64 | * capacity and load factor. 65 | */ 66 | public TPrimitiveOffheapHash() { 67 | this( DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR ); 68 | } 69 | 70 | 71 | /** 72 | * Creates a new TPrimitiveHash instance with a prime 73 | * capacity at or near the specified capacity and with the default 74 | * load factor. 75 | * 76 | * @param initialCapacity an int value 77 | */ 78 | public TPrimitiveOffheapHash( int initialCapacity ) { 79 | this( initialCapacity, DEFAULT_LOAD_FACTOR ); 80 | } 81 | 82 | 83 | /** 84 | * Creates a new TPrimitiveHash instance with a prime 85 | * capacity at or near the minimum needed to hold 86 | * initialCapacity elements with load factor 87 | * loadFactor without triggering a rehash. 88 | * 89 | * @param initialCapacity an int value 90 | * @param loadFactor a float value 91 | */ 92 | public TPrimitiveOffheapHash( int initialCapacity, float loadFactor ) { 93 | super(); 94 | initialCapacity = Math.max( 1, initialCapacity ); 95 | _loadFactor = loadFactor; 96 | setUp( HashFunctions.fastCeil( initialCapacity / loadFactor ) ); 97 | } 98 | 99 | 100 | /** 101 | * Returns the capacity of the hash table. This is the true 102 | * physical capacity, without adjusting for the load factor. 103 | * 104 | * @return the physical capacity of the hash table. 105 | */ 106 | @Override 107 | public int capacity() { 108 | return (int)_states.capacity(); 109 | } 110 | 111 | 112 | /** 113 | * Delete the record at index. 114 | * 115 | * @param index an int value 116 | */ 117 | @Override 118 | protected void removeAt( int index ) { 119 | _states.put(index, REMOVED); 120 | super.removeAt( index ); 121 | } 122 | 123 | 124 | /** 125 | * initializes the hashtable to a prime capacity which is at least 126 | * initialCapacity + 1. 127 | * 128 | * @param initialCapacity an int value 129 | * @return the actual capacity chosen 130 | */ 131 | @Override 132 | protected int setUp( int initialCapacity ) { 133 | int capacity; 134 | 135 | capacity = super.setUp( initialCapacity ); 136 | _states = new TByteOffheapArray( capacity ); 137 | return capacity; 138 | } 139 | } // TPrimitiveOffheapHash 140 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/impl/package.html: -------------------------------------------------------------------------------- 1 | 20 | 21 | This package (and its sub-packages) contain internal implementations used in Trove. These 22 | classes should not be accessed directly (treat them like com.sun 23 | classes. 24 | 25 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/impl/sync/SynchronizedCollection.java: -------------------------------------------------------------------------------- 1 | // //////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | // //////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.impl.sync; 20 | 21 | import java.io.IOException; 22 | import java.io.ObjectOutputStream; 23 | import java.io.Serializable; 24 | import java.util.Collection; 25 | import java.util.Iterator; 26 | 27 | 28 | /** 29 | * 30 | */ 31 | class SynchronizedCollection implements Collection, Serializable { 32 | private static final long serialVersionUID = 3053995032091335093L; 33 | 34 | final Collection c; // Backing Collection 35 | final Object mutex; // Object on which to synchronize 36 | 37 | SynchronizedCollection( Collection c, Object mutex ) { 38 | this.c = c; 39 | this.mutex = mutex; 40 | } 41 | 42 | @Override 43 | public int size() { 44 | synchronized( mutex ) { return c.size(); } 45 | } 46 | @Override 47 | public boolean isEmpty() { 48 | synchronized( mutex ) { return c.isEmpty(); } 49 | } 50 | @Override 51 | public boolean contains( Object o ) { 52 | synchronized( mutex ) { return c.contains( o ); } 53 | } 54 | @Override 55 | public Object[] toArray() { 56 | synchronized( mutex ) { return c.toArray(); } 57 | } 58 | @Override 59 | public T[] toArray( T[] a ) { 60 | synchronized( mutex ) { return c.toArray( a ); } 61 | } 62 | 63 | @Override 64 | public Iterator iterator() { 65 | return c.iterator(); // Must be manually synched by user! 66 | } 67 | 68 | @Override 69 | public boolean add( E e ) { 70 | synchronized( mutex ) { return c.add( e ); } 71 | } 72 | @Override 73 | public boolean remove( Object o ) { 74 | synchronized( mutex ) { return c.remove( o ); } 75 | } 76 | 77 | @Override 78 | public boolean containsAll( Collection coll ) { 79 | synchronized( mutex ) { return c.containsAll( coll ); } 80 | } 81 | @Override 82 | public boolean addAll( Collection coll ) { 83 | synchronized( mutex ) { return c.addAll( coll ); } 84 | } 85 | @Override 86 | public boolean removeAll( Collection coll ) { 87 | synchronized( mutex ) { return c.removeAll( coll ); } 88 | } 89 | @Override 90 | public boolean retainAll( Collection coll ) { 91 | synchronized( mutex ) { return c.retainAll( coll ); } 92 | } 93 | @Override 94 | public void clear() { 95 | synchronized( mutex ) { c.clear(); } 96 | } 97 | @Override 98 | public String toString() { 99 | synchronized( mutex ) { return c.toString(); } 100 | } 101 | private void writeObject( ObjectOutputStream s ) throws IOException { 102 | synchronized( mutex ) { s.defaultWriteObject(); } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/impl/sync/SynchronizedSet.java: -------------------------------------------------------------------------------- 1 | // //////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | // //////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.impl.sync; 20 | 21 | import java.util.Set; 22 | 23 | 24 | /** Local implementation of SynchronizedSet so we can set the mutex explicitly. */ 25 | class SynchronizedSet extends SynchronizedCollection implements Set { 26 | private static final long serialVersionUID = 487447009682186044L; 27 | 28 | SynchronizedSet( Set s, Object mutex ) { super( s, mutex ); } 29 | @Override 30 | public boolean equals( Object o ) { synchronized( mutex ) { return c.equals( o ); } } 31 | @Override 32 | public int hashCode() { synchronized( mutex ) { return c.hashCode(); } } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/iterator/TAdvancingIterator.java: -------------------------------------------------------------------------------- 1 | // //////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | // //////////////////////////////////////////////////////////////////////////// 18 | package gnu.trove.iterator; 19 | 20 | /** 21 | * Common interface for iterators that operate via the "advance" method for moving the 22 | * cursor to the next element. 23 | */ 24 | public interface TAdvancingIterator extends TIterator { 25 | /** 26 | * Moves the iterator forward to the next entry. 27 | * 28 | * @throws java.util.NoSuchElementException if the iterator is already exhausted 29 | */ 30 | public void advance(); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/iterator/TIterator.java: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | package gnu.trove.iterator; 19 | 20 | /** 21 | * Common interface for all iterators used in Trove. 22 | */ 23 | public interface TIterator { 24 | /** 25 | * Returns true if the iterator can be advanced past its current location. 26 | * 27 | * @return a boolean value 28 | */ 29 | public boolean hasNext(); 30 | 31 | /** 32 | * Removes the last entry returned by the iterator. The result of invoking this method 33 | * more than once for a single entry is undefined and can leave the underlying data 34 | * structure in a confused state. 35 | */ 36 | public void remove(); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/iterator/TPrimitiveIterator.java: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 4 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 5 | // 6 | // This library is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation; either 9 | // version 2.1 of the License, or (at your option) any later version. 10 | // 11 | // This library is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU Lesser General Public 17 | // License along with this program; if not, write to the Free Software 18 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | /////////////////////////////////////////////////////////////////////////////// 20 | 21 | package gnu.trove.iterator; 22 | 23 | /** 24 | * Implements all iterator functions for the hashed object set. 25 | * Subclasses may override objectAtIndex to vary the object 26 | * returned by calls to next() (e.g. for values, and Map.Entry 27 | * objects). 28 | *

29 | *

Note that iteration is fastest if you forego the calls to 30 | * hasNext in favor of checking the size of the structure 31 | * yourself and then call next() that many times: 32 | *

33 | *

34 |  * Iterator i = collection.iterator();
35 |  * for (int size = collection.size(); size-- > 0;) {
36 |  *   Object o = i.next();
37 |  * }
38 |  * 
39 | *

40 | *

You may, of course, use the hasNext(), next() idiom too if 41 | * you aren't in a performance critical spot.

42 | */ 43 | public interface TPrimitiveIterator extends TIterator { 44 | /** 45 | * Returns true if the iterator can be advanced past its current 46 | * location. 47 | * 48 | * @return a boolean value 49 | */ 50 | @Override 51 | public boolean hasNext(); 52 | 53 | 54 | /** 55 | * Removes the last entry returned by the iterator. 56 | * Invoking this method more than once for a single entry 57 | * will leave the underlying data structure in a confused 58 | * state. 59 | */ 60 | @Override 61 | public void remove(); 62 | 63 | } // TPrimitiveIterator 64 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/iterator/hash/TObjectHashIterator.java: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 4 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 5 | // 6 | // This library is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation; either 9 | // version 2.1 of the License, or (at your option) any later version. 10 | // 11 | // This library is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU Lesser General Public 17 | // License along with this program; if not, write to the Free Software 18 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | /////////////////////////////////////////////////////////////////////////////// 20 | 21 | 22 | package gnu.trove.iterator.hash; 23 | 24 | import gnu.trove.impl.hash.TObjectHash; 25 | import gnu.trove.impl.hash.THashIterator; 26 | 27 | 28 | /** 29 | * Iterator for hashtables that use open addressing to resolve collisions. 30 | * 31 | * @author Eric D. Friedman 32 | * @author Rob Eden 33 | * @author Jeff Randall 34 | * @version $Id: TObjectHashIterator.java,v 1.1.2.4 2009/10/09 01:44:34 robeden Exp $ 35 | */ 36 | 37 | public class TObjectHashIterator extends THashIterator { 38 | 39 | protected final TObjectHash _objectHash; 40 | 41 | 42 | public TObjectHashIterator( TObjectHash hash ) { 43 | super( hash ); 44 | _objectHash = hash; 45 | } 46 | 47 | 48 | @Override 49 | @SuppressWarnings("unchecked") 50 | protected E objectAtIndex( int index ) { 51 | Object obj = _objectHash._set[index]; 52 | if ( obj == TObjectHash.FREE || obj == TObjectHash.REMOVED ) { 53 | return null; 54 | } 55 | return (E) obj; 56 | } 57 | 58 | } // TObjectHashIterator 59 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/list/TLinkable.java: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.list; 20 | 21 | import java.io.Serializable; 22 | 23 | 24 | 25 | /** 26 | * Interface for Objects which can be inserted into a TLinkedList. 27 | * 28 | * @author Eric D. Friedman 29 | * @version $Id: TLinkable.java,v 1.1.2.2 2009/09/04 12:32:33 upholderoftruth Exp $ 30 | * @see gnu.trove.list.linked.TLinkedList 31 | */ 32 | 33 | public interface TLinkable extends Serializable { 34 | static final long serialVersionUID = 997545054865482562L; 35 | 36 | /** 37 | * Returns the linked list node after this one. 38 | * 39 | * @return a TLinkable value 40 | */ 41 | public T getNext(); 42 | 43 | 44 | /** 45 | * Returns the linked list node before this one. 46 | * 47 | * @return a TLinkable value 48 | */ 49 | public T getPrevious(); 50 | 51 | 52 | /** 53 | * Sets the linked list node after this one. 54 | * 55 | * @param linkable a TLinkable value 56 | */ 57 | public void setNext( T linkable ); 58 | 59 | 60 | /** 61 | * Sets the linked list node before this one. 62 | * 63 | * @param linkable a TLinkable value 64 | */ 65 | public void setPrevious( T linkable ); 66 | }// TLinkable 67 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/list/TLinkableAdapter.java: -------------------------------------------------------------------------------- 1 | package gnu.trove.list; 2 | 3 | /** 4 | * Simple adapter class implementing {@link TLinkable}, so you don't have to. Example: 5 | *
 6 | 	private class MyObject extends TLinkableAdapter {
 7 | 		private final String value;
 8 | 
 9 | 		MyObject( String value ) {
10 | 			this.value = value;
11 | 		}
12 | 		
13 | 		public String getValue() {
14 | 			return value;
15 | 		}
16 | 	}
17 |  * 
18 | */ 19 | public abstract class TLinkableAdapter implements TLinkable { 20 | private volatile T next; 21 | private volatile T prev; 22 | 23 | @Override 24 | public T getNext() { 25 | return next; 26 | } 27 | 28 | @Override 29 | public void setNext( T next ) { 30 | this.next = next; 31 | } 32 | 33 | @Override 34 | public T getPrevious() { 35 | return prev; 36 | } 37 | 38 | @Override 39 | public void setPrevious( T prev ) { 40 | this.prev = prev; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/map/TMap.java: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2011, Rob Eden All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.map; 20 | 21 | import gnu.trove.function.TObjectFunction; 22 | import gnu.trove.procedure.TObjectObjectProcedure; 23 | import gnu.trove.procedure.TObjectProcedure; 24 | 25 | import java.util.Map; 26 | 27 | 28 | /** 29 | * Interface extension to {@link Map} which adds Trove-specific features. 30 | */ 31 | public interface TMap extends Map { 32 | 33 | /** 34 | * Inserts a key/value pair into the map if the specified key is not already 35 | * associated with a value. 36 | * 37 | * @param key an Object value 38 | * @param value an Object value 39 | * @return the previous value associated with key, 40 | * or {@code null} if none was found. 41 | */ 42 | public V putIfAbsent(K key, V value); 43 | 44 | 45 | /** 46 | * Executes procedure for each key in the map. 47 | * 48 | * @param procedure a TObjectProcedure value 49 | * @return false if the loop over the keys terminated because 50 | * the procedure returned false for some key. 51 | */ 52 | public boolean forEachKey(TObjectProcedure procedure); 53 | 54 | 55 | /** 56 | * Executes procedure for each value in the map. 57 | * 58 | * @param procedure a TObjectProcedure value 59 | * @return false if the loop over the values terminated because 60 | * the procedure returned false for some value. 61 | */ 62 | public boolean forEachValue(TObjectProcedure procedure); 63 | 64 | 65 | /** 66 | * Executes procedure for each key/value entry in the 67 | * map. 68 | * 69 | * @param procedure a TObjectObjectProcedure value 70 | * @return false if the loop over the entries terminated because 71 | * the procedure returned false for some entry. 72 | */ 73 | @SuppressWarnings({"unchecked"}) 74 | public boolean forEachEntry(TObjectObjectProcedure procedure); 75 | 76 | 77 | /** 78 | * Retains only those entries in the map for which the procedure 79 | * returns a true value. 80 | * 81 | * @param procedure determines which entries to keep 82 | * @return true if the map was modified. 83 | */ 84 | @SuppressWarnings({"unchecked"}) 85 | public boolean retainEntries(TObjectObjectProcedure procedure); 86 | 87 | 88 | /** 89 | * Transform the values in this map using function. 90 | * 91 | * @param function a TObjectFunction value 92 | */ 93 | public void transformValues(TObjectFunction function); 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/procedure/TObjectObjectProcedure.java: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.procedure; 20 | 21 | /** 22 | * Interface for procedures that take two Object parameters. 23 | *

24 | * Created: Mon Nov 5 22:03:30 2001 25 | * 26 | * @author Eric D. Friedman 27 | * @version $Id: TObjectObjectProcedure.java,v 1.1.2.1 2009/09/06 17:02:20 upholderoftruth Exp $ 28 | */ 29 | 30 | public interface TObjectObjectProcedure { 31 | 32 | /** 33 | * Executes this procedure. A false return value indicates that 34 | * the application executing this procedure should not invoke this 35 | * procedure again. 36 | * 37 | * @param a an Object value 38 | * @param b an Object value 39 | * @return true if additional invocations of the procedure are 40 | * allowed. 41 | */ 42 | public boolean execute( K a, V b ); 43 | }// TObjectObjectProcedure 44 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/procedure/TObjectProcedure.java: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | 20 | package gnu.trove.procedure; 21 | 22 | /** 23 | * Interface for procedures with one Object parameter. 24 | * 25 | * Created: Mon Nov 5 21:45:49 2001 26 | * 27 | * @author Eric D. Friedman 28 | * @version $Id: TObjectProcedure.java,v 1.1.2.1 2009/09/02 21:52:33 upholderoftruth Exp $ 29 | */ 30 | 31 | public interface TObjectProcedure { 32 | /** 33 | * Executes this procedure. A false return value indicates that 34 | * the application executing this procedure should not invoke this 35 | * procedure again. 36 | * 37 | * @param object an Object value 38 | * @return true if additional invocations of the procedure are 39 | * allowed. 40 | */ 41 | public boolean execute(T object); 42 | }// TObjectProcedure 43 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/procedure/array/ToObjectArrayProceedure.java: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.procedure.array; 20 | 21 | import gnu.trove.procedure.TObjectProcedure; 22 | 23 | 24 | 25 | /** 26 | * A procedure which stores each value it receives into a target array. 27 | *

28 | * Created: Sat Jan 12 10:13:42 2002 29 | * 30 | * @author Eric D. Friedman 31 | * @version $Id: ToObjectArrayProceedure.java,v 1.1.2.1 2009/09/02 21:52:33 upholderoftruth Exp $ 32 | */ 33 | 34 | public final class ToObjectArrayProceedure implements TObjectProcedure { 35 | 36 | private final T[] target; 37 | private int pos = 0; 38 | 39 | 40 | public ToObjectArrayProceedure( final T[] target ) { 41 | this.target = target; 42 | } 43 | 44 | 45 | @Override 46 | public final boolean execute( T value ) { 47 | target[pos++] = value; 48 | return true; 49 | } 50 | } // ToObjectArrayProcedure 51 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/strategy/HashingStrategy.java: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2002, Eric D. Friedman All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.strategy; 20 | 21 | import java.io.Serializable; 22 | 23 | 24 | /** 25 | * Interface to support pluggable hashing strategies in maps and sets. 26 | * Implementers can use this interface to make the trove hashing 27 | * algorithms use object values, values provided by the java runtime, 28 | * or a custom strategy when computing hashcodes. 29 | * 30 | * @author Eric Friedman 31 | * @author Rob Eden 32 | */ 33 | 34 | public interface HashingStrategy extends Serializable { 35 | static final long serialVersionUID = 5674097166776615540L; 36 | 37 | /** 38 | * Computes a hash code for the specified object. Implementers 39 | * can use the object's own hashCode method, the Java 40 | * runtime's identityHashCode, or a custom scheme. 41 | * 42 | * @param object for which the hashcode is to be computed 43 | * @return the hashCode 44 | */ 45 | int computeHashCode( T object ); 46 | 47 | /** 48 | * Compares o1 and o2 for equality. Strategy implementers may use 49 | * the objects' own equals() methods, compare object references, 50 | * or implement some custom scheme. 51 | * 52 | * @param o1 an Object value 53 | * @param o2 an Object value 54 | * @return true if the objects are equal according to this strategy. 55 | */ 56 | boolean equals( T o1, T o2 ); 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/gnu/trove/strategy/IdentityHashingStrategy.java: -------------------------------------------------------------------------------- 1 | package gnu.trove.strategy; 2 | 3 | /** 4 | * A {@link gnu.trove.strategy.HashingStrategy} that does identity comparisons 5 | * (==) and uses {@link System#identityHashCode(Object)} for hashCode generation. 6 | */ 7 | public class IdentityHashingStrategy implements HashingStrategy { 8 | static final long serialVersionUID = -5188534454583764904L; 9 | 10 | 11 | /** 12 | * A single instance that can be shared with multiple collections. 13 | * This instance is thread safe. 14 | */ 15 | public static final IdentityHashingStrategy INSTANCE = 16 | new IdentityHashingStrategy(); 17 | 18 | 19 | @Override 20 | public int computeHashCode( K object ) { 21 | return System.identityHashCode( object ); 22 | } 23 | 24 | @Override 25 | public boolean equals( K o1, K o2 ) { 26 | return o1 == o2; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/gnu/trove/TDecoratorsTest.java: -------------------------------------------------------------------------------- 1 | // //////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | // //////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove; 20 | 21 | import gnu.trove.list.TIntList; 22 | import gnu.trove.list.array.TIntArrayList; 23 | import junit.framework.TestCase; 24 | 25 | import java.util.Iterator; 26 | import java.util.List; 27 | 28 | 29 | /** 30 | * 31 | */ 32 | public class TDecoratorsTest extends TestCase { 33 | public void testIntListDecorator() { 34 | TIntList list = new TIntArrayList(); 35 | list.add( 2 ); 36 | list.add( 3 ); 37 | list.add( 4 ); 38 | list.add( 5 ); 39 | list.add( 6 ); 40 | 41 | List wrapped_list = TDecorators.wrap( list ); 42 | assertEquals( 5, wrapped_list.size() ); 43 | assertEquals( Integer.valueOf( 2 ), wrapped_list.get( 0 ) ); 44 | assertEquals( Integer.valueOf( 3 ), wrapped_list.get( 1 ) ); 45 | assertEquals( Integer.valueOf( 4 ), wrapped_list.get( 2 ) ); 46 | assertEquals( Integer.valueOf( 5 ), wrapped_list.get( 3 ) ); 47 | assertEquals( Integer.valueOf( 6 ), wrapped_list.get( 4 ) ); 48 | 49 | list.removeAt( 1 ); 50 | 51 | assertEquals( 4, list.size() ); 52 | assertEquals( Integer.valueOf( 2 ), wrapped_list.get( 0 ) ); 53 | assertEquals( Integer.valueOf( 4 ), wrapped_list.get( 1 ) ); 54 | assertEquals( Integer.valueOf( 5 ), wrapped_list.get( 2 ) ); 55 | assertEquals( Integer.valueOf( 6 ), wrapped_list.get( 3 ) ); 56 | 57 | wrapped_list.remove( 1 ); 58 | 59 | assertEquals( 3, list.size() ); 60 | assertEquals( 2, list.get( 0 ) ); 61 | assertEquals( 5, list.get( 1 ) ); 62 | assertEquals( 6, list.get( 2 ) ); 63 | 64 | list.clear(); 65 | assertTrue( wrapped_list.isEmpty() ); 66 | 67 | wrapped_list.add( Integer.valueOf( 7 ) ); 68 | assertEquals( 1, list.size() ); 69 | assertEquals( 7, list.get( 0 ) ); 70 | 71 | wrapped_list.clear(); 72 | assertTrue( list.isEmpty() ); 73 | 74 | list.add( 8 ); 75 | list.add( 9 ); 76 | list.add( 10 ); 77 | 78 | Iterator wrapper_list_it = wrapped_list.iterator(); 79 | assertTrue( wrapper_list_it.hasNext() ); 80 | assertEquals( Integer.valueOf( 8 ), wrapper_list_it.next() ); 81 | assertTrue( wrapper_list_it.hasNext() ); 82 | assertEquals( Integer.valueOf( 9 ), wrapper_list_it.next() ); 83 | assertTrue( wrapper_list_it.hasNext() ); 84 | assertEquals( Integer.valueOf( 10 ), wrapper_list_it.next() ); 85 | assertFalse( wrapper_list_it.hasNext() ); 86 | 87 | wrapper_list_it = wrapped_list.iterator(); 88 | assertTrue( wrapper_list_it.hasNext() ); 89 | assertEquals( Integer.valueOf( 8 ), wrapper_list_it.next() ); 90 | wrapper_list_it.remove(); 91 | assertTrue( wrapper_list_it.hasNext() ); 92 | assertEquals( Integer.valueOf( 9 ), wrapper_list_it.next() ); 93 | assertTrue( wrapper_list_it.hasNext() ); 94 | assertEquals( Integer.valueOf( 10 ), wrapper_list_it.next() ); 95 | assertFalse( wrapper_list_it.hasNext() ); 96 | 97 | assertEquals( 2, list.size() ); 98 | assertEquals( 9, list.get( 0 ) ); 99 | assertEquals( 10, list.get( 1 ) ); 100 | } 101 | 102 | public void testIntListDecoratorSubList() { 103 | TIntList list = new TIntArrayList(); 104 | list.add( 2 ); 105 | list.add( 3 ); 106 | list.add( 4 ); 107 | list.add( 5 ); 108 | list.add( 6 ); 109 | 110 | List wrapped_list = TDecorators.wrap( list ); 111 | 112 | List sublist = wrapped_list.subList( 1, 4 ); 113 | assertEquals( 3, sublist.size() ); 114 | assertEquals( Integer.valueOf( 3 ), sublist.get( 0 ) ); 115 | assertEquals( Integer.valueOf( 4 ), sublist.get( 1 ) ); 116 | assertEquals( Integer.valueOf( 5 ), sublist.get( 2 ) ); 117 | 118 | sublist.clear(); 119 | 120 | assertEquals( 2, list.size() ); 121 | assertEquals( 2, list.get( 0 ) ); 122 | assertEquals( 6, list.get( 1 ) ); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/test/java/gnu/trove/array/TPrimitiveOffheapArrayTest.java: -------------------------------------------------------------------------------- 1 | package gnu.trove.array; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import junit.framework.TestCase; 7 | 8 | public class TPrimitiveOffheapArrayTest extends TestCase { 9 | 10 | private TIntOffheapArray list; 11 | 12 | @Override 13 | public void setUp() throws Exception { 14 | super.setUp(); 15 | 16 | list = new TIntOffheapArray(5); 17 | assertEquals(5, list.capacity()); 18 | list.put(0, 1); 19 | list.put(1, 2); 20 | list.put(2, 3); 21 | list.put(3, 4); 22 | list.put(4, 5); 23 | } 24 | 25 | 26 | @Override 27 | public void tearDown() throws Exception { 28 | super.tearDown(); 29 | } 30 | 31 | public void testGet() { 32 | for (int i = 0; i < 5; i++) { 33 | assertEquals(i + 1, list.get(i)); 34 | } 35 | 36 | try { 37 | list.get(list.capacity()); 38 | fail("Expected IndexOutOfBoundsException"); 39 | } 40 | catch (IndexOutOfBoundsException ex) { 41 | // Expected 42 | } 43 | } 44 | 45 | public void testPut() { 46 | list.put(0, 5); 47 | list.put(1, 4); 48 | list.put(2, 3); 49 | list.put(3, 2); 50 | list.put(4, 1); 51 | 52 | for (int i = 0; i < 5; i++) { 53 | assertEquals(5 - i, list.get(i)); 54 | } 55 | 56 | try { 57 | list.put(5, 20); 58 | fail("Expected IndexOutOfBoundsException"); 59 | } 60 | catch ( IndexOutOfBoundsException ex ) { 61 | // Expected 62 | } 63 | } 64 | 65 | public void testResize() { 66 | list.resize(10); 67 | testGet(); 68 | list.put(9, 100); 69 | assertEquals(0, list.get(8)); 70 | assertEquals(100, list.get(9)); 71 | 72 | list.resize(3); 73 | assertEquals(3, list.capacity()); 74 | for (int i = 0; i < 3; i++) { 75 | assertEquals(i + 1, list.get(i)); 76 | } 77 | } 78 | 79 | public void testResizeStress() { 80 | list.clear(); 81 | for (int i = 1; i < 1000000; i++) { 82 | list.resize(5 * i); 83 | list.put(5 * i - 1, i); 84 | } 85 | for (int i = 1; i < 1000000; i++) { 86 | assertEquals(0, list.get(5 * i - 2)); 87 | assertEquals(i, list.get(5 * i - 1)); 88 | } 89 | } 90 | 91 | public void testClear() { 92 | list.clear(); 93 | assertEquals(5, list.capacity()); 94 | 95 | for (int i = 0; i < 5; i++) { 96 | assertEquals(0, list.get(i)); 97 | } 98 | } 99 | 100 | public void testFree() { 101 | list.free(); 102 | try { 103 | list.put(0, 20); 104 | fail("Expected IndexOutOfBoundsException"); 105 | } 106 | catch ( IndexOutOfBoundsException ex ) { 107 | // Expected 108 | } 109 | } 110 | 111 | public void testFreeStress() { 112 | List list = new ArrayList(); 113 | for (int i = 0; i < 10000; i++) { 114 | list.add(new TIntOffheapArray(1000000 + 100 * i)); 115 | list.get(i).free(); 116 | } 117 | } 118 | 119 | // TODO: Figure out why these are crashing and reenable 120 | //public void testGcStress() { 121 | // for (int i = 0; i < 100; i++) { 122 | // new TIntOffheapArray(50000000); 123 | // } 124 | //} 125 | 126 | public void testToArray() { 127 | int[] array = new int[10]; 128 | list.toArray(2, array, 1, 3); 129 | assertEquals(0, array[0]); 130 | assertEquals(3, array[1]); 131 | assertEquals(4, array[2]); 132 | assertEquals(5, array[3]); 133 | assertEquals(0, array[4]); 134 | 135 | list.resize(100); 136 | for (int i = 0; i < 100; i++) { 137 | list.put(i, i); 138 | } 139 | array = new int[100]; 140 | list.toArray(30, array, 20, 60); 141 | for (int i = 0; i < 20; i++) { 142 | assertEquals(0, array[i]); 143 | } 144 | for (int i = 20; i < 80; i++) { 145 | assertEquals(i + 10, array[i]); 146 | } 147 | for (int i = 80; i < 100; i++) { 148 | assertEquals(0, array[i]); 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/test/java/gnu/trove/impl/PrimeFinderTest.java: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001-2006, Eric D. Friedman All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | 20 | package gnu.trove.impl; 21 | 22 | import junit.framework.*; 23 | import gnu.trove.impl.PrimeFinder; 24 | 25 | 26 | 27 | /** 28 | * 29 | * Created: Sun Nov 4 11:37:24 2001 30 | * 31 | * @author Eric D. Friedman 32 | * @version $Id: PrimeFinderTest.java,v 1.1.2.1 2009/11/07 03:55:33 robeden Exp $ 33 | */ 34 | 35 | public class PrimeFinderTest extends TestCase { 36 | 37 | public PrimeFinderTest(String name) { 38 | super(name); 39 | } 40 | 41 | public void testPrimeFinder() throws Exception { 42 | int r = PrimeFinder.nextPrime(999999); 43 | assertEquals(1070981,r); 44 | } 45 | } // PrimeFinderTests 46 | -------------------------------------------------------------------------------- /src/test/java/gnu/trove/impl/hash/HashTestKit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * //////////////////////////////////////////////////////////////////////////// 3 | * // Copyright (c) 2010, Rob Eden All Rights Reserved. 4 | * // 5 | * // This library is free software; you can redistribute it and/or 6 | * // modify it under the terms of the GNU Lesser General Public 7 | * // License as published by the Free Software Foundation; either 8 | * // version 2.1 of the License, or (at your option) any later version. 9 | * // 10 | * // This library is distributed in the hope that it will be useful, 11 | * // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * // GNU General Public License for more details. 14 | * // 15 | * // You should have received a copy of the GNU Lesser General Public 16 | * // License along with this program; if not, write to the Free Software 17 | * // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | * /////////////////////////////////////////////////////////////////////////////// 19 | */ 20 | 21 | package gnu.trove.impl.hash; 22 | 23 | import junit.framework.TestCase; 24 | 25 | 26 | /** 27 | * Static functions for unit tests 28 | */ 29 | public class HashTestKit { 30 | /** 31 | * Confirm that the internal FREE counter matches the values in the slots. 32 | */ 33 | public static void checkFreeSlotCount( THash hash, Object[] slot_keys, 34 | Object free_marker ) { 35 | 36 | int free_counter = hash._free; 37 | 38 | int count = 0; 39 | for( Object slot_key : slot_keys ) { 40 | if ( slot_key == free_marker ) count++; 41 | } 42 | 43 | TestCase.assertEquals( free_counter, count ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/gnu/trove/impl/hash/TObjectHashTest.java: -------------------------------------------------------------------------------- 1 | package gnu.trove.impl.hash; 2 | 3 | import gnu.trove.map.hash.TObjectLongHashMap; 4 | import junit.framework.TestCase; 5 | 6 | 7 | /** 8 | * 9 | */ 10 | public class TObjectHashTest extends TestCase { 11 | // Test case bug bug ID 3067307 12 | public static void testBug3067307() { 13 | TObjectLongHashMap testHash = new TObjectLongHashMap(); 14 | final int c = 1000; 15 | for ( long i = 1; i < c; i++ ) { 16 | final String data = "test-" + i; 17 | testHash.put( data, i ); 18 | testHash.remove( data ); 19 | } 20 | } 21 | 22 | // Test case bug bug ID 3067307 23 | public static void testBug3067307_noAutoCompact() { 24 | TObjectLongHashMap testHash = new TObjectLongHashMap(); 25 | testHash.setAutoCompactionFactor( 0 ); 26 | final int c = 1000; 27 | for ( long i = 1; i < c; i++ ) { 28 | final String data = "test-" + i; 29 | testHash.put( data, i ); 30 | testHash.remove( data ); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/gnu/trove/list/linked/TLinkableAdapterTest.java: -------------------------------------------------------------------------------- 1 | package gnu.trove.list.linked; 2 | 3 | import gnu.trove.list.TLinkableAdapter; 4 | import junit.framework.TestCase; 5 | 6 | 7 | /** 8 | * 9 | */ 10 | public class TLinkableAdapterTest extends TestCase { 11 | public void testOverride() { 12 | TLinkedList list = new TLinkedList(); 13 | 14 | list.add( new MyObject( "1" ) ); 15 | list.add( new MyObject( "2" ) ); 16 | list.add( new MyObject( "3" ) ); 17 | 18 | int i = 1; 19 | for( MyObject obj : list ) { 20 | assertEquals( String.valueOf( i ), obj.getValue() ); 21 | i++; 22 | } 23 | } 24 | 25 | 26 | private class MyObject extends TLinkableAdapter { 27 | private final String value; 28 | 29 | MyObject( String value ) { 30 | this.value = value; 31 | } 32 | 33 | 34 | public String getValue() { 35 | return value; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/gnu/trove/map/hash/ArrayHashingStrategy.java: -------------------------------------------------------------------------------- 1 | package gnu.trove.map.hash; 2 | 3 | import java.io.Serializable; 4 | import java.util.Arrays; 5 | 6 | import gnu.trove.strategy.HashingStrategy; 7 | 8 | 9 | /** 10 | * 11 | */ 12 | public class ArrayHashingStrategy 13 | implements HashingStrategy, Serializable { 14 | 15 | @Override 16 | public int computeHashCode( char[] o ) { 17 | return Arrays.hashCode( o ); 18 | } 19 | 20 | @Override 21 | public boolean equals( char[] o1, char[] o2 ) { 22 | return Arrays.equals( o1, o2 ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/gnu/trove/map/hash/NoEntryValueTest.java: -------------------------------------------------------------------------------- 1 | package gnu.trove.map.hash; 2 | 3 | import gnu.trove.map.TObjectIntMap; 4 | import junit.framework.TestCase; 5 | 6 | import java.util.Arrays; 7 | 8 | 9 | /** 10 | * Test for a number of bugs related to no_entry_value, including 3432402 11 | */ 12 | public class NoEntryValueTest extends TestCase { 13 | public void testAdjustToNoEntry() { 14 | TObjectIntMap map = new TObjectIntHashMap(); 15 | 16 | assertEquals( 0, map.getNoEntryValue() ); 17 | assertEquals( 0, map.get( "NotInThere" ) ); 18 | 19 | map.put( "Value", 1 ); 20 | assertEquals( 1, map.size() ); 21 | assertEquals( 1, map.get( "Value" ) ); 22 | assertTrue( map.containsKey( "Value" ) ); 23 | assertTrue( map.containsValue( 1 ) ); 24 | assertTrue( Arrays.equals( new int[] { 1 }, map.values() ) ); 25 | 26 | map.adjustValue( "Value", -1 ); 27 | assertEquals( 1, map.size() ); 28 | assertEquals( 0, map.get( "Value" ) ); 29 | assertTrue( map.containsKey( "Value" ) ); 30 | assertTrue( map.containsValue( 0 ) ); 31 | assertTrue( Arrays.equals( new int[] { 0 }, map.values() ) ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/gnu/trove/map/hash/TCustomHashMapTest.java: -------------------------------------------------------------------------------- 1 | package gnu.trove.map.hash; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.ObjectInputStream; 6 | import java.io.ObjectOutputStream; 7 | import java.util.ArrayList; 8 | import java.util.Arrays; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.Random; 12 | import java.util.Set; 13 | 14 | import gnu.trove.strategy.HashingStrategy; 15 | import junit.framework.TestCase; 16 | 17 | 18 | /** 19 | * 20 | */ 21 | public class TCustomHashMapTest extends TestCase { 22 | // Example from Trove overview doc 23 | public void testArray() { 24 | char[] foo = new char[]{ 'a', 'b', 'c' }; 25 | char[] bar = new char[]{ 'a', 'b', 'c' }; 26 | 27 | assertFalse( foo.hashCode() == bar.hashCode() ); 28 | //noinspection ArrayEquals 29 | assertFalse( foo.equals( bar ) ); 30 | 31 | HashingStrategy strategy = new ArrayHashingStrategy(); 32 | assertTrue( strategy.computeHashCode( foo ) == 33 | strategy.computeHashCode( bar ) ); 34 | assertTrue( strategy.equals( foo, bar ) ); 35 | 36 | Map map = new TCustomHashMap( strategy ); 37 | map.put( foo, "yay" ); 38 | assertTrue( map.containsKey( foo ) ); 39 | assertTrue( map.containsKey( bar ) ); 40 | assertEquals( "yay", map.get( foo ) ); 41 | assertEquals( "yay", map.get( bar ) ); 42 | 43 | Set keys = map.keySet(); 44 | assertTrue( keys.contains( foo ) ); 45 | assertTrue( keys.contains( bar ) ); 46 | } 47 | 48 | 49 | public void testSerialization() throws Exception { 50 | char[] foo = new char[]{ 'a', 'b', 'c' }; 51 | char[] bar = new char[]{ 'a', 'b', 'c' }; 52 | 53 | HashingStrategy strategy = new ArrayHashingStrategy(); 54 | Map map = new TCustomHashMap( strategy ); 55 | 56 | map.put( foo, "yay" ); 57 | 58 | // Make sure it still works after being serialized 59 | ObjectOutputStream oout = null; 60 | ByteArrayOutputStream bout = null; 61 | ObjectInputStream oin = null; 62 | ByteArrayInputStream bin = null; 63 | try { 64 | bout = new ByteArrayOutputStream(); 65 | oout = new ObjectOutputStream( bout ); 66 | 67 | oout.writeObject( map ); 68 | 69 | bin = new ByteArrayInputStream( bout.toByteArray() ); 70 | oin = new ObjectInputStream( bin ); 71 | 72 | map = ( Map ) oin.readObject(); 73 | } 74 | finally { 75 | if ( oin != null ) oin.close(); 76 | if ( bin != null ) bin.close(); 77 | if ( oout != null ) oout.close(); 78 | if ( bout != null ) bout.close(); 79 | } 80 | 81 | assertTrue( map.containsKey( foo ) ); 82 | assertTrue( map.containsKey( bar ) ); 83 | assertEquals( "yay", map.get( foo ) ); 84 | assertEquals( "yay", map.get( bar ) ); 85 | 86 | Set keys = map.keySet(); 87 | assertTrue( keys.contains( foo ) ); 88 | assertTrue( keys.contains( bar ) ); 89 | } 90 | 91 | static class ByteArrayStrategy implements HashingStrategy { 92 | 93 | // Copied from Arrays.hashCode, but applied only to the first four bytes 94 | @Override 95 | public int computeHashCode( byte[] bytes ) { 96 | if ( bytes == null ) return 0; 97 | int h = 1; 98 | for ( int i = 0; i < 4; i++ ) h = 31 * h + bytes[ i ]; 99 | return h; 100 | } 101 | 102 | @Override 103 | public boolean equals( byte[] o1, byte[] o2 ) { 104 | return Arrays.equals( o1, o2 ); 105 | } 106 | } 107 | 108 | private static byte[] random( int n, Random rnd ) { 109 | byte[] ba = new byte[ n ]; 110 | for ( int i = 0; i < ba.length; i++ ) { 111 | ba[ i ] = ( byte ) rnd.nextInt(); 112 | } 113 | return ba; 114 | } 115 | 116 | public void testBug4706479() throws Exception { 117 | Random rnd = new Random( 1234 ); 118 | TCustomHashMap map = 119 | new TCustomHashMap( new ByteArrayStrategy() ); 120 | List list = new ArrayList(); 121 | List expected = new ArrayList(); 122 | 123 | for ( int i = 0; i < 1000; i++ ) { 124 | byte[] ba = random( 16, rnd ); 125 | list.add( ba ); 126 | 127 | Integer obj = Integer.valueOf( i ); 128 | expected.add( obj ); 129 | map.put( ba, obj ); 130 | } 131 | 132 | assertEquals( list.size(), map.size() ); 133 | 134 | // Make sure all the arrays are found in the map 135 | for( byte[] array : map.keySet() ) { 136 | boolean found_it = false; 137 | for( byte[] test : list ) { 138 | if ( Arrays.equals( test, array ) ) { 139 | found_it = true; 140 | break; 141 | } 142 | } 143 | 144 | assertTrue( "Unable to find: " + Arrays.toString( array ), found_it ); 145 | } 146 | // Make sure all the Integers are found in the map 147 | for( Integer obj : map.values() ) { 148 | assertTrue( "Unable to find: " + obj, expected.contains( obj ) ); 149 | } 150 | 151 | for ( int i = 0; i < expected.size(); i++ ) { 152 | assertEquals( expected.get( i ), map.get( list.get( i ) ) ); 153 | } 154 | 155 | // Remove items 156 | for ( int i = 0; i < list.size(); i++ ) { 157 | assertEquals( expected.get( i ), map.remove( list.get( i ) ) ); 158 | } 159 | 160 | assertEquals( 0, map.size() ); 161 | assertTrue( map.isEmpty() ); 162 | 163 | for ( byte[] aList : list ) { 164 | assertNull( map.get( aList ) ); 165 | } 166 | } 167 | 168 | 169 | } 170 | -------------------------------------------------------------------------------- /src/test/java/gnu/trove/map/hash/TObjectPrimitiveCustomHashMapTest.java: -------------------------------------------------------------------------------- 1 | package gnu.trove.map.hash; 2 | 3 | import gnu.trove.map.TObjectIntMap; 4 | import gnu.trove.map.custom_hash.TObjectIntCustomHashMap; 5 | import gnu.trove.strategy.HashingStrategy; 6 | import junit.framework.TestCase; 7 | 8 | import java.io.ByteArrayInputStream; 9 | import java.io.ByteArrayOutputStream; 10 | import java.io.ObjectInputStream; 11 | import java.io.ObjectOutputStream; 12 | import java.util.Set; 13 | 14 | 15 | /** 16 | * 17 | */ 18 | public class TObjectPrimitiveCustomHashMapTest extends TestCase { 19 | // Example from Trove overview doc 20 | public void testArray() { 21 | char[] foo = new char[] { 'a', 'b', 'c' }; 22 | char[] bar = new char[] { 'a', 'b', 'c' }; 23 | 24 | assertFalse( foo.hashCode() == bar.hashCode() ); 25 | //noinspection ArrayEquals 26 | assertFalse( foo.equals( bar ) ); 27 | 28 | HashingStrategy strategy = new ArrayHashingStrategy(); 29 | assertTrue( strategy.computeHashCode( foo ) == 30 | strategy.computeHashCode( bar ) ); 31 | assertTrue( strategy.equals( foo, bar ) ); 32 | 33 | TObjectIntMap map = new TObjectIntCustomHashMap( strategy ); 34 | map.put( foo, 12 ); 35 | assertTrue( map.containsKey( foo ) ); 36 | assertTrue( map.containsKey( bar ) ); 37 | assertEquals( 12, map.get( foo ) ); 38 | assertEquals( 12, map.get( bar ) ); 39 | 40 | Set keys = map.keySet(); 41 | assertTrue( keys.contains( foo ) ); 42 | assertTrue( keys.contains( bar ) ); 43 | } 44 | 45 | 46 | public void testSerialization() throws Exception { 47 | char[] foo = new char[] { 'a', 'b', 'c' }; 48 | char[] bar = new char[] { 'a', 'b', 'c' }; 49 | 50 | HashingStrategy strategy = new ArrayHashingStrategy(); 51 | TObjectIntMap map = new TObjectIntCustomHashMap( strategy ); 52 | 53 | map.put( foo, 33 ); 54 | 55 | // Make sure it still works after being serialized 56 | ObjectOutputStream oout = null; 57 | ByteArrayOutputStream bout = null; 58 | ObjectInputStream oin = null; 59 | ByteArrayInputStream bin = null; 60 | try { 61 | bout = new ByteArrayOutputStream(); 62 | oout = new ObjectOutputStream( bout ); 63 | 64 | oout.writeObject( map ); 65 | 66 | bin = new ByteArrayInputStream( bout.toByteArray() ); 67 | oin = new ObjectInputStream( bin ); 68 | 69 | map = ( TObjectIntMap ) oin.readObject(); 70 | } 71 | finally { 72 | if ( oin != null ) oin.close(); 73 | if ( bin != null ) bin.close(); 74 | if ( oout != null ) oout.close(); 75 | if ( bout != null ) bout.close(); 76 | } 77 | 78 | assertTrue( map.containsKey( foo ) ); 79 | assertTrue( map.containsKey( bar ) ); 80 | assertEquals( 33, map.get( foo ) ); 81 | assertEquals( 33, map.get( bar ) ); 82 | 83 | Set keys = map.keySet(); 84 | assertTrue( keys.contains( foo ) ); 85 | assertTrue( keys.contains( bar ) ); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/test/java/gnu/trove/set/hash/TCustomHashSetTest.java: -------------------------------------------------------------------------------- 1 | package gnu.trove.set.hash; 2 | 3 | import gnu.trove.strategy.HashingStrategy; 4 | import gnu.trove.map.hash.ArrayHashingStrategy; 5 | import junit.framework.TestCase; 6 | 7 | import java.io.ByteArrayInputStream; 8 | import java.io.ByteArrayOutputStream; 9 | import java.io.ObjectInputStream; 10 | import java.io.ObjectOutputStream; 11 | import java.util.Set; 12 | 13 | 14 | /** 15 | * 16 | */ 17 | public class TCustomHashSetTest extends TestCase { 18 | public void testArray() { 19 | char[] foo = new char[] { 'a', 'b', 'c' }; 20 | char[] bar = new char[] { 'a', 'b', 'c' }; 21 | 22 | assertFalse( foo.hashCode() == bar.hashCode() ); 23 | //noinspection ArrayEquals 24 | assertFalse( foo.equals( bar ) ); 25 | 26 | HashingStrategy strategy = new ArrayHashingStrategy(); 27 | assertTrue( strategy.computeHashCode( foo ) == 28 | strategy.computeHashCode( bar ) ); 29 | assertTrue( strategy.equals( foo, bar ) ); 30 | 31 | Set set = new TCustomHashSet( strategy ); 32 | set.add( foo ); 33 | assertTrue( set.contains( foo ) ); 34 | assertTrue( set.contains( bar ) ); 35 | 36 | set.remove( bar ); 37 | 38 | assertTrue( set.isEmpty() ); 39 | } 40 | 41 | 42 | public void testSerialization() throws Exception { 43 | char[] foo = new char[] { 'a', 'b', 'c' }; 44 | char[] bar = new char[] { 'a', 'b', 'c' }; 45 | 46 | HashingStrategy strategy = new ArrayHashingStrategy(); 47 | Set set = new TCustomHashSet( strategy ); 48 | 49 | set.add( foo ); 50 | 51 | // Make sure it still works after being serialized 52 | ObjectOutputStream oout = null; 53 | ByteArrayOutputStream bout = null; 54 | ObjectInputStream oin = null; 55 | ByteArrayInputStream bin = null; 56 | try { 57 | bout = new ByteArrayOutputStream(); 58 | oout = new ObjectOutputStream( bout ); 59 | 60 | oout.writeObject( set ); 61 | 62 | bin = new ByteArrayInputStream( bout.toByteArray() ); 63 | oin = new ObjectInputStream( bin ); 64 | 65 | set = ( Set ) oin.readObject(); 66 | } 67 | finally { 68 | if ( oin != null ) oin.close(); 69 | if ( bin != null ) bin.close(); 70 | if ( oout != null ) oout.close(); 71 | if ( bout != null ) bout.close(); 72 | } 73 | 74 | assertTrue( set.contains( foo ) ); 75 | assertTrue( set.contains( bar ) ); 76 | 77 | set.remove( bar ); 78 | 79 | assertTrue( set.isEmpty() ); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/test/java/gnu/trove/strategy/IdentityHashingStrategyTest.java: -------------------------------------------------------------------------------- 1 | package gnu.trove.strategy; 2 | 3 | import gnu.trove.map.hash.TCustomHashMap; 4 | import junit.framework.TestCase; 5 | 6 | import java.util.Map; 7 | 8 | 9 | /** 10 | * 11 | */ 12 | public class IdentityHashingStrategyTest extends TestCase { 13 | public void testInMap() { 14 | Map map = 15 | new TCustomHashMap( new IdentityHashingStrategy() ); 16 | 17 | Integer first = new Integer( 0 ); 18 | Integer second = new Integer( 0 ); 19 | 20 | map.put( first, "first" ); 21 | 22 | assertEquals( 1, map.size() ); 23 | assertTrue( map.containsKey( first )); 24 | assertFalse( map.containsKey( second ) ); 25 | assertEquals( "first", map.get( first ) ); 26 | 27 | map.put( second, "second" ); 28 | 29 | assertEquals( 2, map.size() ); 30 | assertEquals( "first", map.get( first ) ); 31 | assertEquals( "second", map.get( second ) ); 32 | 33 | map.remove( first ); 34 | 35 | assertEquals( 1, map.size() ); 36 | assertFalse( map.containsKey( first ) ); 37 | assertTrue( map.containsKey( second ) ); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /templates/gnu/trove/TDecorators.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2008, Robert D. Eden All Rights Reserved. 3 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 4 | // 5 | // This library is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU Lesser General Public 7 | // License as published by the Free Software Foundation; either 8 | // version 2.1 of the License, or (at your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public 16 | // License along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | /////////////////////////////////////////////////////////////////////////////// 19 | 20 | 21 | package gnu.trove; 22 | 23 | 24 | import java.util.*; 25 | 26 | import gnu.trove.list.*; 27 | import gnu.trove.map.*; 28 | import gnu.trove.set.*; 29 | import gnu.trove.decorator.*; 30 | 31 | 32 | 33 | /** 34 | * This is a static utility class that provides functions for simplifying creation of 35 | * decorators. 36 | * 37 | * @author Robert D. Eden 38 | * @author Jeff Randall 39 | * @since Trove 2.1 40 | */ 41 | public class TDecorators { 42 | // Hide the constructor 43 | private TDecorators() {} 44 | 45 | 46 | #REPLICATED1# 47 | 48 | 49 | #REPLICATED2# 50 | 51 | 52 | #REPLICATED3# 53 | 54 | 55 | #REPLICATED4# 56 | 57 | 58 | #REPLICATED5# 59 | } 60 | ====START_REPLICATED_CONTENT #1==== 61 | /** 62 | * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} 63 | * interface. 64 | * 65 | * @param map the T#K##V#ObjectMap to be wrapped 66 | * @return the wrapped map. 67 | */ 68 | public static Map<#KT#,#VT#> wrap( T#K##V#Map map ) { 69 | return new T#K##V#MapDecorator( map ); 70 | } 71 | =====END_REPLICATED_CONTENT #1===== 72 | ====START_REPLICATED_CONTENT #2==== 73 | /** 74 | * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} 75 | * interface. 76 | * 77 | * @param map the TObject#E#Map to be wrapped 78 | * @return the wrapped map. 79 | */ 80 | public static Map wrap( TObject#E#Map map ) { 81 | return new TObject#E#MapDecorator( map ); 82 | } 83 | =====END_REPLICATED_CONTENT #2===== 84 | ====START_REPLICATED_CONTENT #3==== 85 | /** 86 | * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} 87 | * interface. 88 | * 89 | * @param map the T#E#ObjectMap to be wrapped 90 | * @return the wrapped map. 91 | */ 92 | public static Map<#ET#,T> wrap( T#E#ObjectMap map ) { 93 | return new T#E#ObjectMapDecorator( map ); 94 | } 95 | =====END_REPLICATED_CONTENT #3===== 96 | ====START_REPLICATED_CONTENT #4==== 97 | /** 98 | * Wrap the given set in a decorator that uses the standard {@link java.util.Set Set} 99 | * interface. 100 | * 101 | * @param set the T#E#Set to be wrapped 102 | * @return the wrapped set. 103 | */ 104 | public static Set<#ET#> wrap( T#E#Set set ) { 105 | return new T#E#SetDecorator( set ); 106 | } 107 | =====END_REPLICATED_CONTENT #4===== 108 | ====START_REPLICATED_CONTENT #5==== 109 | /** 110 | * Wrap the given list in a decorator that uses the standard {@link java.util.List List} 111 | * interface. 112 | * 113 | * @param list the T#E#List to be wrapped 114 | * @return the wrapped list. 115 | */ 116 | public static List<#ET#> wrap( T#E#List list ) { 117 | return new T#E#ListDecorator( list ); 118 | } 119 | =====END_REPLICATED_CONTENT #5===== 120 | -------------------------------------------------------------------------------- /templates/gnu/trove/array/_E_OffheapArray.template: -------------------------------------------------------------------------------- 1 | package gnu.trove.array; 2 | 3 | import java.util.Arrays; 4 | 5 | ////////////////////////////////////////////////// 6 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 7 | ////////////////////////////////////////////////// 8 | 9 | /** 10 | * Direct memory allocated array. 11 | *

12 | * Uses {@link sun.misc.Unsafe} directly to avoid byte 13 | * swaps due to endian mis-matches that can result when using 14 | * {@link ByteBuffer.allocateDirect()} 15 | */ 16 | public class T#E#OffheapArray extends AbstractOffheapArray { 17 | private static final int SHIFT = 31 - Integer.numberOfLeadingZeros(#EBYTES#); 18 | private static final long ARRAY_OFFSET = UNSAFE.arrayBaseOffset(#e#[].class); 19 | private static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(UNSAFE.arrayIndexScale(#e#[].class)); 20 | private static final long UNSAFE_COPY_THRESHOLD = 1024L * 1024L; 21 | 22 | public T#E#OffheapArray(long capacity) { 23 | super(capacity << SHIFT); 24 | } 25 | 26 | @Override 27 | public void resize(long newCapacity) { 28 | super.resize(newCapacity << SHIFT); 29 | } 30 | 31 | public void put(long index, #e# value) { 32 | check(index); 33 | UNSAFE.put#E#(address + (index << SHIFT), value); 34 | } 35 | 36 | public #e# get(long index) { 37 | check(index); 38 | return UNSAFE.get#E#(address + (index << SHIFT)); 39 | } 40 | 41 | public void toArray(long srcIndex, #e#[] dst, int dstIndex, int length) { 42 | check(srcIndex, dstIndex, dst.length, length); 43 | long srcAddress = address + (srcIndex << SHIFT); 44 | long dstOffset = ARRAY_OFFSET + (((long) dstIndex) << ARRAY_SHIFT); 45 | long longLength = ((long) length) << SHIFT; 46 | while (longLength > 0) { 47 | long size = (length > UNSAFE_COPY_THRESHOLD) ? UNSAFE_COPY_THRESHOLD : longLength; 48 | UNSAFE.copyMemory(null, srcAddress, dst, dstOffset, size); 49 | longLength -= size; 50 | srcAddress += size; 51 | dstOffset += size; 52 | } 53 | } 54 | 55 | public void fromArray(#e#[] src, int srcIndex, long dstIndex, int length) { 56 | check(dstIndex, srcIndex, src.length, length); 57 | long dstAddress = address + (dstIndex << SHIFT); 58 | long srcOffset = ARRAY_OFFSET + (((long) srcIndex) << ARRAY_SHIFT); 59 | long longLength = ((long) length) << SHIFT; 60 | while (longLength > 0) { 61 | long size = (length > UNSAFE_COPY_THRESHOLD) ? UNSAFE_COPY_THRESHOLD : longLength; 62 | UNSAFE.copyMemory(src, srcOffset, null, dstAddress, size); 63 | longLength -= size; 64 | dstAddress += size; 65 | srcOffset += size; 66 | } 67 | } 68 | 69 | @Override 70 | public long capacity() { 71 | return capacity >> SHIFT; 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | StringBuilder s = new StringBuilder("["); 77 | for (long i = 0; i < capacity(); i++) { 78 | if (i > 0) { 79 | s.append(", "); 80 | } 81 | s.append(UNSAFE.get#E#(address + (i << SHIFT))); 82 | } 83 | s.append("]"); 84 | return s.toString(); 85 | } 86 | 87 | // Simple runtime checks to help catch any "surprising" changes in the Unsafe api. 88 | static { 89 | T#E#OffheapArray array = new T#E#OffheapArray(10); 90 | assert(array.capacity() == 10); 91 | array.put(3, (#e#) -45); 92 | array.put(5, (#e#) 121); 93 | staticAssert(array.get(1) == 0); 94 | staticAssert(array.get(2) == 0); 95 | staticAssert(array.get(3) == -45); 96 | staticAssert(array.get(4) == 0); 97 | staticAssert(array.get(5) == 121); 98 | staticAssert(array.get(6) == 0); 99 | staticAssert(array.get(7) == 0); 100 | staticAssert(array.get(8) == 0); 101 | array.resize(5); 102 | staticAssert(array.capacity() == 5); 103 | staticAssert(array.get(1) == 0); 104 | staticAssert(array.get(2) == 0); 105 | staticAssert(array.get(3) == -45); 106 | staticAssert(array.get(4) == 0); 107 | array.resize(20); 108 | staticAssert(array.capacity() == 20); 109 | staticAssert(array.get(1) == 0); 110 | staticAssert(array.get(2) == 0); 111 | staticAssert(array.get(3) == -45); 112 | staticAssert(array.get(4) == 0); 113 | array.fromArray(new #e#[] {(#e#) -3, 0, 4, 5}, 0, 7, 4); 114 | staticAssert(array.get(6) == 0); 115 | staticAssert(array.get(7) == -3); 116 | staticAssert(array.get(8) == 0); 117 | staticAssert(array.get(9) == 4); 118 | staticAssert(array.get(10) == 5); 119 | staticAssert(array.get(11) == 0); 120 | #e#[] dst = new #e#[5]; 121 | array.toArray(3, dst, 0, 5); 122 | staticAssert(Arrays.equals(dst, new #e#[] {(#e#) -45, 0, 0, 0, (#e#) -3})); 123 | array.clear(); 124 | array.toArray(3, dst, 0, 5); 125 | staticAssert(Arrays.equals(dst, new #e#[] {0, 0, 0, 0, 0})); 126 | array.free(); 127 | } 128 | 129 | private static void staticAssert(boolean condition) { 130 | if (!condition) { 131 | throw new Error("Failed initialization checks"); 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /templates/gnu/trove/decorator/_E_ListDecorator.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2009, Robert D. Eden All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.decorator; 20 | 21 | import gnu.trove.list.T#E#List; 22 | 23 | import java.io.Externalizable; 24 | import java.io.IOException; 25 | import java.io.ObjectInput; 26 | import java.io.ObjectOutput; 27 | import java.util.AbstractList; 28 | import java.util.List; 29 | 30 | 31 | ////////////////////////////////////////////////// 32 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 33 | ////////////////////////////////////////////////// 34 | 35 | 36 | /** 37 | * Wrapper class to make a T#E#List conform to the java.util.List API. 38 | * This class simply decorates an underlying T#E#List and translates the Object-based 39 | * APIs into their Trove primitive analogs. 40 | *

41 | * Note that wrapping and unwrapping primitive values is extremely inefficient. If 42 | * possible, users of this class should override the appropriate methods in this class 43 | * and use a table of canonical values. 44 | *

45 | * 46 | * @author Robert D. Eden 47 | */ 48 | public class T#E#ListDecorator extends AbstractList<#ET#> 49 | implements List<#ET#>, Externalizable, Cloneable { 50 | 51 | static final long serialVersionUID = 1L; 52 | 53 | /** the wrapped primitive list */ 54 | protected T#E#List list; 55 | 56 | 57 | /** 58 | * FOR EXTERNALIZATION ONLY!! 59 | */ 60 | public T#E#ListDecorator() {} 61 | 62 | 63 | /** 64 | * Creates a wrapper that decorates the specified primitive map. 65 | * 66 | * @param list the T#E#List to wrap. 67 | */ 68 | public T#E#ListDecorator( T#E#List list ) { 69 | super(); 70 | this.list = list; 71 | } 72 | 73 | 74 | /** 75 | * Returns a reference to the list wrapped by this decorator. 76 | * 77 | * @return the wrapped T#E#List instance. 78 | */ 79 | public T#E#List getList() { 80 | return list; 81 | } 82 | 83 | 84 | @Override 85 | public int size() { 86 | return list.size(); 87 | } 88 | 89 | 90 | @Override 91 | public #ET# get( int index ) { 92 | #e# value = list.get( index ); 93 | if ( value == list.getNoEntryValue() ) return null; 94 | else return #ET#.valueOf( value ); 95 | } 96 | 97 | 98 | @Override 99 | public #ET# set( int index, #ET# value ) { 100 | #e# previous_value = list.set( index, value ); 101 | if ( previous_value == list.getNoEntryValue() ) return null; 102 | else return #ET#.valueOf( previous_value ); 103 | } 104 | 105 | 106 | @Override 107 | public void add( int index, #ET# value ) { 108 | list.insert( index, value.#e#Value() ); 109 | } 110 | 111 | 112 | @Override 113 | public #ET# remove( int index ) { 114 | #e# previous_value = list.removeAt( index ); 115 | if ( previous_value == list.getNoEntryValue() ) return null; 116 | else return #ET#.valueOf( previous_value ); 117 | } 118 | 119 | 120 | // Implements Externalizable 121 | @Override 122 | public void readExternal( ObjectInput in ) 123 | throws IOException, ClassNotFoundException { 124 | 125 | // VERSION 126 | in.readByte(); 127 | 128 | // LIST 129 | list = ( T#E#List ) in.readObject(); 130 | } 131 | 132 | 133 | // Implements Externalizable 134 | @Override 135 | public void writeExternal( ObjectOutput out ) throws IOException { 136 | // VERSION 137 | out.writeByte(0); 138 | 139 | // LIST 140 | out.writeObject( list ); 141 | } 142 | 143 | } 144 | -------------------------------------------------------------------------------- /templates/gnu/trove/function/_E_Function.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.function; 20 | 21 | ////////////////////////////////////////////////// 22 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 23 | ////////////////////////////////////////////////// 24 | 25 | 26 | /** 27 | * Interface for functions that accept and return one #e# primitive. 28 | */ 29 | public interface T#E#Function { 30 | /** 31 | * Execute this function with value 32 | * 33 | * @param value a #e# input 34 | * @return a #e# result 35 | */ 36 | public #e# execute( #e# value ); 37 | } 38 | -------------------------------------------------------------------------------- /templates/gnu/trove/impl/sync/SynchronizedRandomAccess_E_List.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2008, Robert D. Eden All Rights Reserved. 3 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 4 | // 5 | // This library is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU Lesser General Public 7 | // License as published by the Free Software Foundation; either 8 | // version 2.1 of the License, or (at your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public 16 | // License along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | /////////////////////////////////////////////////////////////////////////////// 19 | 20 | package gnu.trove.impl.sync; 21 | 22 | 23 | ////////////////////////////////////////////////// 24 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 25 | ////////////////////////////////////////////////// 26 | 27 | //////////////////////////////////////////////////////////// 28 | // THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // 29 | // Access to these methods should be through TCollections // 30 | //////////////////////////////////////////////////////////// 31 | 32 | 33 | import gnu.trove.iterator.*; 34 | import gnu.trove.procedure.*; 35 | import gnu.trove.set.*; 36 | import gnu.trove.list.*; 37 | import gnu.trove.function.*; 38 | import gnu.trove.map.*; 39 | import gnu.trove.*; 40 | 41 | import java.util.Collection; 42 | import java.util.Iterator; 43 | import java.util.Set; 44 | import java.util.Map; 45 | import java.util.RandomAccess; 46 | import java.util.Random; 47 | import java.io.Serializable; 48 | import java.io.ObjectOutputStream; 49 | import java.io.IOException; 50 | 51 | 52 | public class TSynchronizedRandomAccess#E#List extends TSynchronized#E#List 53 | implements RandomAccess { 54 | 55 | static final long serialVersionUID = 1530674583602358482L; 56 | 57 | public TSynchronizedRandomAccess#E#List( T#E#List list ) { 58 | super( list ); 59 | } 60 | 61 | public TSynchronizedRandomAccess#E#List( T#E#List list, Object mutex ) { 62 | super( list, mutex ); 63 | } 64 | 65 | @Override 66 | public T#E#List subList( int fromIndex, int toIndex ) { 67 | synchronized( mutex ) { 68 | return new TSynchronizedRandomAccess#E#List( 69 | list.subList( fromIndex, toIndex ), mutex ); 70 | } 71 | } 72 | 73 | /** 74 | * Allows instances to be deserialized in pre-1.4 JREs (which do 75 | * not have SynchronizedRandomAccessList). SynchronizedList has 76 | * a readResolve method that inverts this transformation upon 77 | * deserialization. 78 | */ 79 | private Object writeReplace() { 80 | return new TSynchronized#E#List( list ); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /templates/gnu/trove/impl/sync/Synchronized_E_Collection.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2008, Robert D. Eden All Rights Reserved. 3 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 4 | // 5 | // This library is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU Lesser General Public 7 | // License as published by the Free Software Foundation; either 8 | // version 2.1 of the License, or (at your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public 16 | // License along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | /////////////////////////////////////////////////////////////////////////////// 19 | 20 | package gnu.trove.impl.sync; 21 | 22 | 23 | ////////////////////////////////////////////////// 24 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 25 | ////////////////////////////////////////////////// 26 | 27 | //////////////////////////////////////////////////////////// 28 | // THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // 29 | // Access to these methods should be through TCollections // 30 | //////////////////////////////////////////////////////////// 31 | 32 | 33 | import gnu.trove.iterator.*; 34 | import gnu.trove.procedure.*; 35 | import gnu.trove.set.*; 36 | import gnu.trove.list.*; 37 | import gnu.trove.function.*; 38 | import gnu.trove.map.*; 39 | import gnu.trove.*; 40 | 41 | import java.util.Collection; 42 | import java.util.Iterator; 43 | import java.util.Set; 44 | import java.util.Map; 45 | import java.util.RandomAccess; 46 | import java.util.Random; 47 | import java.io.Serializable; 48 | import java.io.ObjectOutputStream; 49 | import java.io.IOException; 50 | 51 | 52 | public class TSynchronized#E#Collection implements T#E#Collection, Serializable { 53 | private static final long serialVersionUID = 3053995032091335093L; 54 | 55 | final T#E#Collection c; // Backing Collection 56 | final Object mutex; // Object on which to synchronize 57 | 58 | public TSynchronized#E#Collection( T#E#Collection c ) { 59 | if ( c == null ) 60 | throw new NullPointerException(); 61 | this.c = c; 62 | mutex = this; 63 | } 64 | public TSynchronized#E#Collection( T#E#Collection c, Object mutex ) { 65 | this.c = c; 66 | this.mutex = mutex; 67 | } 68 | 69 | @Override 70 | public int size() { 71 | synchronized( mutex ) { return c.size(); } 72 | } 73 | @Override 74 | public boolean isEmpty() { 75 | synchronized( mutex ) { return c.isEmpty(); } 76 | } 77 | @Override 78 | public boolean contains( #e# o ) { 79 | synchronized( mutex ) { return c.contains( o ); } 80 | } 81 | @Override 82 | public #e#[] toArray() { 83 | synchronized( mutex ) { return c.toArray(); } 84 | } 85 | @Override 86 | public #e#[] toArray( #e#[] a ) { 87 | synchronized( mutex ) { return c.toArray( a ); } 88 | } 89 | 90 | @Override 91 | public T#E#Iterator iterator() { 92 | return c.iterator(); // Must be manually synched by user! 93 | } 94 | 95 | @Override 96 | public boolean add( #e# e ) { 97 | synchronized (mutex ) { return c.add( e ); } 98 | } 99 | @Override 100 | public boolean remove( #e# o ) { 101 | synchronized( mutex ) { return c.remove( o ); } 102 | } 103 | 104 | @Override 105 | public boolean containsAll( Collection coll ) { 106 | synchronized( mutex ) { return c.containsAll( coll );} 107 | } 108 | @Override 109 | public boolean containsAll( T#E#Collection coll ) { 110 | synchronized( mutex ) { return c.containsAll( coll );} 111 | } 112 | @Override 113 | public boolean containsAll( #e#[] array ) { 114 | synchronized( mutex ) { return c.containsAll( array );} 115 | } 116 | 117 | @Override 118 | public boolean addAll( Collection coll ) { 119 | synchronized( mutex ) { return c.addAll( coll ); } 120 | } 121 | @Override 122 | public boolean addAll( T#E#Collection coll ) { 123 | synchronized( mutex ) { return c.addAll( coll ); } 124 | } 125 | @Override 126 | public boolean addAll( #e#[] array ) { 127 | synchronized( mutex ) { return c.addAll( array ); } 128 | } 129 | 130 | @Override 131 | public boolean removeAll( Collection coll ) { 132 | synchronized( mutex ) { return c.removeAll( coll ); } 133 | } 134 | @Override 135 | public boolean removeAll( T#E#Collection coll ) { 136 | synchronized( mutex ) { return c.removeAll( coll ); } 137 | } 138 | @Override 139 | public boolean removeAll( #e#[] array ) { 140 | synchronized( mutex ) { return c.removeAll( array ); } 141 | } 142 | 143 | @Override 144 | public boolean retainAll( Collection coll ) { 145 | synchronized( mutex ) { return c.retainAll( coll ); } 146 | } 147 | @Override 148 | public boolean retainAll( T#E#Collection coll ) { 149 | synchronized( mutex ) { return c.retainAll( coll ); } 150 | } 151 | @Override 152 | public boolean retainAll( #e#[] array ) { 153 | synchronized( mutex ) { return c.retainAll( array ); } 154 | } 155 | 156 | @Override 157 | public #e# getNoEntryValue() { return c.getNoEntryValue(); } 158 | @Override 159 | public boolean forEach( T#E#Procedure procedure ) { 160 | synchronized( mutex ) { return c.forEach( procedure ); } 161 | } 162 | 163 | @Override 164 | public void clear() { 165 | synchronized( mutex ) { c.clear(); } 166 | } 167 | @Override 168 | public String toString() { 169 | synchronized( mutex ) { return c.toString(); } 170 | } 171 | private void writeObject( ObjectOutputStream s ) throws IOException { 172 | synchronized( mutex ) { s.defaultWriteObject(); } 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /templates/gnu/trove/impl/sync/Synchronized_E_ObjectMap.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2008, Robert D. Eden All Rights Reserved. 3 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 4 | // 5 | // This library is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU Lesser General Public 7 | // License as published by the Free Software Foundation; either 8 | // version 2.1 of the License, or (at your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public 16 | // License along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | /////////////////////////////////////////////////////////////////////////////// 19 | 20 | package gnu.trove.impl.sync; 21 | 22 | 23 | ////////////////////////////////////////////////// 24 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 25 | ////////////////////////////////////////////////// 26 | 27 | //////////////////////////////////////////////////////////// 28 | // THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // 29 | // Access to these methods should be through TCollections // 30 | //////////////////////////////////////////////////////////// 31 | 32 | 33 | import gnu.trove.iterator.*; 34 | import gnu.trove.procedure.*; 35 | import gnu.trove.set.*; 36 | import gnu.trove.list.*; 37 | import gnu.trove.function.*; 38 | import gnu.trove.map.*; 39 | import gnu.trove.*; 40 | 41 | import java.util.Collection; 42 | import java.util.Iterator; 43 | import java.util.Set; 44 | import java.util.Map; 45 | import java.util.RandomAccess; 46 | import java.util.Random; 47 | import java.io.Serializable; 48 | import java.io.ObjectOutputStream; 49 | import java.io.IOException; 50 | 51 | public class TSynchronized#E#ObjectMap 52 | implements T#E#ObjectMap, Serializable { 53 | // use serialVersionUID from JDK 1.2.2 for interoperability 54 | private static final long serialVersionUID = 1978198479659022715L; 55 | 56 | private final T#E#ObjectMap m; // Backing Map 57 | final Object mutex; // Object on which to synchronize 58 | 59 | public TSynchronized#E#ObjectMap( T#E#ObjectMap m ) { 60 | if ( m == null ) 61 | throw new NullPointerException(); 62 | this.m = m; 63 | mutex = this; 64 | } 65 | 66 | public TSynchronized#E#ObjectMap( T#E#ObjectMap m, Object mutex ) { 67 | this.m = m; 68 | this.mutex = mutex; 69 | } 70 | 71 | @Override 72 | public int size() { 73 | synchronized( mutex ) { return m.size(); } 74 | } 75 | @Override 76 | public boolean isEmpty(){ 77 | synchronized( mutex ) { return m.isEmpty(); } 78 | } 79 | @Override 80 | public boolean containsKey( #e# key ) { 81 | synchronized( mutex ) { return m.containsKey( key ); } 82 | } 83 | @Override 84 | public boolean containsValue( Object value ){ 85 | synchronized( mutex ) { return m.containsValue( value ); } 86 | } 87 | @Override 88 | public V get( #e# key ) { 89 | synchronized( mutex ) { return m.get( key ); } 90 | } 91 | 92 | @Override 93 | public V put( #e# key, V value ) { 94 | synchronized( mutex ) { return m.put( key, value ); } 95 | } 96 | @Override 97 | public V remove( #e# key ) { 98 | synchronized( mutex ) { return m.remove( key ); } 99 | } 100 | @Override 101 | public void putAll( Map map ) { 102 | synchronized( mutex ) { m.putAll( map ); } 103 | } 104 | @Override 105 | public void putAll( T#E#ObjectMap map ) { 106 | synchronized( mutex ) { m.putAll( map ); } 107 | } 108 | @Override 109 | public void clear() { 110 | synchronized( mutex ) { m.clear(); } 111 | } 112 | 113 | private transient T#E#Set keySet = null; 114 | private transient Collection values = null; 115 | 116 | @Override 117 | public T#E#Set keySet() { 118 | synchronized( mutex ) { 119 | if ( keySet == null ) 120 | keySet = new TSynchronized#E#Set( m.keySet(), mutex ); 121 | return keySet; 122 | } 123 | } 124 | @Override 125 | public #e#[] keys() { 126 | synchronized( mutex ) { return m.keys(); } 127 | } 128 | @Override 129 | public #e#[] keys( #e#[] array ) { 130 | synchronized( mutex ) { return m.keys( array ); } 131 | } 132 | 133 | @Override 134 | public Collection valueCollection() { 135 | synchronized( mutex ) { 136 | if ( values == null ) { 137 | values = new SynchronizedCollection( m.valueCollection(), mutex ); 138 | } 139 | return values; 140 | } 141 | } 142 | @Override 143 | public Object[] values() { 144 | synchronized( mutex ) { return m.values(); } 145 | } 146 | @Override 147 | public V[] values( V[] array ) { 148 | synchronized( mutex ) { return m.values( array ); } 149 | } 150 | 151 | @Override 152 | public T#E#ObjectIterator iterator() { 153 | return m.iterator(); // Must be manually synched by user! 154 | } 155 | 156 | // unchanging over the life of the map, no need to lock 157 | @Override 158 | public #e# getNoEntryKey() { return m.getNoEntryKey(); } 159 | 160 | @Override 161 | public V putIfAbsent( #e# key, V value ) { 162 | synchronized( mutex ) { return m.putIfAbsent( key, value ); } 163 | } 164 | @Override 165 | public boolean forEachKey( T#E#Procedure procedure ) { 166 | synchronized( mutex ) { return m.forEachKey( procedure ); } 167 | } 168 | @Override 169 | public boolean forEachValue( TObjectProcedure procedure ) { 170 | synchronized( mutex ) { return m.forEachValue( procedure ); } 171 | } 172 | @Override 173 | public boolean forEachEntry( T#E#ObjectProcedure procedure ) { 174 | synchronized( mutex ) { return m.forEachEntry( procedure ); } 175 | } 176 | @Override 177 | public void transformValues( TObjectFunction function ) { 178 | synchronized( mutex ) { m.transformValues( function ); } 179 | } 180 | @Override 181 | public boolean retainEntries( T#E#ObjectProcedure procedure ) { 182 | synchronized( mutex ) { return m.retainEntries( procedure ); } 183 | } 184 | 185 | @Override 186 | public boolean equals( Object o ) { 187 | synchronized( mutex ) { return m.equals( o ); } 188 | } 189 | @Override 190 | public int hashCode() { 191 | synchronized( mutex ) { return m.hashCode(); } 192 | } 193 | @Override 194 | public String toString() { 195 | synchronized( mutex ) { return m.toString(); } 196 | } 197 | private void writeObject( ObjectOutputStream s ) throws IOException { 198 | synchronized( mutex ) { s.defaultWriteObject(); } 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /templates/gnu/trove/impl/sync/Synchronized_E_Set.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2008, Robert D. Eden All Rights Reserved. 3 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 4 | // 5 | // This library is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU Lesser General Public 7 | // License as published by the Free Software Foundation; either 8 | // version 2.1 of the License, or (at your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public 16 | // License along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | /////////////////////////////////////////////////////////////////////////////// 19 | 20 | package gnu.trove.impl.sync; 21 | 22 | 23 | ////////////////////////////////////////////////// 24 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 25 | ////////////////////////////////////////////////// 26 | 27 | //////////////////////////////////////////////////////////// 28 | // THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // 29 | // Access to these methods should be through TCollections // 30 | //////////////////////////////////////////////////////////// 31 | 32 | 33 | import gnu.trove.iterator.*; 34 | import gnu.trove.procedure.*; 35 | import gnu.trove.set.*; 36 | import gnu.trove.list.*; 37 | import gnu.trove.function.*; 38 | import gnu.trove.map.*; 39 | import gnu.trove.*; 40 | 41 | import java.util.Collection; 42 | import java.util.Iterator; 43 | import java.util.Set; 44 | import java.util.Map; 45 | import java.util.RandomAccess; 46 | import java.util.Random; 47 | import java.io.Serializable; 48 | import java.io.ObjectOutputStream; 49 | import java.io.IOException; 50 | 51 | 52 | public class TSynchronized#E#Set extends TSynchronized#E#Collection 53 | implements T#E#Set { 54 | 55 | private static final long serialVersionUID = 487447009682186044L; 56 | 57 | public TSynchronized#E#Set( T#E#Set s ) { 58 | super( s ); 59 | } 60 | public TSynchronized#E#Set( T#E#Set s, Object mutex ) { 61 | super( s, mutex ); 62 | } 63 | 64 | @Override 65 | public boolean equals( Object o ) { 66 | synchronized( mutex ) { return c.equals( o ); } 67 | } 68 | @Override 69 | public int hashCode() { 70 | synchronized( mutex ) { return c.hashCode(); } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /templates/gnu/trove/impl/unmodifiable/UnmodifiableObject_E_Map.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2008, Robert D. Eden All Rights Reserved. 3 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 4 | // 5 | // This library is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU Lesser General Public 7 | // License as published by the Free Software Foundation; either 8 | // version 2.1 of the License, or (at your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public 16 | // License along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | /////////////////////////////////////////////////////////////////////////////// 19 | 20 | package gnu.trove.impl.unmodifiable; 21 | 22 | 23 | ////////////////////////////////////////////////// 24 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 25 | ////////////////////////////////////////////////// 26 | 27 | //////////////////////////////////////////////////////////// 28 | // THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // 29 | // Access to these methods should be through TCollections // 30 | //////////////////////////////////////////////////////////// 31 | 32 | 33 | import gnu.trove.iterator.*; 34 | import gnu.trove.procedure.*; 35 | import gnu.trove.set.*; 36 | import gnu.trove.list.*; 37 | import gnu.trove.function.*; 38 | import gnu.trove.map.*; 39 | import gnu.trove.*; 40 | 41 | import java.util.*; 42 | import java.io.Serializable; 43 | import java.io.ObjectOutputStream; 44 | import java.io.IOException; 45 | 46 | 47 | public class TUnmodifiableObject#E#Map implements TObject#E#Map, Serializable { 48 | private static final long serialVersionUID = -1034234728574286014L; 49 | 50 | private final TObject#E#Map m; 51 | 52 | public TUnmodifiableObject#E#Map( TObject#E#Map m ) { 53 | if ( m == null ) 54 | throw new NullPointerException(); 55 | this.m = m; 56 | } 57 | 58 | @Override 59 | public int size() { return m.size(); } 60 | @Override 61 | public boolean isEmpty() { return m.isEmpty(); } 62 | @Override 63 | public boolean containsKey( Object key ){ return m.containsKey( key ); } 64 | @Override 65 | public boolean containsValue( #e# val ) { return m.containsValue( val ); } 66 | @Override 67 | public #e# get( Object key ) { return m.get( key ); } 68 | 69 | @Override 70 | public #e# put( K key, #e# value ) { throw new UnsupportedOperationException(); } 71 | @Override 72 | public #e# remove( Object key ) { throw new UnsupportedOperationException(); } 73 | @Override 74 | public void putAll( TObject#E#Map m ) { throw new UnsupportedOperationException(); } 75 | @Override 76 | public void putAll( Map map ) { throw new UnsupportedOperationException(); } 77 | @Override 78 | public void clear() { throw new UnsupportedOperationException(); } 79 | 80 | private transient Set keySet = null; 81 | private transient T#E#Collection values = null; 82 | 83 | @Override 84 | public Set keySet() { 85 | if ( keySet == null ) 86 | keySet = Collections.unmodifiableSet( m.keySet() ); 87 | return keySet; 88 | } 89 | @Override 90 | public Object[] keys() { return m.keys(); } 91 | @Override 92 | public K[] keys( K[] array ) { return m.keys( array ); } 93 | 94 | @Override 95 | public T#E#Collection valueCollection() { 96 | if ( values == null ) 97 | values = TCollections.unmodifiableCollection( m.valueCollection() ); 98 | return values; 99 | } 100 | @Override 101 | public #e#[] values() { return m.values(); } 102 | @Override 103 | public #e#[] values( #e#[] array ) { return m.values( array ); } 104 | 105 | @Override 106 | public boolean equals(Object o) { return o == this || m.equals(o); } 107 | @Override 108 | public int hashCode() { return m.hashCode(); } 109 | @Override 110 | public String toString() { return m.toString(); } 111 | @Override 112 | public #e# getNoEntryValue() { return m.getNoEntryValue(); } 113 | 114 | @Override 115 | public boolean forEachKey( TObjectProcedure procedure ) { 116 | return m.forEachKey( procedure ); 117 | } 118 | @Override 119 | public boolean forEachValue( T#E#Procedure procedure ) { 120 | return m.forEachValue( procedure ); 121 | } 122 | @Override 123 | public boolean forEachEntry( TObject#E#Procedure procedure ) { 124 | return m.forEachEntry( procedure ); 125 | } 126 | 127 | @Override 128 | public TObject#E#Iterator iterator() { 129 | return new TObject#E#Iterator() { 130 | TObject#E#Iterator iter = m.iterator(); 131 | 132 | @Override 133 | public K key() { return iter.key(); } 134 | @Override 135 | public #e# value() { return iter.value(); } 136 | @Override 137 | public void advance() { iter.advance(); } 138 | @Override 139 | public boolean hasNext() { return iter.hasNext(); } 140 | @Override 141 | public #e# setValue( #e# val ) { throw new UnsupportedOperationException(); } 142 | @Override 143 | public void remove() { throw new UnsupportedOperationException(); } 144 | }; 145 | } 146 | 147 | @Override 148 | public #e# putIfAbsent( K key, #e# value ) { throw new UnsupportedOperationException(); } 149 | @Override 150 | public void transformValues( T#E#Function function ) { throw new UnsupportedOperationException(); } 151 | @Override 152 | public boolean retainEntries( TObject#E#Procedure procedure ) { throw new UnsupportedOperationException(); } 153 | @Override 154 | public boolean increment( K key ) { throw new UnsupportedOperationException(); } 155 | @Override 156 | public boolean adjustValue( K key, #e# amount ) { throw new UnsupportedOperationException(); } 157 | @Override 158 | public #e# adjustOrPutValue( K key, #e# adjust_amount, #e# put_amount ) { throw new UnsupportedOperationException(); } 159 | } 160 | -------------------------------------------------------------------------------- /templates/gnu/trove/impl/unmodifiable/UnmodifiableRandomAccess_E_List.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2008, Robert D. Eden All Rights Reserved. 3 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 4 | // 5 | // This library is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU Lesser General Public 7 | // License as published by the Free Software Foundation; either 8 | // version 2.1 of the License, or (at your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public 16 | // License along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | /////////////////////////////////////////////////////////////////////////////// 19 | 20 | package gnu.trove.impl.unmodifiable; 21 | 22 | 23 | ////////////////////////////////////////////////// 24 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 25 | ////////////////////////////////////////////////// 26 | 27 | //////////////////////////////////////////////////////////// 28 | // THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // 29 | // Access to these methods should be through TCollections // 30 | //////////////////////////////////////////////////////////// 31 | 32 | 33 | import gnu.trove.iterator.*; 34 | import gnu.trove.procedure.*; 35 | import gnu.trove.set.*; 36 | import gnu.trove.list.*; 37 | import gnu.trove.function.*; 38 | import gnu.trove.map.*; 39 | import gnu.trove.*; 40 | 41 | import java.util.Collection; 42 | import java.util.Iterator; 43 | import java.util.Set; 44 | import java.util.Map; 45 | import java.util.RandomAccess; 46 | import java.util.Random; 47 | import java.io.Serializable; 48 | import java.io.ObjectOutputStream; 49 | import java.io.IOException; 50 | 51 | 52 | public class TUnmodifiableRandomAccess#E#List extends TUnmodifiable#E#List 53 | implements RandomAccess { 54 | 55 | private static final long serialVersionUID = -2542308836966382001L; 56 | 57 | public TUnmodifiableRandomAccess#E#List( T#E#List list ) { 58 | super( list ); 59 | } 60 | 61 | @Override 62 | public T#E#List subList( int fromIndex, int toIndex ) { 63 | return new TUnmodifiableRandomAccess#E#List( list.subList( fromIndex, toIndex ) ); 64 | } 65 | 66 | /** 67 | * Allows instances to be deserialized in pre-1.4 JREs (which do 68 | * not have UnmodifiableRandomAccessList). UnmodifiableList has 69 | * a readResolve method that inverts this transformation upon 70 | * deserialization. 71 | */ 72 | private Object writeReplace() { 73 | return new TUnmodifiable#E#List( list ); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /templates/gnu/trove/impl/unmodifiable/Unmodifiable_E_Collection.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2008, Robert D. Eden All Rights Reserved. 3 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 4 | // 5 | // This library is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU Lesser General Public 7 | // License as published by the Free Software Foundation; either 8 | // version 2.1 of the License, or (at your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public 16 | // License along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | /////////////////////////////////////////////////////////////////////////////// 19 | 20 | package gnu.trove.impl.unmodifiable; 21 | 22 | 23 | ////////////////////////////////////////////////// 24 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 25 | ////////////////////////////////////////////////// 26 | 27 | //////////////////////////////////////////////////////////// 28 | // THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // 29 | // Access to these methods should be through TCollections // 30 | //////////////////////////////////////////////////////////// 31 | 32 | 33 | import gnu.trove.iterator.*; 34 | import gnu.trove.procedure.*; 35 | import gnu.trove.set.*; 36 | import gnu.trove.list.*; 37 | import gnu.trove.function.*; 38 | import gnu.trove.map.*; 39 | import gnu.trove.*; 40 | 41 | import java.util.Collection; 42 | import java.util.Iterator; 43 | import java.util.Set; 44 | import java.util.Map; 45 | import java.util.RandomAccess; 46 | import java.util.Random; 47 | import java.io.Serializable; 48 | import java.io.ObjectOutputStream; 49 | import java.io.IOException; 50 | 51 | 52 | public class TUnmodifiable#E#Collection implements T#E#Collection, Serializable { 53 | private static final long serialVersionUID = 1820017752578914078L; 54 | 55 | final T#E#Collection c; 56 | 57 | public TUnmodifiable#E#Collection( T#E#Collection c ) { 58 | if ( c == null ) 59 | throw new NullPointerException(); 60 | this.c = c; 61 | } 62 | 63 | @Override 64 | public int size() { return c.size(); } 65 | @Override 66 | public boolean isEmpty() { return c.isEmpty(); } 67 | @Override 68 | public boolean contains( #e# o ) { return c.contains( o ); } 69 | @Override 70 | public #e#[] toArray() { return c.toArray(); } 71 | @Override 72 | public #e#[] toArray( #e#[] a ) { return c.toArray( a ); } 73 | @Override 74 | public String toString() { return c.toString(); } 75 | @Override 76 | public #e# getNoEntryValue() { return c.getNoEntryValue(); } 77 | @Override 78 | public boolean forEach( T#E#Procedure procedure ) { return c.forEach( procedure ); } 79 | 80 | @Override 81 | public T#E#Iterator iterator() { 82 | return new T#E#Iterator() { 83 | T#E#Iterator i = c.iterator(); 84 | 85 | @Override 86 | public boolean hasNext() { return i.hasNext(); } 87 | @Override 88 | public #e# next() { return i.next(); } 89 | @Override 90 | public void remove() { throw new UnsupportedOperationException(); } 91 | }; 92 | } 93 | 94 | @Override 95 | public boolean add( #e# e ) { throw new UnsupportedOperationException(); } 96 | @Override 97 | public boolean remove( #e# o ) { throw new UnsupportedOperationException(); } 98 | 99 | @Override 100 | public boolean containsAll( Collection coll ) { return c.containsAll( coll ); } 101 | @Override 102 | public boolean containsAll( T#E#Collection coll ) { return c.containsAll( coll ); } 103 | @Override 104 | public boolean containsAll( #e#[] array ) { return c.containsAll( array ); } 105 | 106 | @Override 107 | public boolean addAll( T#E#Collection coll ) { throw new UnsupportedOperationException(); } 108 | @Override 109 | public boolean addAll( Collection coll ) { throw new UnsupportedOperationException(); } 110 | @Override 111 | public boolean addAll( #e#[] array ) { throw new UnsupportedOperationException(); } 112 | 113 | @Override 114 | public boolean removeAll( Collection coll ) { throw new UnsupportedOperationException(); } 115 | @Override 116 | public boolean removeAll( T#E#Collection coll ) { throw new UnsupportedOperationException(); } 117 | @Override 118 | public boolean removeAll( #e#[] array ) { throw new UnsupportedOperationException(); } 119 | 120 | @Override 121 | public boolean retainAll( Collection coll ) { throw new UnsupportedOperationException(); } 122 | @Override 123 | public boolean retainAll( T#E#Collection coll ) { throw new UnsupportedOperationException(); } 124 | @Override 125 | public boolean retainAll( #e#[] array ) { throw new UnsupportedOperationException(); } 126 | 127 | @Override 128 | public void clear() { throw new UnsupportedOperationException(); } 129 | } 130 | -------------------------------------------------------------------------------- /templates/gnu/trove/impl/unmodifiable/Unmodifiable_E_ObjectMap.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2008, Robert D. Eden All Rights Reserved. 3 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 4 | // 5 | // This library is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU Lesser General Public 7 | // License as published by the Free Software Foundation; either 8 | // version 2.1 of the License, or (at your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public 16 | // License along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | /////////////////////////////////////////////////////////////////////////////// 19 | 20 | package gnu.trove.impl.unmodifiable; 21 | 22 | 23 | ////////////////////////////////////////////////// 24 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 25 | ////////////////////////////////////////////////// 26 | 27 | //////////////////////////////////////////////////////////// 28 | // THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // 29 | // Access to these methods should be through TCollections // 30 | //////////////////////////////////////////////////////////// 31 | 32 | 33 | import gnu.trove.iterator.*; 34 | import gnu.trove.procedure.*; 35 | import gnu.trove.set.*; 36 | import gnu.trove.list.*; 37 | import gnu.trove.function.*; 38 | import gnu.trove.map.*; 39 | import gnu.trove.*; 40 | 41 | import java.util.*; 42 | import java.io.Serializable; 43 | import java.io.ObjectOutputStream; 44 | import java.io.IOException; 45 | 46 | 47 | public class TUnmodifiable#E#ObjectMap implements T#E#ObjectMap, Serializable { 48 | private static final long serialVersionUID = -1034234728574286014L; 49 | 50 | private final T#E#ObjectMap m; 51 | 52 | public TUnmodifiable#E#ObjectMap( T#E#ObjectMap m ) { 53 | if ( m == null ) 54 | throw new NullPointerException(); 55 | this.m = m; 56 | } 57 | 58 | @Override 59 | public int size() { return m.size(); } 60 | @Override 61 | public boolean isEmpty() { return m.isEmpty(); } 62 | @Override 63 | public boolean containsKey( #e# key ) { return m.containsKey( key ); } 64 | @Override 65 | public boolean containsValue( Object val ) { return m.containsValue( val ); } 66 | @Override 67 | public V get( #e# key) { return m.get( key ); } 68 | 69 | @Override 70 | public V put( #e# key, V value ) { throw new UnsupportedOperationException(); } 71 | @Override 72 | public V remove( #e# key ) { throw new UnsupportedOperationException(); } 73 | @Override 74 | public void putAll( T#E#ObjectMap m ) { throw new UnsupportedOperationException(); } 75 | @Override 76 | public void putAll( Map map ) { throw new UnsupportedOperationException(); } 77 | @Override 78 | public void clear() { throw new UnsupportedOperationException(); } 79 | 80 | private transient T#E#Set keySet = null; 81 | private transient Collection values = null; 82 | 83 | @Override 84 | public T#E#Set keySet() { 85 | if ( keySet == null ) 86 | keySet = TCollections.unmodifiableSet( m.keySet() ); 87 | return keySet; 88 | } 89 | @Override 90 | public #e#[] keys() { return m.keys(); } 91 | @Override 92 | public #e#[] keys( #e#[] array ) { return m.keys( array ); } 93 | 94 | @Override 95 | public Collection valueCollection() { 96 | if ( values == null ) 97 | values = Collections.unmodifiableCollection( m.valueCollection() ); 98 | return values; 99 | } 100 | @Override 101 | public Object[] values() { return m.values(); } 102 | @Override 103 | public V[] values( V[] array ) { return m.values( array ); } 104 | 105 | @Override 106 | public boolean equals(Object o) { return o == this || m.equals(o); } 107 | @Override 108 | public int hashCode() { return m.hashCode(); } 109 | @Override 110 | public String toString() { return m.toString(); } 111 | @Override 112 | public #e# getNoEntryKey() { return m.getNoEntryKey(); } 113 | 114 | @Override 115 | public boolean forEachKey( T#E#Procedure procedure ) { 116 | return m.forEachKey( procedure ); 117 | } 118 | @Override 119 | public boolean forEachValue( TObjectProcedure procedure ) { 120 | return m.forEachValue( procedure ); 121 | } 122 | @Override 123 | public boolean forEachEntry( T#E#ObjectProcedure procedure ) { 124 | return m.forEachEntry( procedure ); 125 | } 126 | 127 | @Override 128 | public T#E#ObjectIterator iterator() { 129 | return new T#E#ObjectIterator() { 130 | T#E#ObjectIterator iter = m.iterator(); 131 | 132 | @Override 133 | public #e# key() { return iter.key(); } 134 | @Override 135 | public V value() { return iter.value(); } 136 | @Override 137 | public void advance() { iter.advance(); } 138 | @Override 139 | public boolean hasNext() { return iter.hasNext(); } 140 | @Override 141 | public V setValue( V val ) { throw new UnsupportedOperationException(); } 142 | @Override 143 | public void remove() { throw new UnsupportedOperationException(); } 144 | }; 145 | } 146 | 147 | @Override 148 | public V putIfAbsent( #e# key, V value ) { throw new UnsupportedOperationException(); } 149 | @Override 150 | public void transformValues( TObjectFunction function ) { throw new UnsupportedOperationException(); } 151 | @Override 152 | public boolean retainEntries( T#E#ObjectProcedure procedure ) { throw new UnsupportedOperationException(); } 153 | } 154 | -------------------------------------------------------------------------------- /templates/gnu/trove/impl/unmodifiable/Unmodifiable_E_Set.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2008, Robert D. Eden All Rights Reserved. 3 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 4 | // 5 | // This library is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU Lesser General Public 7 | // License as published by the Free Software Foundation; either 8 | // version 2.1 of the License, or (at your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public 16 | // License along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | /////////////////////////////////////////////////////////////////////////////// 19 | 20 | package gnu.trove.impl.unmodifiable; 21 | 22 | 23 | ////////////////////////////////////////////////// 24 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 25 | ////////////////////////////////////////////////// 26 | 27 | //////////////////////////////////////////////////////////// 28 | // THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // 29 | // Access to these methods should be through TCollections // 30 | //////////////////////////////////////////////////////////// 31 | 32 | 33 | import gnu.trove.iterator.*; 34 | import gnu.trove.procedure.*; 35 | import gnu.trove.set.*; 36 | import gnu.trove.list.*; 37 | import gnu.trove.function.*; 38 | import gnu.trove.map.*; 39 | import gnu.trove.*; 40 | 41 | import java.util.Collection; 42 | import java.util.Iterator; 43 | import java.util.Set; 44 | import java.util.Map; 45 | import java.util.RandomAccess; 46 | import java.util.Random; 47 | import java.io.Serializable; 48 | import java.io.ObjectOutputStream; 49 | import java.io.IOException; 50 | 51 | 52 | public class TUnmodifiable#E#Set extends TUnmodifiable#E#Collection 53 | implements T#E#Set, Serializable { 54 | 55 | private static final long serialVersionUID = -9215047833775013803L; 56 | 57 | public TUnmodifiable#E#Set( T#E#Set s ) { super( s ); } 58 | @Override 59 | public boolean equals( Object o ) { return o == this || c.equals(o); } 60 | @Override 61 | public int hashCode() { return c.hashCode(); } 62 | } 63 | -------------------------------------------------------------------------------- /templates/gnu/trove/impl/unmodifiable/Unmodifiable_K__V_Map.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2008, Robert D. Eden All Rights Reserved. 3 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 4 | // 5 | // This library is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU Lesser General Public 7 | // License as published by the Free Software Foundation; either 8 | // version 2.1 of the License, or (at your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public 16 | // License along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | /////////////////////////////////////////////////////////////////////////////// 19 | 20 | package gnu.trove.impl.unmodifiable; 21 | 22 | 23 | ////////////////////////////////////////////////// 24 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 25 | ////////////////////////////////////////////////// 26 | 27 | //////////////////////////////////////////////////////////// 28 | // THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // 29 | // Access to these methods should be through TCollections // 30 | //////////////////////////////////////////////////////////// 31 | 32 | 33 | import gnu.trove.iterator.*; 34 | import gnu.trove.procedure.*; 35 | import gnu.trove.set.*; 36 | import gnu.trove.list.*; 37 | import gnu.trove.function.*; 38 | import gnu.trove.map.*; 39 | import gnu.trove.*; 40 | 41 | import java.util.Collection; 42 | import java.util.Iterator; 43 | import java.util.Set; 44 | import java.util.Map; 45 | import java.util.RandomAccess; 46 | import java.util.Random; 47 | import java.io.Serializable; 48 | import java.io.ObjectOutputStream; 49 | import java.io.IOException; 50 | 51 | 52 | public class TUnmodifiable#K##V#Map implements T#K##V#Map, Serializable { 53 | private static final long serialVersionUID = -1034234728574286014L; 54 | 55 | private final T#K##V#Map m; 56 | 57 | public TUnmodifiable#K##V#Map( T#K##V#Map m ) { 58 | if ( m == null ) 59 | throw new NullPointerException(); 60 | this.m = m; 61 | } 62 | 63 | @Override 64 | public int size() { return m.size(); } 65 | @Override 66 | public boolean isEmpty() { return m.isEmpty(); } 67 | @Override 68 | public boolean containsKey( #k# key ) { return m.containsKey( key ); } 69 | @Override 70 | public boolean containsValue( #v# val ) { return m.containsValue( val ); } 71 | @Override 72 | public #v# get( #k# key) { return m.get( key ); } 73 | 74 | @Override 75 | public #v# put( #k# key, #v# value ) { throw new UnsupportedOperationException(); } 76 | @Override 77 | public #v# remove( #k# key ) { throw new UnsupportedOperationException(); } 78 | @Override 79 | public void putAll( T#K##V#Map m ) { throw new UnsupportedOperationException(); } 80 | @Override 81 | public void putAll( Map map ) { throw new UnsupportedOperationException(); } 82 | @Override 83 | public void clear() { throw new UnsupportedOperationException(); } 84 | 85 | private transient T#K#Set keySet = null; 86 | private transient T#V#Collection values = null; 87 | 88 | @Override 89 | public T#K#Set keySet() { 90 | if ( keySet == null ) 91 | keySet = TCollections.unmodifiableSet( m.keySet() ); 92 | return keySet; 93 | } 94 | @Override 95 | public #k#[] keys() { return m.keys(); } 96 | @Override 97 | public #k#[] keys( #k#[] array ) { return m.keys( array ); } 98 | 99 | @Override 100 | public T#V#Collection valueCollection() { 101 | if ( values == null ) 102 | values = TCollections.unmodifiableCollection( m.valueCollection() ); 103 | return values; 104 | } 105 | @Override 106 | public #v#[] values() { return m.values(); } 107 | @Override 108 | public #v#[] values( #v#[] array ) { return m.values( array ); } 109 | 110 | @Override 111 | public boolean equals(Object o) { return o == this || m.equals(o); } 112 | @Override 113 | public int hashCode() { return m.hashCode(); } 114 | @Override 115 | public String toString() { return m.toString(); } 116 | @Override 117 | public #k# getNoEntryKey() { return m.getNoEntryKey(); } 118 | @Override 119 | public #v# getNoEntryValue() { return m.getNoEntryValue(); } 120 | 121 | @Override 122 | public boolean forEachKey( T#K#Procedure procedure ) { 123 | return m.forEachKey( procedure ); 124 | } 125 | @Override 126 | public boolean forEachValue( T#V#Procedure procedure ) { 127 | return m.forEachValue( procedure ); 128 | } 129 | @Override 130 | public boolean forEachEntry( T#K##V#Procedure procedure ) { 131 | return m.forEachEntry( procedure ); 132 | } 133 | 134 | @Override 135 | public T#K##V#Iterator iterator() { 136 | return new T#K##V#Iterator() { 137 | T#K##V#Iterator iter = m.iterator(); 138 | 139 | @Override 140 | public #k# key() { return iter.key(); } 141 | @Override 142 | public #v# value() { return iter.value(); } 143 | @Override 144 | public void advance() { iter.advance(); } 145 | @Override 146 | public boolean hasNext() { return iter.hasNext(); } 147 | @Override 148 | public #v# setValue( #v# val ) { throw new UnsupportedOperationException(); } 149 | @Override 150 | public void remove() { throw new UnsupportedOperationException(); } 151 | }; 152 | } 153 | 154 | @Override 155 | public #v# putIfAbsent( #k# key, #v# value ) { throw new UnsupportedOperationException(); } 156 | @Override 157 | public void transformValues( T#V#Function function ) { throw new UnsupportedOperationException(); } 158 | @Override 159 | public boolean retainEntries( T#K##V#Procedure procedure ) { throw new UnsupportedOperationException(); } 160 | @Override 161 | public boolean increment( #k# key ) { throw new UnsupportedOperationException(); } 162 | @Override 163 | public boolean adjustValue( #k# key, #v# amount ) { throw new UnsupportedOperationException(); } 164 | @Override 165 | public #v# adjustOrPutValue( #k# key, #v# adjust_amount, #v# put_amount ) { throw new UnsupportedOperationException(); } 166 | } 167 | -------------------------------------------------------------------------------- /templates/gnu/trove/iterator/Object_E_Iterator.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 4 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 5 | // 6 | // This library is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation; either 9 | // version 2.1 of the License, or (at your option) any later version. 10 | // 11 | // This library is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU Lesser General Public 17 | // License along with this program; if not, write to the Free Software 18 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | /////////////////////////////////////////////////////////////////////////////// 20 | 21 | package gnu.trove.iterator; 22 | 23 | ////////////////////////////////////////////////// 24 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 25 | ////////////////////////////////////////////////// 26 | 27 | 28 | /** 29 | * Iterator for maps of type Object and #e#. 30 | *

31 | * The iterator semantics for Trove's primitive maps is slightly different 32 | * from those defined in java.util.Iterator, but still well within 33 | * the scope of the pattern, as defined by Gamma, et al. 34 | *

35 | * This iterator does not implicitly advance to the next entry when 36 | * the value at the current position is retrieved. Rather, you must explicitly 37 | * ask the iterator to advance() and then retrieve either the key(), 38 | * the value() or both. This is done so that you have the option, but not 39 | * the obligation, to retrieve keys and/or values as your application requires, and 40 | * without introducing wrapper objects that would carry both. As the iteration is 41 | * stateful, access to the key/value parts of the current map entry happens in 42 | * constant time. 43 | *

44 | * In practice, the iterator is akin to a "search finger" that you move from 45 | * position to position. Read or write operations affect the current entry only and 46 | * do not assume responsibility for moving the finger. 47 | *

48 | * Here are some sample scenarios for this class of iterator: 49 | *

50 | *

 51 |  * // accessing keys/values through an iterator:
 52 |  * for ( TObject#E#Iterator it = map.iterator(); it.hasNext(); ) {
 53 |  *   it.advance();
 54 |  *   if ( satisfiesCondition( it.key() ) ) {
 55 |  *     doSomethingWithValue( it.value() );
 56 |  *   }
 57 |  * }
 58 |  * 
59 | *

60 | *

 61 |  * // modifying values in-place through iteration:
 62 |  * for ( TObject#E#Iterator it = map.iterator(); it.hasNext(); ) {
 63 |  *   it.advance();
 64 |  *   if ( satisfiesCondition( it.key() ) ) {
 65 |  *     it.setValue( newValueForKey( it.key() ) );
 66 |  *   }
 67 |  * }
 68 |  * 
69 | *

70 | *

 71 |  * // deleting entries during iteration:
 72 |  * for ( TObject#E#Iterator it = map.iterator(); it.hasNext(); ) {
 73 |  *   it.advance();
 74 |  *   if ( satisfiesCondition( it.key() ) ) {
 75 |  *     it.remove();
 76 |  *   }
 77 |  * }
 78 |  * 
79 | *

80 | *

 81 |  * // faster iteration by avoiding hasNext():
 82 |  * TObject#E#Iterator iterator = map.iterator();
 83 |  * for ( int i = map.size(); i-- > 0; ) {
 84 |  *   iterator.advance();
 85 |  *   doSomethingWithKeyAndValue( iterator.key(), iterator.value() );
 86 |  * }
 87 |  * 
88 | * 89 | * @author Eric D. Friedman 90 | * @author Rob Eden 91 | * @author Jeff Randall 92 | * @version $Id: Object_E_Iterator.template,v 1.1.2.1 2009/09/14 19:02:20 upholderoftruth Exp $ 93 | */ 94 | public interface TObject#E#Iterator extends TAdvancingIterator { 95 | 96 | /** 97 | * Provides access to the key of the mapping at the iterator's position. 98 | * Note that you must advance() the iterator at least once 99 | * before invoking this method. 100 | * 101 | * @return the key of the entry at the iterator's current position. 102 | */ 103 | public K key(); 104 | 105 | 106 | /** 107 | * Provides access to the value of the mapping at the iterator's position. 108 | * Note that you must advance() the iterator at least once 109 | * before invoking this method. 110 | * 111 | * @return the value of the entry at the iterator's current position. 112 | */ 113 | public #e# value(); 114 | 115 | 116 | /** 117 | * Replace the value of the mapping at the iterator's position with the 118 | * specified value. Note that you must advance() the iterator at 119 | * least once before invoking this method. 120 | * 121 | * @param val the value to set in the current entry 122 | * @return the old value of the entry. 123 | */ 124 | public #e# setValue( #e# val ); 125 | } 126 | -------------------------------------------------------------------------------- /templates/gnu/trove/iterator/_E_Iterator.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.iterator; 20 | 21 | ////////////////////////////////////////////////// 22 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 23 | ////////////////////////////////////////////////// 24 | 25 | 26 | /** 27 | * Iterator for #e# collections. 28 | */ 29 | public interface T#E#Iterator extends TIterator { 30 | /** 31 | * Advances the iterator to the next element in the underlying collection 32 | * and returns it. 33 | * 34 | * @return the next #e# in the collection 35 | * @exception NoSuchElementException if the iterator is already exhausted 36 | */ 37 | public #e# next(); 38 | } 39 | -------------------------------------------------------------------------------- /templates/gnu/trove/iterator/_E_ObjectIterator.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 4 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 5 | // 6 | // This library is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation; either 9 | // version 2.1 of the License, or (at your option) any later version. 10 | // 11 | // This library is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU Lesser General Public 17 | // License along with this program; if not, write to the Free Software 18 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | /////////////////////////////////////////////////////////////////////////////// 20 | 21 | package gnu.trove.iterator; 22 | 23 | ////////////////////////////////////////////////// 24 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 25 | ////////////////////////////////////////////////// 26 | 27 | 28 | /** 29 | * Iterator for maps of type #e# and Object. 30 | *

31 | * The iterator semantics for Trove's primitive maps is slightly different 32 | * from those defined in java.util.Iterator, but still well within 33 | * the scope of the pattern, as defined by Gamma, et al. 34 | *

35 | * This iterator does not implicitly advance to the next entry when 36 | * the value at the current position is retrieved. Rather, you must explicitly 37 | * ask the iterator to advance() and then retrieve either the key(), 38 | * the value() or both. This is done so that you have the option, but not 39 | * the obligation, to retrieve keys and/or values as your application requires, and 40 | * without introducing wrapper objects that would carry both. As the iteration is 41 | * stateful, access to the key/value parts of the current map entry happens in 42 | * constant time. 43 | *

44 | * In practice, the iterator is akin to a "search finger" that you move from 45 | * position to position. Read or write operations affect the current entry only and 46 | * do not assume responsibility for moving the finger. 47 | *

48 | * Here are some sample scenarios for this class of iterator: 49 | *

50 | *

 51 |  * // accessing keys/values through an iterator:
 52 |  * for ( T#E#ObjectIterator it = map.iterator(); it.hasNext(); ) {
 53 |  *   it.advance();
 54 |  *   if ( satisfiesCondition( it.key() ) ) {
 55 |  *     doSomethingWithValue( it.value() );
 56 |  *   }
 57 |  * }
 58 |  * 
59 | *

60 | *

 61 |  * // modifying values in-place through iteration:
 62 |  * for ( T#E#ObjectIterator it = map.iterator(); it.hasNext(); ) {
 63 |  *   it.advance();
 64 |  *   if ( satisfiesCondition( it.key() ) ) {
 65 |  *     it.setValue( newValueForKey( it.key() ) );
 66 |  *   }
 67 |  * }
 68 |  * 
69 | *

70 | *

 71 |  * // deleting entries during iteration:
 72 |  * for ( T#E#ObjectIterator it = map.iterator(); it.hasNext(); ) {
 73 |  *   it.advance();
 74 |  *   if ( satisfiesCondition( it.key() ) ) {
 75 |  *     it.remove();
 76 |  *   }
 77 |  * }
 78 |  * 
79 | *

80 | *

 81 |  * // faster iteration by avoiding hasNext():
 82 |  * T#E#ObjectIterator iterator = map.iterator();
 83 |  * for ( int i = map.size(); i-- > 0; ) {
 84 |  *   iterator.advance();
 85 |  *   doSomethingWithKeyAndValue( iterator.key(), iterator.value() );
 86 |  * }
 87 |  * 
88 | * 89 | * @author Eric D. Friedman 90 | * @author Rob Eden 91 | * @author Jeff Randall 92 | * @version $Id: _E_ObjectIterator.template,v 1.1.2.1 2009/09/15 02:38:31 upholderoftruth Exp $ 93 | */ 94 | public interface T#E#ObjectIterator extends TAdvancingIterator { 95 | 96 | /** 97 | * Provides access to the key of the mapping at the iterator's position. 98 | * Note that you must advance() the iterator at least once 99 | * before invoking this method. 100 | * 101 | * @return the key of the entry at the iterator's current position. 102 | */ 103 | public #e# key(); 104 | 105 | 106 | /** 107 | * Provides access to the value of the mapping at the iterator's position. 108 | * Note that you must advance() the iterator at least once 109 | * before invoking this method. 110 | * 111 | * @return the value of the entry at the iterator's current position. 112 | */ 113 | public V value(); 114 | 115 | 116 | /** 117 | * Replace the value of the mapping at the iterator's position with the 118 | * specified value. Note that you must advance() the iterator at 119 | * least once before invoking this method. 120 | * 121 | * @param val the value to set in the current entry 122 | * @return the old value of the entry. 123 | */ 124 | public V setValue( V val ); 125 | } 126 | -------------------------------------------------------------------------------- /templates/gnu/trove/iterator/_K__V_Iterator.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.iterator; 20 | 21 | ////////////////////////////////////////////////// 22 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 23 | ////////////////////////////////////////////////// 24 | 25 | 26 | /** 27 | * Iterator for maps of type #k# and #v#. 28 | * 29 | *

The iterator semantics for Trove's primitive maps is slightly different 30 | * from those defined in java.util.Iterator, but still well within 31 | * the scope of the pattern, as defined by Gamma, et al.

32 | * 33 | *

This iterator does not implicitly advance to the next entry when 34 | * the value at the current position is retrieved. Rather, you must explicitly 35 | * ask the iterator to advance() and then retrieve either the key(), 36 | * the value() or both. This is done so that you have the option, but not 37 | * the obligation, to retrieve keys and/or values as your application requires, and 38 | * without introducing wrapper objects that would carry both. As the iteration is 39 | * stateful, access to the key/value parts of the current map entry happens in 40 | * constant time.

41 | * 42 | *

In practice, the iterator is akin to a "search finger" that you move from 43 | * position to position. Read or write operations affect the current entry only and 44 | * do not assume responsibility for moving the finger.

45 | * 46 | *

Here are some sample scenarios for this class of iterator:

47 | * 48 | *
 49 |  * // accessing keys/values through an iterator:
 50 |  * for ( T#K##V#Iterator it = map.iterator(); it.hasNext(); ) {
 51 |  *   it.advance();
 52 |  *   if ( satisfiesCondition( it.key() ) {
 53 |  *     doSomethingWithValue( it.value() );
 54 |  *   }
 55 |  * }
 56 |  * 
57 | * 58 | *
 59 |  * // modifying values in-place through iteration:
 60 |  * for ( T#K##V#Iterator it = map.iterator(); it.hasNext(); ) {
 61 |  *   it.advance();
 62 |  *   if ( satisfiesCondition( it.key() ) {
 63 |  *     it.setValue( newValueForKey( it.key() ) );
 64 |  *   }
 65 |  * }
 66 |  * 
67 | * 68 | *
 69 |  * // deleting entries during iteration:
 70 |  * for ( T#K##V#Iterator it = map.iterator(); it.hasNext(); ) {
 71 |  *   it.advance();
 72 |  *   if ( satisfiesCondition( it.key() ) {
 73 |  *     it.remove();
 74 |  *   }
 75 |  * }
 76 |  * 
77 | * 78 | *
 79 |  * // faster iteration by avoiding hasNext():
 80 |  * T#K##V#Iterator iterator = map.iterator();
 81 |  * for ( int i = map.size(); i-- > 0; ) {
 82 |  *   iterator.advance();
 83 |  *   doSomethingWithKeyAndValue( iterator.key(), iterator.value() );
 84 |  * }
 85 |  * 
86 | */ 87 | public interface T#K##V#Iterator extends TAdvancingIterator { 88 | /** 89 | * Provides access to the key of the mapping at the iterator's position. 90 | * Note that you must advance() the iterator at least once 91 | * before invoking this method. 92 | * 93 | * @return the key of the entry at the iterator's current position. 94 | */ 95 | public #k# key(); 96 | 97 | /** 98 | * Provides access to the value of the mapping at the iterator's position. 99 | * Note that you must advance() the iterator at least once 100 | * before invoking this method. 101 | * 102 | * @return the value of the entry at the iterator's current position. 103 | */ 104 | public #v# value(); 105 | 106 | /** 107 | * Replace the value of the mapping at the iterator's position with the 108 | * specified value. Note that you must advance() the iterator at 109 | * least once before invoking this method. 110 | * 111 | * @param val the value to set in the current entry 112 | * @return the old value of the entry. 113 | */ 114 | public #v# setValue( #v# val ); 115 | } 116 | -------------------------------------------------------------------------------- /templates/gnu/trove/procedure/Object_E_Procedure.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.procedure; 20 | 21 | ////////////////////////////////////////////////// 22 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 23 | ////////////////////////////////////////////////// 24 | 25 | 26 | /** 27 | * Interface for procedures that take two parameters of type Object and #e#. 28 | */ 29 | public interface TObject#E#Procedure { 30 | 31 | /** 32 | * Executes this procedure. A false return value indicates that 33 | * the application executing this procedure should not invoke this 34 | * procedure again. 35 | * 36 | * @param a an Object value 37 | * @param b a #e# value 38 | * @return true if additional invocations of the procedure are 39 | * allowed. 40 | */ 41 | public boolean execute( K a, #e# b ); 42 | } 43 | -------------------------------------------------------------------------------- /templates/gnu/trove/procedure/_E_ObjectProcedure.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.procedure; 20 | 21 | ////////////////////////////////////////////////// 22 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 23 | ////////////////////////////////////////////////// 24 | 25 | 26 | /** 27 | * Interface for procedures that take two parameters of type #e# and Object. 28 | */ 29 | public interface T#E#ObjectProcedure { 30 | 31 | /** 32 | * Executes this procedure. A false return value indicates that 33 | * the application executing this procedure should not invoke this 34 | * procedure again. 35 | * 36 | * @param a a #e# value 37 | * @param b an Object value 38 | * @return true if additional invocations of the procedure are 39 | * allowed. 40 | */ 41 | public boolean execute( #e# a, T b ); 42 | } 43 | -------------------------------------------------------------------------------- /templates/gnu/trove/procedure/_E_Procedure.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.procedure; 20 | 21 | 22 | ////////////////////////////////////////////////// 23 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 24 | ////////////////////////////////////////////////// 25 | 26 | 27 | /** 28 | * Interface for procedures with one #e# parameter. 29 | */ 30 | public interface T#E#Procedure { 31 | /** 32 | * Executes this procedure. A false return value indicates that 33 | * the application executing this procedure should not invoke this 34 | * procedure again. 35 | * 36 | * @param value a value of type #e# 37 | * @return true if additional invocations of the procedure are 38 | * allowed. 39 | */ 40 | public boolean execute( #e# value ); 41 | } 42 | -------------------------------------------------------------------------------- /templates/gnu/trove/procedure/_K__V_Procedure.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.procedure; 20 | 21 | ////////////////////////////////////////////////// 22 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 23 | ////////////////////////////////////////////////// 24 | 25 | 26 | /** 27 | * Interface for procedures that take two parameters of type #k# and #v#. 28 | */ 29 | public interface T#K##V#Procedure { 30 | 31 | /** 32 | * Executes this procedure. A false return value indicates that 33 | * the application executing this procedure should not invoke this 34 | * procedure again. 35 | * 36 | * @param a a #k# value 37 | * @param b a #v# value 38 | * @return true if additional invocations of the procedure are 39 | * allowed. 40 | */ 41 | public boolean execute( #k# a, #v# b ); 42 | } 43 | -------------------------------------------------------------------------------- /templates/gnu/trove/queue/_E_Queue.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | package gnu.trove.queue; 20 | 21 | 22 | import gnu.trove.T#E#Collection; 23 | 24 | import java.io.Serializable; 25 | 26 | /** 27 | * Interface for Trove queue implementations. 28 | * 29 | * @see java.util.Queue 30 | */ 31 | public interface T#E#Queue extends T#E#Collection { 32 | /** 33 | * Retrieves and removes the head of this queue. This method differs from 34 | * {@link #poll} only in that it throws an exception if this queue is empty. 35 | */ 36 | public #e# element(); 37 | 38 | 39 | /** 40 | * Inserts the specified element into this queue if it is possible to do so 41 | * immediately without violating capacity restrictions. When using a 42 | * capacity-restricted queue, this method is generally preferable to 43 | * {@link #add}, which can fail to insert an element only by throwing an exception. 44 | * 45 | * @param e The element to add. 46 | * 47 | * @return true if the element was added to this queue, else false 48 | */ 49 | public boolean offer( #e# e ); 50 | 51 | 52 | /** 53 | * Retrieves, but does not remove, the head of this queue, or returns 54 | * {@link #getNoEntryValue} if this queue is empty. 55 | * 56 | * @return the head of this queue, or {@link #getNoEntryValue} if this queue is empty 57 | */ 58 | public #e# peek(); 59 | 60 | 61 | /** 62 | * Retrieves and removes the head of this queue, or returns {@link #getNoEntryValue} 63 | * if this queue is empty. 64 | * 65 | * @return the head of this queue, or {@link #getNoEntryValue} if this queue is empty 66 | */ 67 | public #e# poll(); 68 | } 69 | -------------------------------------------------------------------------------- /templates/gnu/trove/stack/_E_Stack.template: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2001, Eric D. Friedman All Rights Reserved. 3 | // Copyright (c) 2009, Rob Eden All Rights Reserved. 4 | // Copyright (c) 2009, Jeff Randall All Rights Reserved. 5 | // 6 | // This library is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation; either 9 | // version 2.1 of the License, or (at your option) any later version. 10 | // 11 | // This library is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU Lesser General Public 17 | // License along with this program; if not, write to the Free Software 18 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | /////////////////////////////////////////////////////////////////////////////// 20 | 21 | 22 | package gnu.trove.stack; 23 | 24 | ////////////////////////////////////////////////// 25 | // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // 26 | ////////////////////////////////////////////////// 27 | 28 | import java.io.Serializable; 29 | 30 | 31 | /** 32 | * A stack of #e# primitives. 33 | */ 34 | public interface T#E#Stack { 35 | 36 | /** 37 | * Returns the value that is used to represent null. The default 38 | * value is generally zero, but can be changed during construction 39 | * of the collection. 40 | * 41 | * @return the value that represents null 42 | */ 43 | public #e# getNoEntryValue(); 44 | 45 | 46 | /** 47 | * Pushes the value onto the top of the stack. 48 | * 49 | * @param val an #e# value 50 | */ 51 | public void push( #e# val ); 52 | 53 | 54 | /** 55 | * Removes and returns the value at the top of the stack. 56 | * 57 | * @return an #e# value 58 | */ 59 | public #e# pop(); 60 | 61 | 62 | /** 63 | * Returns the value at the top of the stack. 64 | * 65 | * @return an #e# value 66 | */ 67 | public #e# peek(); 68 | 69 | 70 | /** 71 | * Returns the current depth of the stack. 72 | */ 73 | public int size(); 74 | 75 | 76 | /** 77 | * Clears the stack. 78 | */ 79 | public void clear(); 80 | 81 | 82 | /** 83 | * Copies the contents of the stack into a native array. Note that this will NOT 84 | * pop them out of the stack. 85 | * 86 | * @return an #e#[] value 87 | */ 88 | public #e#[] toArray(); 89 | 90 | 91 | /** 92 | * Copies a slice of the list into a native array. Note that this will NOT 93 | * pop them out of the stack. 94 | * 95 | * @param dest the array to copy into. 96 | */ 97 | public void toArray( #e#[] dest ); 98 | } 99 | --------------------------------------------------------------------------------