• Stars
    star
    137
  • Rank 266,121 (Top 6 %)
  • Language
    Java
  • Created almost 10 years ago
  • Updated almost 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Save 25% memory for you.

Build Status

中文说明

maven Central

<dependency>
    <groupId>in.srain.cube</groupId>
    <artifactId>simple-hashset</artifactId>
    <type>jar</type>
    <version>1.0.1</version>
</dependency>

gradle:

compile 'in.srain.cube:simple-hashset:1.0.1'

Save 25% memory

Object Size in Java: http://www.codeinstructions.com/2008/12/java-objects-memory-structure.html, http://btoddb-java-sizing.blogspot.com/2012/01/object-sizes.html

Object Size in Davlik : http://www.liaohuqiu.net/posts/android-object-size-dalvik/

In fact, java.util.HashSet is just a wrapper of java.util.HashMap, so its retained heap size is O(n * entry_size).

The java.util.HashMap is using separate chaining to process collision, n is the sum of the count of element and the count of free slots remain in array.

The entry_size is the shadow heap size of the jave.util.HashMap.Entry.

The definition of java.util.HashMap.Entry:

static class Entry<K,V> implements Map.Entry<K,V> {
    final K key;
    V value;
    Entry<K,V> next;
    int hash;
}

So the shadow heap size is:

  • 32bit JVM: 8 + 4 * 4 = 24 bytes
  • 64bit JVM -UseCompressedOops: 16 + 8 * 4 = 48 bytes.
  • 64bit JVM +UseCompressedOops: 12 + 4 * 4 + 4(padding) = 32 bytes.
  • Davlik: 12 + 4 * 4 + 4(padding) = 32 bytes.

In fact V value is usless for HashSet, we can implement a HashSet use the following SimpleHashSetEntry:

private static class SimpleHashSetEntry<T> {

    private int mHash;
    private T mKey;
    private SimpleHashSetEntry<T> mNext;
}

The retained heap size is:

  • 32bit JVM: 8 + 4 * 3 + (padding) = 24 bytes
  • 64bit JVM -UseCompressedOops: 16 + 8 * 3 = 40 bytes. (8 bytes saved, 16.66%)
  • 64bit JVM +UseCompressedOops: 12 + 4 * 3 = 24 bytes. (8 bytes saved, 25%)
  • Davlik: 12 + 4 * 3 = 24 bytes (8 bytes saved, 25%).

License

Apache 2

More Repositories

1

android-Ultra-Pull-To-Refresh

Ultra Pull to Refresh for Android. Support all the views.
Java
9,584
star
2

android-UCToast

Demonstrate how UC browser display a system overlay view in any platform above API level 9.
Java
1,378
star
3

android-GridViewWithHeaderAndFooter

A GridView which can addHeaderView and addFooterView
Java
1,336
star
4

cube-sdk

A light package for Android development, it handles loading image and network request.
Java
1,185
star
5

android-cube-app

Java
1,010
star
6

android-support-23.2-sample

Sample Project for Android Support Library 23.2
Java
773
star
7

leakcanary-demo

The demo for leakcanary: https://github.com/square/leakcanary
Java
631
star
8

fresco-docs-cn

Chinese documentation for fresco. The github pages site is: http://fresco-cn.org/
JavaScript
484
star
9

fresco-demo-for-gradle

404
star
10

wechat-helper

WeChat Helper is a chrome plugin.
JavaScript
365
star
11

icon-font-for-multiple-platforms

Extra icons from Sketch file, generate font files, demos how to use font files on Web, iOS and Android.
Java
359
star
12

android-dynamic-load-awesome

320
star
13

android-ILoveBaidu

I Love Baidu.
Java
222
star
14

android-RavenServer

Start an activity in WeChat!
Java
211
star
15

btcbot-open

在 binance 和 bitfinex 搬砖的机器人,目标是赚更多 BTC 🍺🍺🍺🍺🍺
Python
198
star
16

android-ClipboardManagerCompat

ClipboardManager to API level 1.
Java
182
star
17

android-ActionQueue

ActionQueue allows you run action one by one.
Java
179
star
18

abot-lucky-money

Java
160
star
19

f8-app-tutorial-cn

HTML
111
star
20

follow-each-other

97
star
21

android-CLog

Java
71
star
22

jekyll-multiple-languages

A Multiple Languages plugin for Jekyll
Ruby
46
star
23

ssh-auto-login

Shell
43
star
24

leetcode-helper

Leetcode Chrome extension.
JavaScript
39
star
25

vim_anywhere

Vim Script
29
star
26

fresco-demo-for-maven

A demo project of how to use fresco in Intellij IDEA / Maven
Java
28
star
27

android-BitMaskSample

BitMask Sample
Java
24
star
28

ActionSheet

ActionSheet for Android
23
star
29

qq-tribe-rule

23
star
30

work-anywhere

Shell
21
star
31

leetcode-0x01

19
star
32

infer-docs-cn

Chinese documentation for Facebook Infer.
JavaScript
18
star
33

ReactNativeTestGradlePlugin

ReactNativeTestGradlePlugin
Objective-C
16
star
34

jekyll-multiple-languages-sample

Sample for jekyll-multiple-languages
HTML
15
star
35

liaohuqiu.github.io

It is my blog on github
HTML
14
star
36

chinese-simplified-common-characters

3754 个常用汉字列表 / A list of 3754 Chinese simplified common characters.
13
star
37

cube-php

JavaScript
10
star
38

cube-box

JavaScript
9
star
39

umeng-libs

Python
8
star
40

java-object-size

Java
8
star
41

ABCDFragment

Demo for http://stackoverflow.com/questions/30781141/hide-parent-fragment-from-the-fragment-in-the-viewpager
Java
7
star
42

list-sorter

JavaScript
6
star
43

docker-simple-obfs

Shell
6
star
44

shadowsocks-libenv

Python
5
star
45

centos-setup

Shell
5
star
46

bt-docs

A bootstrap docs like document site.
CSS
5
star
47

android-cube-app-server

JavaScript
4
star
48

umeng-share

Python
4
star
49

cube-sdk-pages

github pages for cube-sdk
CSS
4
star
50

android-Ultra-Pull-To-Refresh-docs

Documentation for android Ultra Pull to Refresh
CSS
4
star
51

kx_auto_login

auto input password and pre-passcode for login in, and keep login session for next login
Shell
3
star
52

dnsmasq-docker

dnsmasq + rsyslog, easy to tune
Shell
3
star
53

keep-running

Monitor your program, keep it running.
Python
3
star
54

aliyun-ossutil-docker

Shell
3
star
55

docker-chinadns

ChinaDns Docker image, base on alpine.
Shell
3
star
56

android-dotview

Java
3
star
57

cube-rpc-python

Python implement for Cube RPC
Python
3
star
58

gradle-generate-maven-pom

2
star
59

fb-docs-TextLayoutBuilder

HTML
2
star
60

cube-rpc

SPEC for cube-rpc
2
star
61

cube-sdk-server

Shell
2
star
62

cold-dns

Shell
1
star
63

mac-setup

Shell
1
star
64

docker-shadowsocks-gateway

Shell
1
star
65

appcfg.py-save-authorization

Save the authorization information of Google Cloud Platform after a successful authorization.
Shell
1
star
66

python-cmd-server

Python
1
star
67

cube-php-docs

HTML
1
star
68

liaohuming.github.io

我的个人博客[email protected]
HTML
1
star
69

ttl

JavaScript
1
star
70

hs-airdrop

HNS 空投
Python
1
star