
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
com.github.vlsi.compactmap:parent
Add Maven dependency:
<dependency>
<groupId>com.github.vlsi.compactmap</groupId>
<artifactId>compactmap</artifactId>
<version>1.3.0</version>
</dependency>
Gradle:
compile("com.github.vlsi.compactmap:compactmap:1.3.0")
This is a memory efficient alternative to HashMap. Main design goal is taken from "Fast Property Access" http://code.google.com/apis/v8/design.html#prop_access.
This implementation however can store specific key-value pairs out of the map, so they do not consume memory when repeated in different maps.
The expected memory consumption (8u40, 64 bit, compressed references) is as follows:
# of elements CompactHashMap HashMap (with 1.0 fillFactor)
0 32 48
1 32 104
2 32 136
3 32 176
4 64 208
5 64 256
6 64 288
7 72 320
8 72 352
In other words, the first three non default values consume the same 32 bytes, then map grows as 32 + 16 + 4 * (n-2) == 40 + 4 * n. Regular HashMap grows as 64 + 36 * n.
The runtime of put and get is constant. The expected runtime is as follows (measured in hashmap and array accesses):
best case worst case
get 1 hashmap + 1 array 2 hashmap
put 1 hashmap + 1 array 6 hashmap
// Mark height->auto a default mapping entry, so it would not consume memory in CompactHashMaps
CompactHashMapDefaultValues.add("height", "auto");
// Mark all values of width as default, so they would not consume memory in real maps
CompactHashMapDefaultValues.add("width");
CompactHashMap<String, String> map = new CompactHashMap<String, String>();
map.put("height", "auto"); // does not consume memory in map
map.put("width", "100%"); // does not consume memory in map either
map.put("id", "myFirstButton"); // consumes some memory
map.get("height"); // => "auto"
map.get("width"); // => "100%"
map.get("id"); // => "myFirstButton"
map.put("height", "50px"); // consumes some memory (switches from default to custom)
map.get("height"); // => "50px"
This library is distibuted under terms of GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
v2.0:
v1.3.0
Map#toString
Map#hashCode
+ equals
Map.Entry#hashCode
+ equals
Map.Entry#toString
Map#containsValue
(it is slow but it works)guava-testlib
for Map
implementation testingv1.2.1
v1.2.0
v1.1
Vladimir Sitnikov sitnikov.vladimir@gmail.com
FAQs
Hash table implementation modelled after memory efficient V8's Fast Property Access
We found that com.github.vlsi.compactmap:parent demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.