Thread: Regular use, infrequent insert standard library (SL) container(s)

  1. #1
    Registered User
    Join Date
    Mar 2016
    Posts
    203

    Regular use, infrequent insert standard library (SL) container(s)

    What would be suitable SL container(s) for frequent search, sort etc but infrequent insertions after it has once been initialized? The container(s) would hold unique, custom objects and I'd like to understand the principles behind any recommendation as well. Thanks
    ps: google not very helpful: Google

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    There's not a lot of choice.

    A sorted vector (or array) that you binary search, giving logarithmic time for access.

    A set (or map), which are implemented as red-black trees (or something similar), giving logarithmic time for access.

    If you didn't need sorting, then an unordered_set (or unordered_map), which are implemented as hash tables, giving constant time for access.

    If you give the details of your object and how often you insert after initialization then someone might be able to suggest a more specialized data structure.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    [QUOTE]ps: google not very helpful: Google

    Then perhaps you need to change your search parameters? Remember that if one "search" doesn't produce the desired results you need to refine your search parameters. Perhaps something like C++ selecting proper container might produce better results.

    Jim

  4. #4
    Registered User
    Join Date
    Mar 2016
    Posts
    203
    algorism: thanks for your reply
    the objects will be stocks (perhaps, later, other financial securities) where each stock object has a unique securities number. there is no requirement for sorting the original container but we'll be running screens on this container, selecting stocks on the basis of various criteria and the selected stocks (much smaller in number than the original
    container size) will need sorting within their own containers but that's another issue.
    Insertions (and deletions) would normally happen quarterly when equity indices usually rebalance unless there's interim corporate events like an IPO (an insertion), takeover/merger (a deletion) etc.
    Another thing I should mention is that sizeof(object) will probably be quite large as it'll have a several data members representing underlying company fundamentals, behavior of its stock price, daily trading volumes, etc but this should not have any effect upon the choice of the container per se? From your list I think the unordered containers might be more up my street
    jim: i posted one of my searches' link but admittedly you defined the search terms better. further down in your link there's a C++11 version of the container cheat-sheet that also seems to point out the unordered containers for this exercise. Thanks

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by sean_cantab
    Insertions (and deletions) would normally happen quarterly (...) Another thing I should mention is that sizeof(object) will probably be quite large as it'll have a several data members representing underlying company fundamentals
    If by "quarterly" you mean the equivalent of "every designated three months in a year", then it sounds like you're looking for a persistent database rather than an in-memory container, with in-memory containers used only after accessing the database to retrieve the relevant records (hence you will not have a huge number of large objects in-memory all at once).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Mar 2016
    Posts
    203
    hi laserlight: the stock selection screens can run directly upon the memory container but for deleting objects can we do it directly from the memory container (here I'm thinking primarily .txt files) or do we need to read entire memory container to an in-memory container first? for insertions, yes, they can be written directly to the memory container. thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 03-19-2017, 03:18 PM
  2. regular expression library questions
    By sandrews in forum C Programming
    Replies: 0
    Last Post: 01-25-2012, 12:57 PM
  3. how to insert data in a map container
    By roelof in forum C++ Programming
    Replies: 40
    Last Post: 06-13-2010, 12:34 AM
  4. Insert Items in Hash Table Container.
    By joenching in forum C++ Programming
    Replies: 18
    Last Post: 05-02-2005, 01:50 PM
  5. Regular Expression Library
    By ChadJohnson in forum C Programming
    Replies: 2
    Last Post: 09-24-2004, 12:38 PM

Tags for this Thread