|
Download knowledge_vault/computer_science/data-structures-and-git.md from Johnny5b/portable-ai-runner: direct link, hf CLI and curl.
- Browser
- Download file 3.21 kB
-
https://huggingface.co/datasets/Johnny5b/portable-ai-runner/resolve/main/knowledge_vault/computer_science/data-structures-and-git.md
- Command line
-
hf download hf://datasets/Johnny5b/portable-ai-runner/knowledge_vault/computer_science/data-structures-and-git.md
-
curl -L -o data-structures-and-git.md https://huggingface.co/datasets/Johnny5b/portable-ai-runner/resolve/main/knowledge_vault/computer_science/data-structures-and-git.md
3.21 kB
| # Data structures + Git operations (CS vault) | |
| ## Data structures — selection table | |
| | Need | Structure | Why | Cost (typical) | | |
| |---|---|---|---| | |
| | Fast lookup by key | hash table | O(1) average | O(1) insert/lookup | | |
| | Ordered iteration + range query | balanced BST (red-black, B-tree) | sorted invariants | O(log n) | | |
| | Priority by score | binary heap | heap property, no full ordering needed | O(log n) push/pop | | |
| | LRU cache | hash map + doubly linked list | O(1) evict of least-recent | O(1) all ops | | |
| | Prefix search / autocomplete | trie | shared-prefix compression | O(|key|) | | |
| | Union/grouping | disjoint set | near-constant merges | O(α(n)) | | |
| | Immutable snapshot (undo, diff) | persistent tree (git object model) | structural sharing | O(log n) version access | | |
| - B-trees (fat nodes matched to disk pages, high branching factor) are the structure for USB/SSD-backed indexes — this drive's situation. A linear scan of the vault beats an in-RAM index only for vaults < ~10 MB; beyond that, keep symbol_index.json + per-domain index files as the B-tree stand-in (flat files, page-friendly, diffable). | |
| ## Git — operations this drive's provenance system relies on | |
| 1. **Content-addressed storage.** Every object (blob, tree, commit, tag) is stored by sha1 of its content. Same content = same hash = free dedup. Same idea as this package's sha256 manifests: hash the bytes, record the hash, verify later. | |
| 2. **commit** = (tree, parent(s), author, committer, message, timestamp). Ancestry is a DAG — merges create two parents. | |
| 3. Working clone with full provenance: | |
| - `git clone --origin upstream <url>` — keep `upstream` so audits can `git fetch upstream` and compare. | |
| - `git rev-parse HEAD` — record the commit hash in the module manifest. This, plus per-file sha256, is the provenance stored in `symbols/schemas/*.manifest.json`. | |
| - `git diff --stat HEAD~1..HEAD` — what changed last commit. | |
| 4. **Conflict discipline:** rebase your own local work before a merge; never rebase published history others depend on (`git push --force` to shared branches is destructive — treat like a delete). | |
| 5. **Selective recovery:** `git checkout <hash> -- path/to/file` restores one file without moving the branch; `git revert <hash>` creates an inverse commit — safe on shared history, unlike `reset --hard`. | |
| 6. **Verification:** `git fsck` checks object database integrity; `git verify-commit <hash>` checks a GPG signature. A manifest storing (repo, commit, file, sha256) detects any silent mutation: recompute, compare, report. | |
| ## Storage-aware notes for an offline USB drive | |
| - Git repos store objects loosely or packed (`git gc` → packfiles). The clones in `modules/` carry full history; if drive space is tight, a `--depth 1` re-clone drops history AND the ability to audit provenance — the trade-off is recorded per module in its manifest, and the default here is full history. | |
| - Filesystem reality: exFAT (cross-platform) has no journaling and no permissions — portable but weaker for integrity; ext4 (Linux) has journaling. Either way the audit ledger (`memories/audit_ledger.jsonl`) + sha256 manifests are the integrity system of record, because they work on any filesystem. |