sparsearray2d

Creator: coderz1093

Last updated:

0 purchases

sparsearray2d Image
sparsearray2d Images

Languages

Categories

Add to Cart

Description:

sparsearray2d

A fast and flexible generic sparse 2 dimensional array.
Features #

Exposes graph such that clients may easily walk directly between neighbouring elements to allow fast array traversal.
Easy conversion between dense and sparse formats.

Usage #
Example:
final sparse = SparseArray2D<String>();

sparse.put(2, 0, 'a');
sparse.put(2, 1, 'b');
sparse.put(2, 5, 'c');
sparse.put(2, 8, 'd');
sparse.put(0, 5, 'e');

print('Sparse form elements');
print(sparse.sparseRows.join('\n'));

print('Dense form values');
print(sparse.denseRows.join('\n'));

print('Dense form with default value "_"');
print(sparse.denseRows.map((final row) => row.padded('-')).join('\n'));

print('Extract row as sparse elements');
print(sparse.sparseRowAt(2));

print('Extract row as sparse values with default value "*"');
print(sparse.sparseRowAt(2)!.dense.padded('*'));

print('Extract column as sparse elements');
print(sparse.sparseColumnAt(5)!.join('\n'));

print('Extract column as sparse values with default value "*"');
print(sparse.sparseColumnAt(5)!.dense.padded('*').join('\n'));

copied to clipboard
Output:
Sparse form elements
(0)[(0, 5)[e]]
(2)[(2, 0)[a],(2, 1)[b],(2, 5)[c],(2, 8)[d]]

Dense form values
(null, null, null, null, null, e, null, null, null)
(null, null, null, null, null, null, null, null, null)
(a, b, null, null, null, c, null, null, d)

Dense form with default value "_"
(-, -, -, -, -, e, -, -, -)
(-, -, -, -, -, -, -, -, -)
(a, b, -, -, -, c, -, -, d)

Extract row as sparse elements
(2)[(2, 0)[a],(2, 1)[b],(2, 5)[c],(2, 8)[d]]

Extract row as sparse values with default value "*"
(a, b, *, *, *, c, *, *, d)

Extract column as sparse elements
(0, 5)[e]
(2, 5)[c]

Extract column as sparse values with default value "*"
e
*
c
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.