4 ms·
I've long thought I should do a blog on it and submit it here, just haven't gotten around to it. Until then... The "lines" data structure. This is a list lib
by luckydude 9y ago
I've long thought I should do a blog on it and submit it here, just haven't gotten around to it. Until then...
The "lines" data structure. This is a list library that scales down to a very small thing and up to pretty decent sized things. Think perl arrays and the ops on them.
lines.h snippet below.
/*
* liblines - interfaces for autoexpanding data structures
*
* s= allocLines(n)
* pre allocate space for slightly less than N entries.
* s = addLine(s, line)
* add line to s, allocating as needed.
* line must be a pointer to preallocated space.
* freeLines(s, freep)
* free the lines array; if freep is set, call that on each entry.
* if freep is 0, do not free each entry.
* buf = popLine(s)
* return the most recently added line (not an alloced copy of it)
* reverseLines(s)
* reverse the order of the lines in the array
* sortLines(space, compar)
* sort the lines using the compar function if set, else string_sort()
* removeLine(s, which, freep)
* look for all lines which match "which" and remove them from the array
* returns number of matches found
* removeLineN(s, i, freep)
* remove the 'i'th line.
* lines = splitLine(buf, delim, lines)
* split buf on any/all chars in delim and put the tokens in lines.
* buf = joinLines(":", s)
* return one string which is all the strings glued together with ":"
* does not free s, caller must free s.
* buf = findLine(lines, needle);
* Return the index the line in lines that matches needle
*/
The stdio stuff. We have a way that you can "push" code on
top of a FILE. Some layers we implemented were compression and CRC and XOR. The compression is lz4 (we may still have
gzip); the CRC stuff splits the file up into "blocks" (size is uniform in a file but it varies by overall file size), crcs each one. The XOR stuff adds an XOR block at the end.
The result to a user is if they
fpush(&f, fopen_crc(...));
then the file will be crc "behind the scenes". That fpush is
the only new line of code to get the crc stuff. Ditto for
compression.
It gives you compression and hardened files under the stdio
API and it's super fast. Like GB/sec fast.
There's other stuff as well, like the spawn() code (I haven't
called fork() in a decade or more) that brings a form of Windows
spawn to Unix (since you can't make fork() work well on Windows). All of the code is Windows/Unix portable.