mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.1 SparseArray
This commit is contained in:
parent
b40ad81a76
commit
afa34b1215
@ -1,3 +1,18 @@
|
|||||||
|
platforms:
|
||||||
|
rpipico:
|
||||||
|
board: rp2040:rp2040:rpipico
|
||||||
|
package: rp2040:rp2040
|
||||||
|
gcc:
|
||||||
|
features:
|
||||||
|
defines:
|
||||||
|
- ARDUINO_ARCH_RP2040
|
||||||
|
warnings:
|
||||||
|
flags:
|
||||||
|
|
||||||
|
packages:
|
||||||
|
rp2040:rp2040:
|
||||||
|
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
|
||||||
|
|
||||||
compile:
|
compile:
|
||||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||||
platforms:
|
platforms:
|
||||||
@ -9,5 +24,6 @@ compile:
|
|||||||
- esp32
|
- esp32
|
||||||
- esp8266
|
- esp8266
|
||||||
# - mega2560
|
# - mega2560
|
||||||
|
- rpipico
|
||||||
libraries:
|
libraries:
|
||||||
- "SHT85"
|
- "SHT85"
|
17
libraries/SparseArray/CHANGELOG.md
Normal file
17
libraries/SparseArray/CHANGELOG.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Change Log sparseArray
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||||
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
|
||||||
|
## [0.1.1] - 2022-11-25
|
||||||
|
- Add RP2040 support to build-CI.
|
||||||
|
- Add CHANGELOG.md
|
||||||
|
- update readme.md
|
||||||
|
|
||||||
|
|
||||||
|
## [0.1.0] - 2022-07-17
|
||||||
|
- initial version, derives from SparseMatrix
|
||||||
|
|
@ -11,22 +11,20 @@
|
|||||||
Arduino library for sparse arrays of floats.
|
Arduino library for sparse arrays of floats.
|
||||||
|
|
||||||
|
|
||||||
TODO REDO DOCUMENTATION.
|
|
||||||
|
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
SparseArray is an **experimental** library to implement a one
|
SparseArray is an **experimental** library to implement a one
|
||||||
dimensional sparse array of floats (a.k.a. vector) on an Arduino.
|
dimensional sparse array of floats (a.k.a. vector) on an Arduino.
|
||||||
A sparse array is a mn array with mostly zeros and a low percentage
|
A sparse array is an array with mostly zeros and a low percentage
|
||||||
non-zero values.
|
non-zero values.
|
||||||
The purpose of this library is efficient storage in memory.
|
The purpose of this library is efficient storage in memory.
|
||||||
|
|
||||||
The maximum array that can be represented is 65535 elements
|
The maximum array size this library can represent is 65535 elements
|
||||||
with a theoretical maximum of 65535 non-zero elements.
|
with a theoretical maximum of 65535 non-zero elements.
|
||||||
(although that does not make sense due to overhead)
|
(although that does not make sense due to overhead)
|
||||||
In practice the library limits this to 1000 non-zero elements.
|
In practice the library limits the number of non-zero elements to 1000.
|
||||||
Note: 255 elements would still fit in an UNO's 2K memory.
|
|
||||||
|
Note: 255 non-zero elements would fit in an UNO's 2K memory.
|
||||||
|
|
||||||
Relates to:
|
Relates to:
|
||||||
- https://github.com/RobTillaart/SparseMatrix
|
- https://github.com/RobTillaart/SparseMatrix
|
||||||
@ -37,15 +35,17 @@ Note: this library is derived from SparseMatrix.
|
|||||||
|
|
||||||
#### Implementation
|
#### Implementation
|
||||||
|
|
||||||
The implementation is based on 2 arrays holding ``` x, value```
|
The implementation is based on 2 arrays holding ```x, value```
|
||||||
where value is float, and x is an uint16_t.
|
where value is float, and x is an uint16_t.
|
||||||
That are 6 bytes per element.
|
That are 6 bytes per element.
|
||||||
The number of elements that the sparse array object can hold are
|
The number of elements that the sparse array object can hold is
|
||||||
given as parameter to the constructor.
|
given as parameter to the constructor.
|
||||||
If the space cannot be allocated the size is set to zero.
|
If the space cannot be allocated the size is set to zero.
|
||||||
|
|
||||||
In the future other data types should be possible.
|
In the future other data types should be possible.
|
||||||
|
|
||||||
|
Relates to https://github.com/RobTillaart/SET
|
||||||
|
|
||||||
|
|
||||||
#### Performance
|
#### Performance
|
||||||
|
|
||||||
@ -99,18 +99,29 @@ This can be useful for printing or processing the non zero elements.
|
|||||||
|
|
||||||
## Future
|
## Future
|
||||||
|
|
||||||
- documentation
|
#### must
|
||||||
- test
|
- improve documentation
|
||||||
|
|
||||||
|
#### should
|
||||||
|
- do test
|
||||||
|
- investigate optimizations
|
||||||
|
- derived sorted class ==> insertSort
|
||||||
- keep in sync with SparseMatrix where possible
|
- keep in sync with SparseMatrix where possible
|
||||||
- merge into one class hierarchy?
|
- merge into one class hierarchy?
|
||||||
|
- Template class for the data type
|
||||||
|
- better than SparseArray64 SparseArray32 SparseArray16 SparseArray8 (signed / unsigned?)
|
||||||
|
|
||||||
|
#### could
|
||||||
- dump should be in the class?
|
- dump should be in the class?
|
||||||
- or as static function...
|
- or as static function...
|
||||||
- stream as param dump(Stream str, ...
|
- stream as param dump(Stream str, ...
|
||||||
|
|
||||||
#### ideas
|
#### ideas
|
||||||
|
|
||||||
- array { uint32_t, float }; for logging millis/micros + measurement
|
- array { uint32_t, float }; for logging millis/micros + measurement
|
||||||
delta coding of time stamp? if it fit in 16 bit?
|
delta coding of time stamp? if it fit in 16 bit?
|
||||||
=> sounds like a class on its own.
|
=> sounds like a class on its own.
|
||||||
|
- investigate index \[\] operator for **get()** and **set()**
|
||||||
|
- would break with sparse matrix
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,15 +1,10 @@
|
|||||||
//
|
//
|
||||||
// FILE: SparseArray.cpp
|
// FILE: SparseArray.cpp
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.0
|
// VERSION: 0.1.1
|
||||||
// DATE: 2022-07-17
|
// DATE: 2022-07-17
|
||||||
// PURPOSE: Arduino library for sparse arrays of floats
|
// PURPOSE: Arduino library for sparse arrays of floats
|
||||||
// URL: https://github.com/RobTillaart/SparseArray
|
// URL: https://github.com/RobTillaart/SparseArray
|
||||||
//
|
|
||||||
// HISTORY:
|
|
||||||
// 0.1.0 2022-07-17 initial version
|
|
||||||
// derives from SparseMatrix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "SparseArray.h"
|
#include "SparseArray.h"
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
//
|
//
|
||||||
// FILE: SparseArray.h
|
// FILE: SparseArray.h
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.0
|
// VERSION: 0.1.1
|
||||||
// DATE: 2022-07-17
|
// DATE: 2022-07-17
|
||||||
// PURPOSE: Arduino library for sparse arrays of floats
|
// PURPOSE: Arduino library for sparse arrays of floats
|
||||||
// URL: https://github.com/RobTillaart/SparseArray
|
// URL: https://github.com/RobTillaart/SparseArray
|
||||||
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#define SPARSEARRAY_LIB_VERSION (F("0.1.0"))
|
#define SPARSEARRAY_LIB_VERSION (F("0.1.1"))
|
||||||
|
|
||||||
#ifndef SPARSEARRAY_MAX_SIZE
|
#ifndef SPARSEARRAY_MAX_SIZE
|
||||||
#define SPARSEARRAY_MAX_SIZE 1000
|
#define SPARSEARRAY_MAX_SIZE 1000
|
||||||
@ -31,9 +31,8 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
// returns false if no slots free
|
// returns false if no slots free
|
||||||
// could return # free slots?
|
|
||||||
bool set(uint16_t x, float value);
|
bool set(uint16_t x, float value);
|
||||||
// adds value to element x,y
|
// adds value to element x
|
||||||
bool add(uint16_t x, float value);
|
bool add(uint16_t x, float value);
|
||||||
float get(uint16_t x);
|
float get(uint16_t x);
|
||||||
|
|
||||||
@ -42,18 +41,18 @@ public:
|
|||||||
void boundingSegment(uint16_t &minX, uint16_t &maxX);
|
void boundingSegment(uint16_t &minX, uint16_t &maxX);
|
||||||
|
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
uint16_t _size = 0;
|
uint16_t _size = 0;
|
||||||
uint16_t _count = 0;
|
uint16_t _count = 0;
|
||||||
|
|
||||||
uint16_t *_x = NULL; // support array's [0..65535]
|
uint16_t *_x = NULL; // support array's [0..65535]
|
||||||
float *_value = NULL;
|
float *_value = NULL;
|
||||||
|
|
||||||
// returns index of x, y if in set
|
// returns index of x if in set
|
||||||
// otherwise -1
|
// otherwise -1
|
||||||
int32_t findPos(uint16_t x);
|
int32_t findPos(uint16_t x);
|
||||||
|
|
||||||
// removes element at pos (from findPos)
|
// removes element at position (from findPos)
|
||||||
// pre: count > 0
|
// pre: count > 0
|
||||||
void removeElement(uint16_t pos);
|
void removeElement(uint16_t pos);
|
||||||
// creates a new element if value != 0 and if there is room
|
// creates a new element if value != 0 and if there is room
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/RobTillaart/SparseArray.git"
|
"url": "https://github.com/RobTillaart/SparseArray.git"
|
||||||
},
|
},
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "*",
|
"platforms": "*",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=SparseArray
|
name=SparseArray
|
||||||
version=0.1.0
|
version=0.1.1
|
||||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
sentence=Arduino library for sparse arrays of floats.
|
sentence=Arduino library for sparse arrays of floats.
|
||||||
|
Loading…
Reference in New Issue
Block a user