Questions tagged [sparse-array]

In computer science, a sparse array is an array in which most of the elements have the same value (known as the default value—usually 0 or null).

In computer science, a sparse array is an array in which most of the elements have the same value (known as the default value—usually 0 or null).

The occurrence of zero elements in a large array is inefficient for both computation and storage. An array in which there is a large number of zero elements is referred to as being sparse.

In the case of sparse arrays, one can ask for a value from an "empty" array position. If one does this, then for an array of numbers, a value of zero should be returned, and for an array of objects, a value of null should be returned.

A naive implementation of an array may allocate space for the entire array, but in the case where there are few non-default values, this implementation is inefficient. Typically the algorithm used instead of an ordinary array is determined by other known features (or statistical features) of the array. For instance, if the sparsity is known in advance or if the elements are arranged according to some function (e.g., the elements occur in blocks). A heap memory allocator in a program might choose to store regions of blank space in a linked list rather than storing all of the allocated regions in, say a bit array.

Wikipedia: http://en.wikipedia.org/wiki/Sparse_array

94 questions
0
votes
2 answers

How to make (and save in RAM) sparsearray at app launch? (android)

I am making an android app. There is an activity in the app, which when triggered, makes a sparsearray and fills it with data. Now this process takes upto 1 minute on the emulator, which is very long. So I want to make that sparsearray once, right…
Tom Wong
  • 31
  • 1
  • 1
  • 4
0
votes
3 answers

How can I get the number of elements in a sparse array in Actionscript?

Actionscript uses sparse arrays, so I can have an array like this: var myArray:Array = new Array(); myArray[0] = "foo"; myArray[22] = "bar"; Now myArray.length will give me 23. Is there a way to get the actual number of items in the array without…
Robert
  • 6,660
  • 5
  • 39
  • 62
0
votes
1 answer

Storing functions in a sparse array with Python

I have a relatively large enum wherein each member represents a message type. A client will receive a message containing the integer value associated with the msg type in the enum. For each msg type there will be an individual function callback to…
Graeme
  • 4,514
  • 5
  • 43
  • 71
0
votes
1 answer

thread-safe cache for sparse, lazy, immutable arrays

I have an application that involves a collection of arrays which can be very large (indices up to the maximum value of an int), but which are lazy - their contents are calculated on the fly and are not actually known until requested. The arrays are…
gcbenison
  • 11,723
  • 4
  • 44
  • 82
1 2 3 4 5 6
7