0

I have a class ID_card of nickname, measure, and pub_key.

I have a storage, containing objects of ID_card.

Applications will search ID_card objects either via nickname, measure, or pub_key.

pub_key is a unique property. Hence, if storage=dict() then storage[pub_key] = object is a suitable key-value design.

If we suppose for simplicity that nickname and measure are also unique then is there maybe some python built-in type for storage such that all the following work:

  1. storage[pub_key] = object
  2. storage[nickname] = object
  3. storage[measure] = object

Ideally, for 2,3 the access to storage returns a list of all objects satisfying the nickname/measure.

  • This is many to one mapping I'd suggest checking out this question https://stackoverflow.com/questions/1921027/many-to-one-mapping-creating-equivalence-classes – Pioneer_11 Aug 04 '22 at 11:24
  • 1
    There is also the multi key dict module https://pypi.org/project/multi_key_dict/ though I'm unsure if it is implemented in C or python, if you're looking for performance then you would probably be better off having three dictionaries `nickname`, `measure` and `pub_key` where `pub_key`, `nickname` and `measure` all give the same reference to a which can then be plugged into a `reference_lookup` dictionary. This would be a fast and low memory approach but fairly verbose – Pioneer_11 Aug 04 '22 at 11:25
  • This is analogous to whether you have indexes on a column in a database. I think you basically have two options - either have a separate key-value mapping (i.e. dictionary) for each field (like having an index for each column in the table) or have a single storage, based on pub_key, and a search function to find items by the other two fields. – Anentropic Aug 04 '22 at 11:29
  • I'm not familiar enough with Pandas to give an answer, but it is a library for working with tabular data (i.e. the rows are your ID_card objects and the columns are the fields) that has an index feature https://pandas.pydata.org/docs/reference/api/pandas.Index.html and is built for good performance on large data sets – Anentropic Aug 04 '22 at 11:31

0 Answers0