0.2.2 DistanceTable

This commit is contained in:
rob tillaart 2021-12-17 10:50:55 +01:00
parent 0c0e711fc0
commit 883fcaada3
9 changed files with 47 additions and 30 deletions

View File

@ -167,3 +167,4 @@ uint16_t DistanceTable::count(float value, float epsilon)
// --- END OF FILE ---

View File

@ -2,7 +2,7 @@
//
// FILE: DistanceTable.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.1
// VERSION: 0.2.2
// 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.2.1"))
#define DISTANCETABLE_LIB_VERSION (F("0.2.2"))
class DistanceTable
@ -57,3 +57,4 @@ protected:
// --- END OF FILE ---

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2015-2021 Rob Tillaart
Copyright (c) 2015-2022 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,7 +1,6 @@
//
// FILE: distanceTable.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo of memory efficient distance table class
// DATE: 2015-06-18
// URL: https://github.com/RobTillaart/DistanceTable
@ -135,4 +134,5 @@ void loop()
{
}
// -- END OF FILE --

View File

@ -1,7 +1,7 @@
# Syntax Coloring Map For DistanceTable
# Syntax Colouring Map For DistanceTable
# Datatypes (KEYWORD1)
# Data types (KEYWORD1)
DistanceTable KEYWORD1

View File

@ -15,8 +15,9 @@
"type": "git",
"url": "https://github.com/RobTillaart/DistanceTable"
},
"version": "0.2.1",
"version": "0.2.2",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"
"platforms": "*",
"headers": "DistanceTable.h"
}

View File

@ -1,5 +1,5 @@
name=DistanceTable
version=0.2.1
version=0.2.2
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Library for a memory efficient DistanceTable for Arduino.

View File

@ -27,16 +27,19 @@ Within the 2K RAM of an Arduino one could store normally a 21 x 21 matrix (1764
## Interface
- **DistanceTable(uint8_t size, float value = 0.0)** Constructor, allocates memory and sets initial value to all elements.
- **DistanceTable(uint8_t size, float value = 0.0)** Constructor, allocates memory and
sets initial value to all elements.
- **~DistanceTable();** Destructor, frees memory
- **void clear()** sets all entries to 0.0.
- **void setAll(float value)** sets all entries to value;
- **void set(uint8_t x, uint8_t y, float value )** sets a value for (x,y) and automatically for (y, x)
- **float get(uint8_t x, uint8_t y)** gets a value from (x,y). If x == y it will return 0.
- **float minimum(uint8_t &x, uint8_t &y)** Returns minimum and first occurrence in x and y. It does skip x == y pairs as these are 0.
- **float maximum(uint8_t &x, uint8_t &y)** Returns maximum and first occurrence in x and y. It does skip x == y pairs as these are 0.
- **uint16_t count(value, epsilon)** counts the number of occurrences of value. As we are comparing floats the epsilon can set a margin for 'almost equal'.
- **float minimum(uint8_t &x, uint8_t &y)** Returns minimum and first occurrence in x and y.
It does skip x == y pairs as these are 0.
- **float maximum(uint8_t &x, uint8_t &y)** Returns maximum and first occurrence in x and y.
It does skip x == y pairs as these are 0.
- **uint16_t count(value, epsilon)** counts the number of occurrences of value.
As we are comparing floats the epsilon can set a margin for 'almost equal'.
### Debug
@ -47,16 +50,28 @@ Within the 2K RAM of an Arduino one could store normally a 21 x 21 matrix (1764
- **uint16_t memoryUsed()** amount of memory used.
## Future
- **clear()** could set all to NAN? is that better as it indicates unknown?
setAll() let the user decide.
Note: table can be used for other symmetrical 2D tables.
And therefore include negative values.
## Operational
See examples.
## Future
- improve documentation
- **clear()** could set all to NAN? is that better as it indicates unknown?
- setAll() let the user decide.
- would DT(x,y) == -DT(y,x) a special case? (for all xy pairs) interesting!!
- e.g. difference in height?
- game with transactions between players?
- it would become a magnitude symmetrical distance table
- **countAbove(float value)** no epsilon needed
- add examples
- Note: table can be used for other symmetrical 2D tables.
- And therefore include negative values.
- derived or related classes
- int64_t int32_t int16_t int8_t + unsigned variants. (8 variations?)
- Template class?
- sum of all distances?
- Hamilton paths?
- idea for very sparse matrix? array of struct (x,y,value);

View File

@ -38,6 +38,7 @@
unittest_setup()
{
fprintf(stderr, "DISTANCETABLE_LIB_VERSION: %s\n", (char *) DISTANCETABLE_LIB_VERSION);
}
unittest_teardown()
@ -48,31 +49,29 @@ unittest_teardown()
unittest(test_constructor)
{
DistanceTable dt(12);
fprintf(stderr, "%s\n", DISTANCETABLE_LIB_VERSION);
assertEqual(12, dt.dimension());
assertEqual(60, dt.elements());
assertEqual(240, dt.memoryUsed());
for (int i = 0; i < 12; i += 4)
{
for (int j = i+1; j < 12; j += 3)
for (int j = i + 1; j < 12; j += 3)
{
dt.set(i, j, i * j);
assertEqual(i * j, dt.get(i, j));
assertEqual(i * j, dt.get(j, i));
}
}
dt.clear();
for (int i = 0; i < 12; i += 4)
{
for (int j = i+1; j < 12; j += 3)
for (int j = i + 1; j < 12; j += 3)
{
assertEqual(0, dt.get(j, i));
}
}
}