Comments (2)
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 whetherT
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>
- Duplicates are not allowed:
- Yes: Use some hash set from another library (but not
- No. Do you want to access elements by index and/or the order is important?
- Yes:
array::array<T>
- No:
array::bag<T>
- Yes:
- Yes. Do you have a hash function for
-
… a mapping of
Key
toValue
.
Do you have a hash function forKey
?- 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>
- Duplicates are not allowed:
- Yes: Use some hash map from another library (but not
-
… 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>
.
- Yes: Repeat with
Block Storage Decision Tree
What do you know about the number of objects in the container?
- It is at most
N
whereN
is small enough that I can waste unused space:array::block_storage_embedded<N * sizeof(T)>
. - It is often
N
whereN
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 thearray::small_XXX
convenience aliases.
- Yes:
- 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.
- Yes:
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from array.