I need a Map impl which would consist of stacked maps, which I could push()
and pop()
, and the values would be "added" or "removed" if they belong to the map being pushed/popped. And the values would be searched top/bottom (or optionally bottom/top).
Is there an existing impl in JDK or elsewhere?
Example:
- Stack
- map4
- foo => aaa
- bar => 45
- map3
- bar => 22
- map2
- foo => ccc
- baz => uuu
- map1
- map4
For this, get("baz")
would return "uuu"
, get("foo")
would return "aaa"
, size()
would return 3
etc.
It's something like JavaScript's prototypal inheritance.
There's one impl I'm wishing for some more sophisticated impl, which wouldn't really go through all layers every time I call any method. Read methods are going to be more often than push()/pop(), so there could be some pre-computation during that.