Giter Club home page Giter Club logo

Comments (2)

foonathan avatar foonathan commented on June 1, 2024

Something like this?

In case you don't know what to use.
The container decision tree helps you pick a container,
the block storage decision tree helps you pick a block storage.

Container Decision Tree

When in doubt, use std::vector.

The problem with that approach:
In this library, all containers are std::vector!

You want to store:

  • … just some objects of type T.
    Do you want often need to check whether T is already present or look it up based on a member?

    • Yes. Do you have a hash function for T?
      • Yes: Use some hash set from another library (but not std::unordered_(multi)set).
      • No:
        • Duplicates are not allowed: array::flat_set<T>
        • Duplicates are allowed: array::flat_multiset<T>
    • No. Do you want to access elements by index and/or the order is important?
      • Yes: array::array<T>
      • No: array::bag<T>
  • … a mapping of Key to Value.
    Do you have a hash function for Key?

    • Yes: Use some hash map from another library (but not std::unordered_(multi)map).
    • No:
      • Duplicates are not allowed: array::flat_map<Key, Value>
      • Duplicates are allowed: array::flat_multimap<Key, Value>
  • … a variant of T1, T2, …, Tn.
    Do you want to access elements by index and/or the order is important?

    • Yes: Repeat with T = std::variant<T1, T2, …, Tn>.
    • No: array::variant_bag<BlockStorage, T1, T2, …, Tn>.

Block Storage Decision Tree

What do you know about the number of objects in the container?

  • It is at most N where N is small enough that I can waste unused space: array::block_storage_embedded<N * sizeof(T)>.
  • It is often N where N is small (single digit) but sometimes larger.
    Do you have a custom allocator?
    • Yes: array::block_storage_heap_sbo<N * sizeof(T), MyCustomAllocator>
    • No: array::block_storage_heap_sbo<N * sizeof(T)>.
      You can also use the array::small_XXX convenience aliases.
  • I don't know anything.
    Do you have a custom allocator?
    • Yes: array::block_storage_heap<MyCustomAllocator>.
    • No: array::block_storage_default or just ignore the template parameter all together.

If you care about growth factors:
Look at the defaulted template parameters in the block storage.

If you have a fancy allocator that can decide the growth factors by itself:
Implement your own BlockStorage.

from array.

Manu343726 avatar Manu343726 commented on June 1, 2024

That looks great. I would also mention views, or at least directly reference what views you take from each container

from array.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.