0

I want to design/find a C++ Datastructure/Container which supports two column of data and CRUD operation on those data. I reviewed the STL Containers but none of them supports my requirement (correct me if I am wrong). My exact requirement is as follows

  1. Datastructure with Two Columns.
  2. Supports the following Functions

    1. Search for a Specific item.

    2. Search for a List of items matching a criteria

    3. Both the column should support the above mentioned Search Operation. ie., I should be able to search for a data on both the columns.

    4. Update a specific item

    5. Delete a specific item
    6. Add new item

I prefer search operation to be faster than add/delete operation.

In Addition I will be sharing this Data between Threads, hence need to support Mutex(I can also implement Mutex Lock on these data separately.)

Does any of the existing STL meets my requirement or do we have any other library or datastructure that fits best to my requirements.

Note: I cant use Database or SQLite to store my data.

Thank you Regards, Dinesh

Dinesh P.R.
  • 6,936
  • 6
  • 35
  • 44

3 Answers3

1

If one of the column is unique then probably you can use Map. Otherwise define a class with two member variables representing the column and store it in a vector. There are algorithms that will help you in searching the container.

Jeeva
  • 4,585
  • 2
  • 32
  • 56
1

Search for a Specific item.

If you need one-way mapping (i.e. fast search over values in one column), you should use map or multimap container classes. There is no, however, bidirectional map in standart library, so you should build your own as pair of (multi)maps or use other libraries, such as boost::bimap

permeakra
  • 612
  • 6
  • 12
1

Your best bet is Boost.Bimap, because it will make it easy for you when you want to search based on either column. If you decided that you need more columns, then Boost.Multi_index might be better. Here is an example!

Community
  • 1
  • 1
Khaled Alshaya
  • 94,250
  • 39
  • 176
  • 234