java - Optimization done by an EnumMap/EnumSet -


i read article enummap. it's written "using enummap brings implementation specific benefits done enum keys, in short enummap optimized map implementation exclusively enum keys."

it's written "enum implemented using arrays , common operations result in constant time. if thinking of high performance map, enummap decent choice enumeration data."


can point me out how optimizations done ? ("operations result in constant time")

looking @ documentation enummap:

a specialized map implementation use enum type keys. of keys in enum map must come single enum type specified, explicitly or implicitly, when map created. enum maps represented internally arrays. representation extremely compact , efficient.

enum maps maintained in natural order of keys (the order in enum constants declared). reflected in iterators returned collections views (keyset(), entryset(), , values()).

in short, enummap array, of type of values of map. in other words, enummap<someenum, somevalue>, somevalue[].

how indexes assigned, might ask? assigned natural order of enum. example:

enum day {     mon, tue, wed, thu, fri, sat, sun } 

the above enum has following natural order.

mon tue wed thu fri sat sun  0   1   2   3   4   5   6 

so, operation map.put(day.fri, "yay!") can viewed as:

array[4] = "yay!"; 

array access constant time operation, , that's why enummap benefits of well. (get()) works same way.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -