Development reference: Difference between revisions
No edit summary |
No edit summary |
||
Line 33: | Line 33: | ||
| Best solution is an unordered set of pointers: | | Best solution is an unordered set of pointers: | ||
typedef boost::unordered_set<MajorObject*> MajorObjects; | typedef boost::unordered_set<MajorObject*> MajorObjects; | ||
|} | |} | ||
Line 46: | Line 47: | ||
|- | |- | ||
| Use unordered_map with a custom object as key. You must add hash and equals functions. Boost makes it easy: | | Use unordered_map with a custom object as key. You must add hash and equals functions. Boost makes it easy: | ||
static bool operator==(MyKeyObject const& m1, MyKeyObject const& m2) | |||
{ | |||
return | |||
m1.id_0 == m2.id_0 | |||
&& m1.id_1 == m2.id_1; | |||
} | |||
static std::size_t hash_value(MyKeyObject const& mko) | |||
{ | |||
std::size_t seed = 0; | |||
boost::hash_combine(seed, mko.id_0); | |||
boost::hash_combine(seed, mko.id_1); | |||
return seed; | |||
} | |||
typedef boost::unordered_map<MyKeyObject, MyValueObject*> MyMap; | |||
Note that you can extend this to use a pointer to a key object, whoop. | |||
|} | |} | ||
Revision as of 17:25, 6 January 2014
Expandc++11 containers |
---|
Expandc++11 example for large groups of objects with frequent crud AND search |
---|
Expandc++11 example for large groups of objects with infrequent crud and frequent search |
---|
Expandc++11 example to associate two complex objects (one the map key, one the map value) |
---|
Expandc++11 example for multiple unordered_set indexes into one group of objects |
---|
Expandc++11 for loop using lambda |
---|
Expandc++ in-memory storage of "major" objects |
---|
Expandc++ stl reverse iterator skeleton |
---|
c++ stl reading a binary file |
---|
Expandc/c++ gdb debugging |
---|
ExpandCreate a portable command line C project in Visual Studio |
---|
ExpandCreate a portable C++ project in Visual Studio |
---|
Expandphp debugging |
---|
Expandjava eclipse project layout format |
---|
ExpandSQL Server 2008+ proper upsert using MERGE |
---|
Expandgit recreate repo |
---|
Expandbash chmod dirs |
---|
Web Services |
---|
Firefox Addon development |
---|
Expandmediawiki collapsible skeleton |
---|
Expandmediawiki collapsible example |
---|