Development reference: Difference between revisions
No edit summary |
No edit summary |
||
Line 60: | Line 60: | ||
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 /> | ||
The primary container can manage object allocation; using a heap-based unique_ptr allocation<br /> | The primary container can manage object allocation; using a heap-based unique_ptr allocation<br /> | ||
map vs key redux | |||
use a key in the set, derive a class from it with the contents | |||
+ small key | |||
+ encapsulation | |||
- requires mutable to solve the const problem | |||
use a key in the set, key includes a mutable object | |||
+ encapsulation | |||
- weird bc everything uses a const object but we have const functions like save() that change the mutable subobject | |||
use a map | |||
+ small key | |||
- no encapsulation, have to deal with a pair instead of an object | |||
can we just put a ref to key in the value? sure why not - err, bc we don't have access to it | |||
+ solves const problem bc value is totally mutable by design | |||
+ we can have multiple keys - and the value can have multiple refs to them | |||
+ simpler equal and hash functions | |||
map: | |||
create an object with internal key(s) | |||
create map index(es) with duplicate key values outside the object - dupe data is the downside | |||
use set(s) with one static key for find(): | |||
create an object with internal key(s) | |||
create set index(es) with specific hash/equals functor(s) | |||
when finding, use one static key object (even across indexes!) so there isn't a big construction each time; just set the necessary key values | |||
that proves difficult when dealing with member vars that are references | |||
but to solve it, just set up a structure of dummy static key objects that use each other; then provide a function to setKey(Object& keyref) { keyref_ = keyref; } | |||
nope, can't reassign refs | |||
the solution: use pointers not references | |||
yes that's right | |||
just do it | |||
apparently there was a reason i was anti-reference for all those years | |||
two reasons to use pointers: | |||
dynamically allocated | |||
reassignment required | |||
there ya go. simple. get it done. | |||
when accessing find results from the set, use a const_cast on the object! | |||
WARNING: a separate base class with the key sounds good... but fails when you have more than one index on the object. just use a static key object for them all! | |||
|} | |} | ||
Revision as of 04:56, 5 July 2015
Expandc++11 Model View Controller skeleton |
---|
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 loop through vector to erase some items |
---|
Expandc++11 range based for loop, jacked with boost index if needed |
---|
Expandc++11 for loop using lambda |
---|
Expandc++11 integer types |
---|
ExpandC++11 scoped enumeration |
---|
Expandc++ in-memory storage of "major" objects |
---|
Expandc++ stl reverse iterator skeleton |
---|
Expandc++ stl reading a binary file into a string |
---|
ExpandC/C++ best-in-class tool selection |
---|
Expandc/c++ gdb debugging |
---|
ExpandC - Create a portable command line C project in Visual Studio |
---|
Expandc++ Create a portable C++ project in Visual Studio |
---|
Expandboost build for both 32 and 64 bit Windows |
---|
Expandphp debugging |
---|
Expandeclipse settings |
---|
Expandeclipse java project layout format |
---|
Expandeclipse new project from existing code |
---|
Expandemacs configuration |
---|
ExpandSQL Server 2008+ proper upsert using MERGE |
---|
Expandgit use kdiff3 as difftool and mergetool |
---|
Expandgit create merge-to command |
---|
Expandgit shared repo |
---|
Expandgit create new branch on server, pull to client |
---|
Expandgit windows configure notepad++ editor |
---|
Expandgit pull when untracked files are in the way |
---|
Expandgit create new branch when untracked files are in the way |
---|
Expandgit fix push behavior - ONLY PUSH CURRENT doh |
---|
Expandgit recreate repo |
---|
Expandgit connect to origin after the fact |
---|
ExpandWindows command prompt FULL SCREEN |
---|
Expandbash chmod dirs |
---|
Web Services |
---|
Firefox Addon development |
---|
Expandmediawiki collapsible skeleton |
---|
Expandmediawiki collapsible example |
---|