I was rejected because of not optimize solution (performance is not good). Hence each operator (lookup, evict and lookup, excluding the db access) will take O(logn) instead of O(1).
Update of the rank, (lookup and removal of the rank entry in the binary tree O(1), and insert is O(logn). The binary tree lookup (O(1) since the hash_map has the iterator db access time dominate the O(logn) hence this logn (to insert into the priority queue,(or pop and insert into the priority) does not matter the look up (with const rank) O(logn) + db access time. The rest of the process is the same as lookup as described below. from that min value item (the rank and the entry), the entry is looked up into the hash_set, and hence removed from there too. On limit reached, the tree is searched for min value. On look up, the entry into the set(of rank) is looked up (O(1)) and then erased, and then insert back after recaulated rank value.The iterator inrto the hash_set is also updated with this new iterator.
I used iterator to avoid look up for entry into the set during each entry lookup in the hashset. My proposal was: create an associated binary tree(std::set) with the hashmap (map of entry as key, and the iterator entry in the std::set of entries). I propose change in the associated ds for hashset, Value to be modified, and only provide access to top entry. Since the priority queue does not provide the key(hash key) insert pair(get_entry_rank(entry), entry) for any entry added, the function int getEntryRank(entry) will return its rank which will not change on lookupĮntry e = db_read_entry() // expensive op The entries are evicted based on the rank. I was asked this question for the above role:Ĭreate a fixed size cache which is fully associative. | Report Duplicate | Flag | PURGE Amazon Principal Software Engineer Computer Architecture & Low Level clients being aware of available servers & makes smart routing based on that available information. Support for Multiple nodes and each node is independent & self-sufficient. Highly scalable - Support for high throughput with very low latency free_food when defined takes type = boolean, hence, any key when using the attribute - free_food must allow only boolean values on subsequent inserts/updates) Once data type is associated with a particular attribute, it cannot be changed. data type of pollution_level is set when key = delhi is inserted)ģ. Data type of the attribute is defined at the first insert.
Attribute is uniquely identified by its name (latitude, longitude etc.Ģ. So, in a nutshell, value must be strongly typed when defined.ġ. Get all keys (cities) where pollution_level is high. Key can have a value consisting of multiple attributes.Įach attribute will have name, type associated (primitive types - boolean, double, integer, string) & type has to be identified at run time.ġ) Key = delhi has 2 attributes ( pollution_level & population)Ģ) Key = jakarta has 3 attributes (latitude, longitude, pollution_level)ģ) Key = bangalore has 4 attributes (extra - free_food)Ĥ) Key = india has 2 attributes (capital & population)ĥ) Key = crocin has 2 attributes (category & manufacturer) Perform a secondary index scan to fetch all key along with their attributes where one of the attribute values is v. Store a set of attributes (value) against a particular key (k)įetch the value stored against a particular key (k) Design a distributed key-value store that can perform the following