22[ ![ Arduino CI] ( https://github.com/RobTillaart/MultiMap/workflows/Arduino%20CI/badge.svg )] ( https://github.com/marketplace/actions/arduino_ci )
33[ ![ Arduino-lint] ( https://github.com/RobTillaart/MultiMap/actions/workflows/arduino-lint.yml/badge.svg )] ( https://github.com/RobTillaart/MultiMap/actions/workflows/arduino-lint.yml )
44[ ![ JSON check] ( https://github.com/RobTillaart/MultiMap/actions/workflows/jsoncheck.yml/badge.svg )] ( https://github.com/RobTillaart/MultiMap/actions/workflows/jsoncheck.yml )
5+ [ ![ GitHub issues] ( https://img.shields.io/github/issues/RobTillaart/MultiMap.svg )] ( https://github.com/RobTillaart/MultiMap/issues )
6+
57[ ![ License: MIT] ( https://img.shields.io/badge/license-MIT-green.svg )] ( https://github.com/RobTillaart/MultiMap/blob/master/LICENSE )
68[ ![ GitHub release] ( https://img.shields.io/github/release/RobTillaart/MultiMap.svg?maxAge=3600 )] ( https://github.com/RobTillaart/MultiMap/releases )
9+ [ ![ PlatformIO Registry] ( https://badges.registry.platformio.org/packages/robtillaart/library/MultiMap.svg )] ( https://registry.platformio.org/libraries/robtillaart/MultiMap )
710
811
912# MultiMap
@@ -39,7 +42,25 @@ Of course this approximation introduces an error.
3942By increasing the number of points and choose their position strategically the average error will be reduced.
4043
4144Note: some functions are hard to approximate with multiMap as they go to infinity or have a singularity.
42- Think of ** tan(x)** around x = PI/2 (90°) or ** sin(1/x)** around zero.
45+ Think of ** tan(x)** around x = PI/2 (90°) or ** sin(1/x)** around zero.
46+
47+
48+ #### Related
49+
50+ Other mapping libraries
51+
52+ - https://github.com/RobTillaart/FastMap
53+ - https://github.com/RobTillaart/Gamma
54+ - https://github.com/RobTillaart/map2colour
55+ - https://github.com/RobTillaart/moduloMap
56+ - https://github.com/RobTillaart/MultiMap
57+
58+
59+ ## Interface
60+
61+ ``` cpp
62+ #include " MultiMap.h"
63+ ```
4364
4465
4566#### Usage
@@ -66,7 +87,7 @@ This is a explicit difference with the **map()** function.
6687Therefore it is important to extend the range of the arrays to cover all possible values.
6788
6889
69- #### Performance
90+ ## Performance
7091
7192** multiMap()** does a linear search for the inputValue in the inputArray.
7293This implies that usage of larger and more precise arrays will take more time.
@@ -96,24 +117,59 @@ Experimental 0.1.7 => use with care.
96117
97118** multiMapCache()** MMC for short, is a very similar function as ** multiMap()** .
98119The main difference is that MMC caches the last input and output value.
99- The goal is to improve the performance by preventing
120+ The goal is to improve the performance by preventing searching the same
121+ value again and again.
100122
101123If the input sequence has a lot of repeating values e.g. 2 2 2 2 2 2 5 5 5 5 5 4 4 4 4 2 2 2 2 2 2
102124MMC will be able to return the value from cache often.
103125Otherwise keeping cache is overhead.
104126
105127Be sure to do your own tests to see if MMC improves your performance.
106128
129+ A possible variation is to cache the last interval - lower and upper index.
130+ It would allow a to test that value and improve the linear search.
131+ (to be investigated).
107132
108- #### Related
109133
110- Other mapping libraries
134+ #### MultiMap two types
111135
112- - https://github.com/RobTillaart/FastMap
113- - https://github.com/RobTillaart/Gamma
114- - https://github.com/RobTillaart/map2colour
115- - https://github.com/RobTillaart/moduloMap
116- - https://github.com/RobTillaart/MultiMap
136+ Experimental 0.2.0 => use with care.
137+
138+ ** multiMap<T1, T2>()** MMTT for short, is a very similar function as ** multiMap()** .
139+ The main difference is that MMTT uses two different types, typical the input
140+ is an integer type and the output is a float or double type.
141+ It is expected that there will be a gain if two different sized integer types are used.
142+ This is not tested.
143+
144+ See the example ** multimap_distance_two_types.ino**
145+
146+ ``` cpp
147+ // for a sharp distance range finder
148+ float sharp2cm2 (int val)
149+ {
150+ // out[ ] holds the distances in cm
151+ float out[ ] = {150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20};
152+
153+ // in[ ] holds the measured analogRead() values for that distance
154+ int in[ ] = { 90, 97, 105, 113, 124, 134, 147, 164, 185, 218, 255, 317, 408, 506};
155+
156+ float dist = multiMap<int, float>(val, in, out, 14);
157+ return dist;
158+ }
159+ ```
160+
161+ A first test indicate that using the int type for the input in the example
162+ is substantial (~37%) faster per call. Test on UNO, time in micros per call.
163+
164+ | types | time us | call |
165+ |:-------:|:---------:|:-------|
166+ | 1 | 194.93 | ```float dist = multiMap<float>(val, in, out, 14);``` |
167+ | 2 | 121.97 | ```float dist = multiMap<int, float>(val, in, out, 14);``` |
168+
169+ Furthermore it is obvious that there is less need for RAM if the integer type is smaller
170+ in size than the float type.
171+
172+ Be sure to do your own tests to see if MMTT improves your performance.
117173
118174
119175## Operation
@@ -129,22 +185,17 @@ Please note the fail example as this shows that in the intern math overflow can
129185
130186- improve documentation
131187
132-
133188#### Should
134189
135190- investigate multiMapCache behaviour
136191 - determine overhead.
137- - investigate binary search multiMapBS behaviour
138- - expect a constant time
139- - where is the tipping point between linear and binary search.
140- (expect around size = 8)
141192- extend unit tests
142-
193+ - multi type versions
143194
144195#### Could
145196
146197- Investigate class implementation
147- - basic call out = mm.map(value);
198+ - basic call ``` out = mm.map(value);```
148199 - runtime adjusting input and output array **begin(in[], out[])**
149200 - performance / footprint
150201 - less parameter passing
@@ -154,14 +205,19 @@ Please note the fail example as this shows that in the intern math overflow can
154205 now it is constrained without user being informed.
155206- Investigate a 2D multiMap e.g. for complex numbers?
156207 - is it possible / feasible?
157- - data type input array does not need to be equal to the output array.
158- - template<typename T1, typename T2>
159- ``` T2 multiMapBS(T1 value, T1* _in, T2* _out, uint16_t size) ```
160-
161208
162209#### Wont
163210
164211- should the lookup tables be merged into one array of pairs?
165212 - you cannot reuse e.g. the input array or the output array then.
166213 this would not improve the memory footprint.
167214
215+
216+ ## Support
217+
218+ If you appreciate my libraries, you can support the development and maintenance.
219+ Improve the quality of the libraries by providing issues and Pull Requests, or
220+ donate through PayPal or GitHub sponsors.
221+
222+ Thank you,
223+
0 commit comments