Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi key map searching/filtering with partial key

My question is akin to Data structure for partial multi-keys mapping?.

I have key-value pairs where the key is composed of three components (strings).

I am looking for a data structure the can efficiently perform search queries over keys, where the queries could be complete or partial specification the key (one or more components omitted). For example:

(x, y, z)
(x, *, *)
(*, y, *)
etc.

The unspecified part of the key can be either at the front, the middle or the end of the key.

My current implementation (a hash map which maps all possible partial keys to a set of values that match this partial key) is horribly slow when inserting, deleting and updating values.

like image 762
Werner de Groot Avatar asked Jul 14 '14 13:07

Werner de Groot


1 Answers

My current implementation (a hash map which maps all possible partial keys to a list of values that match this partial key) is horribly slow when inserting, deleting and updating values.

If you are actually using a list then that is almost certainly the issue as they are slow on deleting/updating/inserting may also be an issue depending on how you are doing it. You are better off using a set (unordered) or balanced binary search tree (ordered).

like image 101
Nuclearman Avatar answered Oct 07 '22 03:10

Nuclearman