Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Sparse Arrays

Name: Anonymous 2011-12-23 0:08

Alright /proglodites/, let's hear how all of you implement a sparse arrays that stores two-dimensional data.

Name: Anonymous 2011-12-24 13:57

Radix trees are a good way to do this.

Assuming you want each cell in the grid to be indexable by two integers denoting the x and y positions, you can concatenate the bitstrings of the x and y locations and use that as the lookup key in a big radix tree. Each node in the radix tree holds an array of 2n pointers, where n is the number of bits to use as a lookup at each node. Anytime you come across a null pointer, you return the default value. This would allow dynamic use of memory and logarithmic lookups as opposed to linear ones.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List