Skip to main content
8 events
when toggle format what by license comment
Aug 12, 2014 at 22:36 vote accept Joney
Aug 12, 2014 at 18:28 comment added Joney Hmm. OK. Thanks for the response, really appreciated - I will ponder on this
Aug 12, 2014 at 18:14 comment added Robert Harvey 1. It depends on how you implement your insert method. You might only manipulate pointers. 2. The data structure should manage memory. 3. Yes, you've got the right idea. Passing a function is one way to keep the tree generalized so that it will work for any struct.
Aug 12, 2014 at 18:09 comment added Joney Thanks for that. Three follow-up questions: (1) doesn't this result in the element's data being copied into the list ? (2) Is it good practice to have the datastrucutre itself take ownership of managing the memory? (3) For something like a btree, I'm still forced to consider either passing a function that either compares elements, or extracts a key from them vs passing a separate key
Aug 12, 2014 at 17:55 comment added Robert Harvey Have a look at a sample implementation, like this one, especially the insert and remove methods. Your user should be able to hand a pointer to the data structure (or an insertion point to the data structure) and a partially filled out struct instance. The method should fix up the pointers.
Aug 12, 2014 at 17:54 comment added Joney I just don't know how to make an objective judgment on which design choice to go with .. they all seem like they have pros & cons. None appear to be "the best"
Aug 12, 2014 at 17:50 comment added Joney Yes, but what should these methods accept? A void pointer to data and a pointer to a comparison function (or in a hash, a to_key function)? Should I pass the key separately? Having a user retain a reference to the data and externally altering it while it's in the datastructure (thus potentially destroying the ds) seems about equally likely as them externally altering a pointer in a node type
Aug 12, 2014 at 17:24 history answered Robert Harvey CC BY-SA 3.0