ArrayMAP介绍

来源:互联网 发布:4y4淘宝装修平台 编辑:程序博客网 时间:2024/05/21 04:38

它不是一个适应大数据的数据结构,相比传统的HashMap速度要慢,因为查找方法是二分法,并且当你删除或者添加数据时,会对空间重新调整,在使用大量数据时,效率并不明显,低于50%。


ArrayMap is a generic key->value mapping data structure that is designed to be more memory efficient than a traditionaljava.util.HashMap. It keeps its mappings in an array data structure -- an integer array of hash codes for each item, andan Object array of the key/value pairs. This allows it to avoid having to create an extra object for every entry put in to the map, and it also tries to control the growth of the size of these arrays more aggressively (since growing them only requires copying the entries in the array, not rebuilding a hash map).


Note that this implementation is not intended to be appropriate for data structures that may contain large numbers of items. It is generally slower than a traditional HashMap, since lookups require a binary search and adds and removes require inserting and deleting entries in the array. 

public final class ArrayMap<K, V> implements Map<K, V> {

staticObject[] mBaseCache;
static int mBaseCacheSize;

int[] mHashes; //mHashes数组中保存的是每一项的HashCode值

Object[] mArray; //,mArray中就是键值对,每两个元素代表一个键值对,前面保存key,后面的保存value

}



public interface MAP<K,V> {

int size();

boolean isEmpty();

boolean containsKey(Object key);

boolean containsVlaue(Object value);

V get(Object key);

V put(K key, V value);

V remove(Object key);

void putAll(Map<? extends K, ? extends V> m);

void clear();

Set<K> keySet();

Collection<V> values();

boolean equals(Object o);

int hasCode();


}

微笑


1 0
原创粉丝点击