I have a two dimensional data with one dimension is ordered and another one is categorical, for example, country
and city_age
:
country | age | city |
---|---|---|
Italy | 2773 | Rome |
Germany | 784 | Berlin |
USA | 397 | New York |
Suppose this database is bigdata.
Now I want to set age range, for example 500-1500 and then search for countries in O(1)
. Is it possible?
If I store data in
using TCountryName = string;
using TCityAge = int;
using TCityName = string;
unordered_map<TCountryName, map<TCityAge, TCityName>> data;
It will take me O(Log[n])
to filter inner map
in each call, and if I define
map<TCityAge, unordered_map<TCountyName, TCityName>> data;
if will to iterate over inner map with O(n)
, and if I define
unordered_map<tuple<TCountyName,TCityAge>, TCityName> data;
it will be O(1)
but only if I know age beforehead.
Is it possible to have data structure to search both by range and by id fast?
BidData
means to avoid brute force scanning...