Skip to content

Migrate to stb_ds for hashes and dynamic arrays#83

Merged
nchapman merged 5 commits into
developfrom
feature/collections
Dec 16, 2025
Merged

Migrate to stb_ds for hashes and dynamic arrays#83
nchapman merged 5 commits into
developfrom
feature/collections

Conversation

@nchapman
Copy link
Copy Markdown
Collaborator

No description provided.

Replace khash-backed StringMap with stb_ds hash maps for ROM aliasing.
stb_ds provides a simpler, more widely-used single-header library with
type-safe macros and automatic key management via sh_new_strdup().

Changes:
- Add workspace/all/vendor/stb/stb_ds.h from nothings/stb
- Add stb_ds_impl.c for single-TU implementation
- Migrate launcher_map.c to use MapEntry* with stb_ds macros
- Migrate launcher_emu_cache.c (uses NULL values for presence-only)
- Export Map_free() for clean API
- Delete stringmap.c/h and vendor/khash/
Remove the custom Array wrapper type in favor of using stb_ds dynamic
arrays directly. This follows the same pattern as the previous StringMap
to stb_ds migration.

Changes:
- Delete collections.h/c (Array type no longer needed)
- Update Entry**, Recent**, Directory** to use stb_ds directly
- Add -I vendor/stb to all makefiles for clean includes
- Update all source files to use #include "stb_ds.h"
- Update tests to use arrpush/arrlen/arrfree macros
- Fix makefile.dev: add stb_ds_impl.c, launcher_emu_cache.c

Migration pattern applied throughout:
- Array* arr = Array_new() → T** arr = NULL
- Array_push(arr, item) → arrpush(arr, item)
- arr->count → arrlen(arr)
- arr->items[i] → arr[i]
- Array_free(arr) → arrfree(arr)
Continues the stb_ds migration by converting two more custom data
structures:

- LauncherPathStack: Replace capacity/count wrapper struct with simple
  typedef to stb_ds dynamic array. Simplifies push/pop to single-line
  macro calls.

- LauncherDirScanResult: Consolidate parallel arrays (paths, is_dirs)
  into single struct array. Cleaner iteration and memory management.
Copilot AI review requested due to automatic review settings December 16, 2025 23:02
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the codebase from custom Array data structures and khash-based StringMap to Sean Barrett's stb_ds single-header library for dynamic arrays and hash tables. The migration affects data structure usage throughout the launcher, replacing:

  • Custom Array type with stb_ds dynamic arrays (e.g., Entry** instead of Array*)
  • StringMap (khash-backed) with stb_ds string hash maps (MapEntry*)
  • Manual memory management with stb_ds automatic growth

Key Changes:

  • Adds stb_ds.h v0.67 vendor library with implementation file
  • Removes khash.h, collections.h/c, stringmap.h/c, and their test file
  • Migrates all dynamic array and hash map usage to stb_ds APIs
  • Updates 40+ files including core launcher logic, tests, and build system

Reviewed changes

Copilot reviewed 40 out of 43 changed files in this pull request and generated no comments.

Show a summary per file
File Description
workspace/all/vendor/stb/stb_ds.h Added stb_ds v0.67 library (1895 lines, vendor file)
workspace/all/vendor/khash/khash.h Removed khash library (was used for StringMap)
workspace/all/vendor/README.md Updated to document stb_ds instead of khash
workspace/all/common/stb_ds_impl.c Added implementation file for stb_ds
workspace/all/common/collections.[ch] Removed custom Array implementation
workspace/all/common/stringmap.[ch] Removed StringMap (khash wrapper)
workspace/all/common/utils.[ch] Made prefixMatch/suffixMatch const-correct
workspace/all/launcher/*.c Migrated to stb_ds dynamic arrays and hash maps
workspace/all/player/player_archive.c Removed unnecessary casts
tests/unit/all/**/*.c Updated tests for stb_ds APIs
build files Updated includes and source lists

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nchapman nchapman merged commit 9fe56f5 into develop Dec 16, 2025
4 checks passed
@nchapman nchapman deleted the feature/collections branch December 16, 2025 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants