Development reference: Difference between revisions
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
! c++11 containers | ! c++11 containers | ||
|- | |- | ||
| sorted_vector || use when doing lots of unsorted insertions and maintaining constant sort would be expensive | | sorted_vector || use when doing lots of unsorted insertions and maintaining constant sort would be expensive; NOTHING beats vector for that | ||
|- | |- | ||
| map || sorted binary search tree; always sorted by key; you can walk through in sorted order (choose unordered if not needed!) | | map || sorted binary search tree; always sorted by key; you can walk through in sorted order (choose unordered if not needed!) | ||
Line 25: | Line 25: | ||
to reference the same group of objects with different sort funtors to create multiple indices.<br /> | to reference the same group of objects with different sort funtors to create multiple indices.<br /> | ||
You just have to manage the keys carefully, so that they don't change (which would invalidate the sorting).<br /> | You just have to manage the keys carefully, so that they don't change (which would invalidate the sorting).<br /> | ||
TODO: develop a sort-on-demand unordered set of pointers that allow changing the key, with b_sort_ tracking? | TODO: develop a sort-on-demand unordered set of pointers that allow changing the key, with b_sort_ tracking for when key changes or new items added? | ||
|} | |} | ||
Line 69: | Line 69: | ||
| Objects will be dynamically created. One set should include them all and be responsible for memory allocation cleanup: | | Objects will be dynamically created. One set should include them all and be responsible for memory allocation cleanup: | ||
TODO | TODO | ||
|} | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! c++11 example for set with specific sorting | |||
|- | |||
| Use set with a specific sort functor. You can create as many of these indexes as you want! | |||
struct customers_set_sort_functor | |||
{ | |||
bool operator()(const MyObject* l, const MyObject* r) const | |||
{ | |||
// the id is the key | |||
return l->id_ < r->id_; | |||
} | |||
}; | |||
typedef set<MyObject*,myobject_sort_by_id_functor> MyObjectsById; | |||
|} | |} | ||
Revision as of 18:44, 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 example for set with specific sorting |
---|
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 |
---|