SDC
SDC is a ridiculously overengineered flash cards app using C, SQLite, Fenwick trees, and PyQt. It was originally written in Go and called SD, named after a common type of flash card. 😀
Usage
Flash cards are stored in the cards
table of a SQLite database. There are four columns: idx INTEGER PRIMARY KEY, weight INTEGER, key TEXT, val TEXT
. The idx
is a unique index for each card, starting at 1. The weight is how often the card should come up. The key and value are the front and reverse sides of the card.
To create a card deck, use sqlite3 cards "CREATE TABLE cards (idx INTEGER PRIMARY KEY, weight INTEGER, key TEXT, val TEXT)"
. You may be able to nearly double performance by enabling WAL with PRAGMA journal_mode=WAL
, because WAL normally writes the content once instead of twice, except during checkpointing.
Now build SDC with gcc sd.c fenwick.c -o sd -lsqlite3 -O2 -march=native
and run ./sd
to enjoy a fast flash cards experience! You can also install the sdc-git
package from the AUR.
The program will display the key
of a randomly selected card. Press any key to show the val
of the card. Now press either y
or n
depending on whether you got the card correct, and the program adjusts that card's weight. Press q
to quit.
Useful commands
Description | Command |
---|---|
View card deck | sqlite3 cards .dump |
Get total number of cards | sqlite3 cards "SELECT COUNT(*) FROM cards" |
Get total number of cards with positive weight | sqlite3 cards "SELECT COUNT(*) FROM cards WHERE weight>0" |
Search for string in keys | sqlite3 cards "SELECT * FROM cards WHERE key LIKE '%hello%'" |
Add card to deck | sd-add.fish |
Edit deck | sqlitevi.fish or sqlitebrowser |
GUI
SDC has a GUI, sd-qt.py, using PyQt6. This script runs the sd
binary located in the same directory as the script, using the command-line flags passed to the script. Alternatively, there's a Tkinter GUI, sd-tk.py, that only requires the Python standard library but looks ancient and doesn't support Wayland. These GUIs aren't compatible with the original unmaintained SD.
It shouldn't be hard to write your own SD clone or GUI, so if you write one, I'd be glad to link to it here.
Performance
SD is designed to be extremely efficient and supports decks with millions of flash cards. If N
is the number of cards, initializing the program requires O(N)
time and O(N)
memory. Selecting a random card and adjusting its weight requires O(log N)
time. Internally, SD uses Fenwick trees to achieve this time complexity. The Fenwick tree implementation is a self-contained library and (hopefully) well-tested.