java - Efficiency regarding storing HashMap values vs. referencing values -


morning all! coding today using hash map , wondering comparison of efficiency in case hope hasn't been answered. lets have file of data each line entry, , 3 columns following fields: number of blocks, starting block, ending block. use hash map keys 3 column data fields. can find out number of blocks each entry taking ending block of entry, subtracting starting entry, , adding one. example:

num of blocks| starting block | ending block

    2           1          2           

which more efficient: omit num of blocks field hash map, , calculating map.get("ending block") - map.get("starting block") + 1 (which in case 2-1+1), or store num of blocks in map x number of entries , calling map.get("num of blocks");

sorry if dumb question little bit experienced in using hash maps.

well depends on data , purpose of hash map. if data large , away storing number of blocks. if can afford that, keep need enter once, , can number of times. calling 1 on map. whereas if dont store it, 2 values hashmap. scenario if need starting , ending block each time regardless of use case, can omit number of blocks have make calls anyway.

i hope answered query.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -