I'm trying to implement a database backed java.util.Map
, most of the interface like put and get was easily implemented however I am having trouble figuring out the best way to implement:
@Override
public Set<K> keySet() {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<V> values() {
// TODO Auto-generated method stub
return null;
}
@Override
public Set<Map.Entry<K, V>> entrySet() {
// TODO Auto-generated method stub
return null;
}
My concern would be that keys and values could count to millions records. So I don't think its memory and cpu efficient to fetch and store all "keys" or "values" when these methods are accessed.
What are the options to implement a memory efficient way to implementing these?
What is the strategy to implement an iterator for the entrySet?