mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.3.3 DistanceTable
This commit is contained in:
parent
f6dbdb9143
commit
67b03021cc
@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.3.3] - 2023-09-25
|
||||
- update changelog
|
||||
- update readme.md
|
||||
|
||||
|
||||
## [0.3.2] - 2022-11.02
|
||||
- add changelog.md
|
||||
- add rp2040 to build-CI
|
||||
@ -56,15 +61,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
## [0.1.3] - 2017-07-27
|
||||
- Fix issue #33
|
||||
|
||||
## [0.1.2]
|
||||
## [0.1.2] - 2017-07-15
|
||||
- fix overflow
|
||||
- add some error detection
|
||||
- revert float to float to memory
|
||||
|
||||
## [0.1.01]
|
||||
## [0.1.01] - 2015-06-19
|
||||
- refactor
|
||||
|
||||
## [0.1.00]
|
||||
## [0.1.00] - 2015-06-18
|
||||
- initial version
|
||||
|
||||
|
||||
|
@ -1,11 +1,9 @@
|
||||
//
|
||||
// FILE: DistanceTable.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.2
|
||||
// VERSION: 0.3.3
|
||||
// PURPOSE: Arduino library to store a symmetrical distance table in less memory
|
||||
// URL: https://github.com/RobTillaart/DistanceTable
|
||||
//
|
||||
// HISTORY: see changelog.md
|
||||
|
||||
|
||||
#include "DistanceTable.h"
|
||||
@ -53,7 +51,7 @@ void DistanceTable::setAll(float value)
|
||||
|
||||
bool DistanceTable::set(uint8_t x, uint8_t y, float value )
|
||||
{
|
||||
// comment next line to skip range check (squeeze performance)
|
||||
// comment next line to skip range check (squeeze performance)
|
||||
if ( (x >= _dimension) || (y >= _dimension)) return false;
|
||||
if (x == y) return (value == 0.0);
|
||||
|
||||
@ -62,7 +60,7 @@ bool DistanceTable::set(uint8_t x, uint8_t y, float value )
|
||||
uint8_t t = x; x = y; y = t; // swap
|
||||
if (_invert) value = -value;
|
||||
}
|
||||
// prevent overflow by moving to 16 bit
|
||||
// prevent overflow by moving to 16 bit
|
||||
uint16_t index = x;
|
||||
index = (index * (index - 1)) / 2 + y;
|
||||
_distanceTable[index] = value;
|
||||
@ -72,7 +70,7 @@ bool DistanceTable::set(uint8_t x, uint8_t y, float value )
|
||||
|
||||
float DistanceTable::get (uint8_t x, uint8_t y)
|
||||
{
|
||||
// comment next line to skip range check (squeeze performance)
|
||||
// comment next line to skip range check (squeeze performance)
|
||||
if ( (x >= _dimension) || (y >= _dimension)) return -1; // NAN ?
|
||||
if ( x == y ) return 0.0;
|
||||
|
||||
@ -90,7 +88,7 @@ float DistanceTable::get (uint8_t x, uint8_t y)
|
||||
};
|
||||
|
||||
|
||||
// triangular dump
|
||||
// triangular dump
|
||||
void DistanceTable::dump(Print * stream)
|
||||
{
|
||||
stream->println();
|
||||
@ -204,7 +202,7 @@ uint16_t DistanceTable::count(float value, float epsilon)
|
||||
}
|
||||
}
|
||||
if (_invert) return cnt;
|
||||
return cnt * 2; // count the symmetrical elements too.
|
||||
return cnt * 2; // count the symmetrical elements too.
|
||||
}
|
||||
|
||||
|
||||
@ -238,9 +236,9 @@ uint16_t DistanceTable::countBelow(float value)
|
||||
}
|
||||
}
|
||||
if (_invert) return cnt;
|
||||
return cnt * 2; // count the symmetrical elements too.
|
||||
return cnt * 2; // count the symmetrical elements too.
|
||||
}
|
||||
|
||||
|
||||
// --- END OF FILE ---
|
||||
// --- END OF FILE ---
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: DistanceTable.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.2
|
||||
// VERSION: 0.3.3
|
||||
// PURPOSE: Arduino library to store a symmetrical distance table in less memory
|
||||
// URL: https://github.com/RobTillaart/DistanceTable
|
||||
//
|
||||
@ -11,7 +11,7 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#define DISTANCETABLE_LIB_VERSION (F("0.3.2"))
|
||||
#define DISTANCETABLE_LIB_VERSION (F("0.3.3"))
|
||||
|
||||
|
||||
class DistanceTable
|
||||
@ -66,5 +66,5 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
// --- END OF FILE ---
|
||||
// --- END OF FILE ---
|
||||
|
||||
|
@ -15,9 +15,9 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/DistanceTable"
|
||||
},
|
||||
"version": "0.3.2",
|
||||
"version": "0.3.3",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
"headers": "DistanceTable.h"
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
name=DistanceTable
|
||||
version=0.3.2
|
||||
version=0.3.3
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library for a memory efficient DistanceTable for Arduino.
|
||||
paragraph=
|
||||
sentence=Library for a memory efficient DistanceTable for Arduino.
|
||||
paragraph=
|
||||
category=Data Processing
|
||||
url=https://github.com/RobTillaart/DistanceTable
|
||||
architectures=*
|
||||
|
@ -1,9 +1,12 @@
|
||||
|
||||
[![Arduino CI](https://github.com/RobTillaart/Distancetable/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino CI](https://github.com/RobTillaart/DistanceTable/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/DistanceTable/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/DistanceTable/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/DistanceTable/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/DistanceTable/actions/workflows/jsoncheck.yml)
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/Distancetable/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/Distancetable.svg?maxAge=3600)](https://github.com/RobTillaart/Distancetable/releases)
|
||||
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/DistanceTable.svg)](https://github.com/RobTillaart/DistanceTable/issues)
|
||||
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/DistanceTable/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/DistanceTable.svg?maxAge=3600)](https://github.com/RobTillaart/DistanceTable/releases)
|
||||
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/DistanceTable.svg)](https://registry.platformio.org/libraries/robtillaart/DistanceTable)
|
||||
|
||||
|
||||
# DistanceTable
|
||||
@ -25,9 +28,11 @@ Within the 2K RAM of an Arduino one could store normally a 21 x 21 matrix (1764
|
||||
The class therefore saves around 50% of RAM.
|
||||
The price is performance as it takes more time to access the elements.
|
||||
|
||||
Relates to:
|
||||
- https://github.com/RobTillaart/SparseArray
|
||||
- https://github.com/RobTillaart/SparseMatrix
|
||||
#### Related
|
||||
|
||||
- https://github.com/RobTillaart/SparseArray
|
||||
- https://github.com/RobTillaart/SparseMatrix
|
||||
- https://www.codeproject.com/Tips/5368686/From-Linear-to-Upper-Triangular-Matrix-Indices
|
||||
|
||||
|
||||
## Interface
|
||||
@ -41,7 +46,7 @@ Relates to:
|
||||
- **DistanceTable(uint8_t size, float value = 0.0)** Constructor, allocates memory and
|
||||
sets initial value to all elements.
|
||||
If memory cannot be allocated, the size will be set to 0.
|
||||
- **~DistanceTable();** Destructor, frees allocated memory.
|
||||
- **~DistanceTable()** Destructor, frees allocated memory.
|
||||
- **void clear()** sets all entries to 0.0.
|
||||
- **void setAll(float value)** sets all entries to value.
|
||||
- **bool set(uint8_t x, uint8_t y, float value )** sets a value for (x,y) and automatically for (y, x).
|
||||
@ -92,12 +97,12 @@ functions need to test it.
|
||||
In practice this means slower, especially when the flag is set to true.
|
||||
|
||||
Some application thoughts:
|
||||
- difference in height
|
||||
- energy levels e.g. transitions of electrons, other physics
|
||||
- transactions between players of a game
|
||||
- difference in height between points on a route or map.
|
||||
- energy levels e.g. transitions of electrons, other physics phenomena.
|
||||
- transactions between players of a game, + for one is - for the other.
|
||||
- hold a 2D colour space
|
||||
|
||||
Note: this function is not tested extensively.
|
||||
Note: this functionality is not tested extensively.
|
||||
|
||||
|
||||
### Debug
|
||||
@ -117,24 +122,32 @@ See examples.
|
||||
|
||||
## Future
|
||||
|
||||
#### Must
|
||||
|
||||
- improve documentation
|
||||
|
||||
|
||||
#### Should
|
||||
|
||||
- improve unit tests
|
||||
- rethink class hierarchy (see ideas below).
|
||||
|
||||
|
||||
#### Could
|
||||
|
||||
- add examples
|
||||
- Note: table can be used for other symmetrical 2D tables.
|
||||
- And therefore include negative values
|
||||
- investigate behaviour of **count()** functions a bit more.
|
||||
- include diagonal?
|
||||
|
||||
|
||||
#### derived or related classes
|
||||
|
||||
- int64_t int32_t int16_t int8_t + unsigned variants? (8 variations? invert flag)
|
||||
- Template class? (release 0.4.0 ?)
|
||||
- should the "non-inverted" distance table be a derived (performant) class?
|
||||
- could the "non-inverted" distance table be a derived or base class?
|
||||
- more performant
|
||||
- diagonal not zero class,
|
||||
- uses a more bytes but allows also extra functionality while staying symmetrical.
|
||||
|
||||
|
||||
- uses more bytes but allows also extra functionality while staying symmetrical.
|
||||
- what if dimension(x) = 2x dimension(y) - non square tables.
|
||||
- is there a spectrum of sparsity of a matrix?
|
||||
- int64_t int32_t int16_t int8_t + unsigned variants? (8 variations? invert flag)
|
||||
- Template class? (release 0.4.0 ?)
|
||||
|
||||
#### won't
|
||||
|
||||
@ -143,3 +156,12 @@ See examples.
|
||||
- Hamilton paths?
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
If you appreciate my libraries, you can support the development and maintenance.
|
||||
Improve the quality of the libraries by providing issues and Pull Requests, or
|
||||
donate through PayPal or GitHub sponsors.
|
||||
|
||||
Thank you,
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user