Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gfx/java-weakidentityhashmap
A standalone library for WeakIdentityHashMap to implement inside-out fields
https://github.com/gfx/java-weakidentityhashmap
Last synced: 26 days ago
JSON representation
A standalone library for WeakIdentityHashMap to implement inside-out fields
- Host: GitHub
- URL: https://github.com/gfx/java-weakidentityhashmap
- Owner: gfx
- Created: 2014-05-26T23:29:56.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-07-05T07:26:13.000Z (over 10 years ago)
- Last Synced: 2023-07-26T21:57:38.331Z (over 1 year ago)
- Language: Java
- Homepage:
- Size: 324 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# WeakIdentityHashMap [![Build Status](https://travis-ci.org/gfx/Java-WeakIdentityHashMap.svg?branch=master)](https://travis-ci.org/gfx/Java-WeakIdentityHashMap) [![Coverage Status](https://coveralls.io/repos/gfx/Java-WeakIdentityHashMap/badge.png)](https://coveralls.io/r/gfx/Java-WeakIdentityHashMap)
## How To Use
In build.gradle:
```gradle
dependencies {
compile 'com.github.gfx.util:weak-identity-hash-map:2.0.+'
}
```In code:
```java
Activity activity = ...;
WeakIdentityHashMap foo = new WeakIdentityHashMap<>()// Set an activity's field.
// If activity is gone, this value is also gone, too.
foo.put(activity, "my field");String value = foo.get(activity); // "my field"
```## TEST COVERAGES
```
./gradlew check jacocoTestReport
open library/build/reports/jacoco/test/html/index.html
```## PERFORMANCE
On Xperia A / Android 4.2.2:
```java
// in an Activity's onCreate()
Map map = new WeakIdentityHashMap<>();
map.put(this, "foo");long t0 = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
String a = map.get(this);
assert a != null;
}
Log.d("XXX", "WeakIdentityHashMap0: " + (System.currentTimeMillis() - t0));t0 = System.currentTimeMillis();
for (int i = 0; i < 200000; i++) {
String a = map.get(this);
assert a != null;
}
Log.d("XXX", "WeakIdentityHashMap1: " + (System.currentTimeMillis() - t0));
```1.0.0:
```
D/XXX﹕ WeakIdentityHashMap1: 449
D/XXX﹕ WeakIdentityHashMap2: 1108
```2.0.0:
```
D/XXX﹕ WeakIdentityHashMap1: 167
D/XXX﹕ WeakIdentityHashMap2: 290
```