https://github.com/ahmed-gaper/sparse-array-and-matrix
The doubly-linked list-based SparseArray and SparseMatrix libraries optimize memory for sparse datasets by storing only non-zero elements in a doubly-linked list, significantly reducing storage compared to traditional arrays.
https://github.com/ahmed-gaper/sparse-array-and-matrix
doubly-linked-list memory-management operator-overloading template
Last synced: 11 months ago
JSON representation
The doubly-linked list-based SparseArray and SparseMatrix libraries optimize memory for sparse datasets by storing only non-zero elements in a doubly-linked list, significantly reducing storage compared to traditional arrays.
- Host: GitHub
- URL: https://github.com/ahmed-gaper/sparse-array-and-matrix
- Owner: Ahmed-Gaper
- Created: 2025-02-12T03:12:26.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-02-12T04:38:36.000Z (11 months ago)
- Last Synced: 2025-02-12T05:25:51.352Z (11 months ago)
- Topics: doubly-linked-list, memory-management, operator-overloading, template
- Language: C++
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sparse-Array-and-Matrix
The DLL-based SparseArray and SparseMatrix optimize memory for sparse datasets by storing only non-zero elements in a doubly-linked list, significantly reducing storage compared to traditional arrays.

## Overview
This project provides two lightweight C++ libraries for handling sparse data efficiently:
- SparseArray: A one-dimensional array that only stores non-zero elements using a doubly linked list.
- SparseMatrix: A two-dimensional matrix implemented as a collection of SparseArray objects—each row is represented as a SparseArray—to reduce memory usage when the data is sparse.
## Features
- Memory Efficiency: Stores only non-zero values.
- Random Access: Supports element access and modification using get, set, and overloaded `operator[]`.
- Iterators: Provides a constant iterator to traverse non-zero elements.
- Robustness: Implements proper copy, assignment, and move semantics.
## Usage
1. Including the Libraries
Include the header files in your project:
```c++
#include "SparseArray.h"
#include "SparseMatrix.h"
```
2. Using SparseArray
Create a SparseArray, set non-zero values, and retrieve data:
```c++
/*--------------------------*/
int capacity = 1000;
SparseArray sparseArray(capacity);
sparseArray[10] = 5;
int value = sparseArray[10];
sparseArray[20] = 15;
/*--------------------------*/
int rows = 100;
int cols = 100;
SparseMatrix sparseMatrix(rows, cols);
sparseMatrix[5][5] = 42;
int matrixValue = sparseMatrix[5][5];
```