Skip to content

Commit 9681c5f

Browse files
siara-ccsiara-in
authored andcommitted
Add Shox96 compression
1 parent 6ae274f commit 9681c5f

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

README.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,36 @@ No dependencies except for the Arduino and ESP32 core SDK. The Sqlite3 code is i
102102

103103
Any Flash memory such as those available on SPIFFS or Micro SD cards have limitation on number of writes / erase per sector. Usually the limitation is 10000 writes or 100000 writes (on the same sector). Although ESP32 supports wear-levelling, this is to be kept in mind before venturing into write-intensive database projects. There is no limitation on reading from Flash.
104104

105+
## Compression with Shox96
106+
107+
This implementation of `sqlite3` includes two functions `shox96_0_2c()` and `shox96_0_2d()` for compressing and decompressing text data.
108+
109+
Shox96 is a compression technique developed for reducing storage size of Short Strings. Details of how it works can be found [here](https://github.com/siara-cc/Shox96).
110+
111+
As of now it can work on only strings made of 'A to Z', 'a to z', '0-9', Special Characters such as &*() etc. found on keyboard, CR, LF, TAB and Space.
112+
113+
In general it can achieve upto 40% size reduction for Short Strings.
114+
115+
### Usage
116+
117+
The following set of commands demonstrate how compression can be accomplished:
118+
119+
```sql
120+
create table test (b1 blob);
121+
insert into test values (shox96_0_2c('Hello World'));
122+
insert into test values (shox96_0_2c('Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry''s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.'));
123+
select txt, length(txt) txt_len from (select shox96_0_2d(b1) txt from test);
124+
select length(b1) compressed_len from test;
125+
```
126+
127+
See screenshots section for output.
128+
129+
### Limitations (for Shox96)
130+
131+
- Trying to decompress any blob that was not compressed using `shox96_0_2c()` will crash the program.
132+
- It does not work if the string has binary characters. that is, other than ASCII 32 to 126, CR, LF and Tab.
133+
- Dictionary based compression / decompression is not yet implemented.
134+
105135
## Acknowledgements
106136

107137
* This library was developed based on NodeMCU module developed by [Luiz Felipe Silva](https://github.com/luizfeliperj). The documentation can be found [here](https://nodemcu.readthedocs.io/en/master/en/modules/sqlite3/).
@@ -112,20 +142,24 @@ Any Flash memory such as those available on SPIFFS or Micro SD cards have limita
112142

113143
## Screenshots
114144

115-
Output of Micro SD example:
145+
### Output of Micro SD example
116146

117147
![](output_screenshot.png?raw=true)
118148

119-
Output of SD Card database query through WebServer example:
149+
### Output of SD Card database query through WebServer example
120150

121151
![](output_web_1.png?raw=true)
122152
![](output_web_2.png?raw=true)
123153

124-
SQLite console:
154+
### SQLite console
125155

126156
![](console_screenshot.png?raw=true)
127157

128-
Output of Querying StackOverflow DB through WebServer example:
158+
### Shox96 compression
159+
160+
![](output_shox96.png?raw=true)
161+
162+
### Output of Querying StackOverflow DB through WebServer example:
129163

130164
![](output_web_so.png?raw=true)
131165
![](output_web_so_id.png?raw=true)

output_shox96.png

110 KB
Loading

src/esp32.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,8 @@ static void shox96_0_2d(sqlite3_context *context, int argc, sqlite3_value **argv
700700
}
701701

702702
int registerShox96_0_2(sqlite3 *db, const char **pzErrMsg, const struct sqlite3_api_routines *pThunk) {
703-
sqlite3_create_function(db, "shox96_0_2c", 1, SQLITE_UTF8, 0, shox96_0_2c, 0, 0);
704-
sqlite3_create_function(db, "shox96_0_2d", 1, SQLITE_UTF8, 0, shox96_0_2d, 0, 0);
703+
sqlite3_create_function(db, "shox96_0_2c", 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, shox96_0_2c, 0, 0);
704+
sqlite3_create_function(db, "shox96_0_2d", 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, shox96_0_2d, 0, 0);
705705
return SQLITE_OK;
706706
}
707707

0 commit comments

Comments
 (0)