????????
????????????????????"????"??????????????????????Android?????????(Spring)???????????????????????HashMap?о???????????????????????????Android?????HmacSHA256???????????????????????????????????????????????
??????????????????????????????????????????????HashMap???з??????????????????????key??????????????
??????HashCode?????????????£??????key??HashMap?д????λ??????????????????hashCode???????????key-value put???????????????λ??????????????
???????????
??????????????ó???HashMap?????????Java??Android????HashMap?????????????????hashCode()??????????????СС????????£???????????????Android??????Java?е?hashCode()?????????????????????????????????????????????????=??=??
????????????????£?
<??-- Android -->
@Override public int hashCode() {
int hash = hashCode;
if (hash == 0) {
if (count == 0) {
return 0;
}
final int end = count + offset;
final char[] chars = value;
for (int i = offset; i < end; ++i) {
hash = 31*hash + chars[i];
}
hashCode = hash;
}
return hash;
}
<??-- Java-->
public int hashCode() {
int h = hash;
int len = count;
if (h == 0 && len > 0) {
int off = offset;
char val[] = value;
for (int i = 0; i < len; i++) {
h = 31*h + val[off++];
}
hash = h;
}
return h;
}
???????Σ???????????????????????????????????????????????????????????????table??С???????Java?е?table????С??16×0.75=12(????×????????)????Android??table??????С??2?????????????????????????????????HashMap???????key???????????????
<!-- Android -->
private static final Entry[] EMPTY_TABLE
= new HashMapEntry[MINIMUM_CAPACITY >>> 1];
//????????
public HashMap() {
table = (HashMapEntry<K?? V>[]) EMPTY_TABLE;
threshold = -1; // Forces first put invocation to replace EMPTY_TABLE
}
<!-- Java -->
static final int DEFAULT_INITIAL_CAPACITY = 16;
static final float DEFAULT_LOAD_FACTOR = 0.75f;
//????????
public HashMap() {
this(DEFAULT_INITIAL_CAPACITY??DEFAULT_LOAD_FACTOR);
}
?????????????????????Android????????HashMap?????"???(threshold )"???趨??????Java????????????????????
<!-- Android -->
//?????????table??С??3/4
threshold = (newCapacity >> 1) + (newCapacity >> 2);
<!-- Java -->
//????????*??????????????+1???С?
threshold = (int)Math.min(capacity * loadFactor?? MAXIMUM_CAPACITY + 1);
????С??
???????????????HashMap??????????????е????????????????????????????????????м???????????HashMap????????