aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / svc / allen_notes.h
| 1 | /* allen_notes.h -- Allen's notes: short things the person saves in their own |
| 2 | * words ("save the gate code is 4471") and gets handed back when they ask |
| 3 | * ("what's the gate code"), without ever browsing for them. Each note keeps |
| 4 | * its key words (folded, without small words like "the" or "is", plurals |
| 5 | * cut to one form); two notes that share a key word are linked, which is the |
| 6 | * map Allen's window draws. Finding a note scores every live note by the key |
| 7 | * words of the question it holds and hands back the best one, the newest on |
| 8 | * a tie. The rules are deliberately simple, to be taught better later. |
| 9 | * Pure: no disk (the kernel keeps notes on disk through svc/allen_memory.h), |
| 10 | * host tested in svc/tests/allen_memory_test.c and ui/tests/allen_ui_test.c. */ |
| 11 | #ifndef AIENOS_ALLEN_NOTES_H |
| 12 | #define AIENOS_ALLEN_NOTES_H |
| 13 | #include <stdint.h> |
| 14 | |
| 15 | #define CK_ALLEN_NOTE_MAX 128u /* bytes of text, NUL included */ |
| 16 | #define CK_ALLEN_NOTES_MAX 512u /* notes Allen can keep */ |
| 17 | #define CK_ALLEN_NOTE_WORDS 12u /* key words kept per note */ |
| 18 | |
| 19 | typedef struct { |
| 20 | uint32_t start; /* Allen's start number when it was saved */ |
| 21 | uint8_t gone; /* deleted (or found damaged on disk): never handed back */ |
| 22 | uint8_t nword; |
| 23 | uint16_t len; |
| 24 | char text[CK_ALLEN_NOTE_MAX]; /* as typed, printable ASCII, NUL-terminated */ |
| 25 | uint32_t word[CK_ALLEN_NOTE_WORDS]; /* key words (hashes), derived from text */ |
| 26 | } ck_allen_note; |
| 27 | |
| 28 | typedef struct { |
| 29 | uint32_t n; /* notes in use, deleted ones included (note i lives in slot i) */ |
| 30 | ck_allen_note note[CK_ALLEN_NOTES_MAX]; |
| 31 | } ck_allen_notes; |
| 32 | |
| 33 | /* Sets text (as typed, trimmed; at most CK_ALLEN_NOTE_MAX - 1 bytes) and its |
| 34 | * key words. 0, or -1 when text is empty, too long or not printable ASCII. */ |
| 35 | int ck_allen_note_set(ck_allen_note *n, const char *text, uint32_t start); |
| 36 | /* Recomputes the key words from n->text (after loading from disk). */ |
| 37 | void ck_allen_note_index(ck_allen_note *n); |
| 38 | /* Key words of any text; returns how many (at most max). */ |
| 39 | unsigned ck_allen_key_words(const char *text, uint32_t *word, unsigned max); |
| 40 | /* Key words two notes share (0: not linked). */ |
| 41 | unsigned ck_allen_note_links(const ck_allen_note *a, const ck_allen_note *b); |
| 42 | /* Live notes linked to note i. */ |
| 43 | unsigned ck_allen_note_degree(const ck_allen_notes *ns, uint32_t i); |
| 44 | /* The best live note for a question: its index, or -1. strict: every key |
| 45 | * word of the question must be in the note; otherwise at least half of |
| 46 | * them. *also: how many other live notes would have qualified. */ |
| 47 | int ck_allen_notes_best(const ck_allen_notes *ns, const char *question, int strict, unsigned *also); |
| 48 | /* Live notes. */ |
| 49 | unsigned ck_allen_notes_live(const ck_allen_notes *ns); |
| 50 | |
| 51 | #endif |