Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Say I have a tree that I'd like to visualize with d3. Nodes have various attributes produced by the d3 library, attributes like an index and position variables. Now, I could add more attributes to each node such as color, depth in the tree, or a label representing which disconnected graph contains the node. These attributes can all be represented with an integer attached to each node, or I could have a few arrays and make each attribute a reference to an array element. Which is better?

I'm sure the answer depends pretty strongly on the context, but it seems like we can split this into visualizations with a lot of nodes or visualizations with relatively few nodes. Keeping in mind the fact that a visualization may need to access or modify these attributes quite often, is this simply a trade-off between memory savings and array index operations? If I implement these two schemes in real code, how should I characterize the performance of each method?

share|improve this question
    
It's likely that the reference is larger than the integer element you're pointing it to –  Robert Harvey Aug 12 at 5:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.