LibJuno 1.0.1
LibJuno is a lightweight C11 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
map_api.h
Go to the documentation of this file.
1/*
2 MIT License
3
4 Copyright (c) 2025 Robin A. Onsay
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files
8 (the "Software"), to deal in the Software without restriction,
9 including without limitation the rights to use, copy, modify, merge,
10 publish, distribute, sublicense, and/or sell copies of the Software,
11 and to permit persons to whom the Software is furnished to do so,
12 subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be
15 included in all copies or substantial portions of the Software.
16*/
17
50#ifndef JUNO_MAP_API_H
51#define JUNO_MAP_API_H
52#include "juno/ds/array_api.h"
53#include "juno/macros.h"
55#include "juno/module.h"
56#include <stdbool.h>
57#include <stddef.h>
58#include "juno/status.h"
59#include "juno/types.h"
60#ifdef __cplusplus
61extern "C"
62{
63#endif
67typedef struct JUNO_MAP_ROOT_TAG JUNO_MAP_ROOT_T;
74struct JUNO_MAP_ROOT_TAG JUNO_MODULE_ROOT(JUNO_MAP_API_T,
75 const JUNO_MAP_HASHABLE_POINTER_API_T *ptHashablePointerApi;
76 const JUNO_VALUE_POINTER_API_T *ptValuePointerApi;
77 JUNO_DS_ARRAY_ROOT_T *ptHashMap;
78);
79
88{
90 JUNO_RESULT_SIZE_T (*Hash)(JUNO_POINTER_T tItem);
92 JUNO_RESULT_BOOL_T (*IsValueNull)(JUNO_POINTER_T tItem);
93};
94
101{
109 JUNO_RESULT_POINTER_T (*Get)(JUNO_MAP_ROOT_T *ptJunoMap, JUNO_POINTER_T tReturnItem);
120};
121
131{
133 ptMap &&
134 ptMap->ptApi &&
135 ptMap->ptHashablePointerApi &&
136 ptMap->ptValuePointerApi &&
137 ptMap->ptHashMap &&
138 ptMap->ptHashablePointerApi->Hash &&
139 ptMap->ptHashablePointerApi->IsValueNull &&
140 ptMap->ptValuePointerApi->Equals
141 );
142 JUNO_STATUS_T tStatus = JunoDs_ArrayVerify(ptMap->ptHashMap);
143 return tStatus;
144}
145
157JUNO_STATUS_T JunoDs_MapInit(JUNO_MAP_ROOT_T *ptMapRoot, const JUNO_MAP_HASHABLE_POINTER_API_T *ptHashablePointerApi, const JUNO_VALUE_POINTER_API_T *ptValuePointerApi, JUNO_DS_ARRAY_ROOT_T *ptArray, JUNO_FAILURE_HANDLER_T pfcnFailureHandler, JUNO_USER_DATA_T *pvUserData);
158
169JUNO_RESULT_POINTER_T JunoDs_MapGet(JUNO_MAP_ROOT_T *ptJunoMap, JUNO_POINTER_T tItem);
170
180
190#ifdef __cplusplus
191}
192#endif
193#endif // JUNO_MAP_API_H
Abstract fixed-capacity array interface for DS modules.
struct JUNO_DS_ARRAY_ROOT_TAG JUNO_DS_ARRAY_ROOT_T
Opaque array root carrying capacity and API pointer.
Definition array_api.h:58
static JUNO_STATUS_T JunoDs_ArrayVerify(const JUNO_DS_ARRAY_ROOT_T *ptArray)
Verify an array instance's capacity and API.
Definition array_api.h:117
JUNO_STATUS_T JunoDs_MapInit(JUNO_MAP_ROOT_T *ptMapRoot, const JUNO_MAP_HASHABLE_POINTER_API_T *ptHashablePointerApi, const JUNO_VALUE_POINTER_API_T *ptValuePointerApi, JUNO_DS_ARRAY_ROOT_T *ptArray, JUNO_FAILURE_HANDLER_T pfcnFailureHandler, JUNO_USER_DATA_T *pvUserData)
Initialize the map root with hashing/equality APIs and backing array.
Definition juno_map.c:34
JUNO_STATUS_T JunoDs_MapSet(JUNO_MAP_ROOT_T *ptJunoMap, JUNO_POINTER_T tItem)
Insert or update an entry (key/value) via linear probing.
Definition juno_map.c:133
static JUNO_STATUS_T JunoDs_MapVerify(JUNO_MAP_ROOT_T *ptMap)
Verify the map root, APIs, and backing array are valid.
Definition map_api.h:130
JUNO_STATUS_T JunoDs_MapRemove(JUNO_MAP_ROOT_T *ptJunoMap, JUNO_POINTER_T tKey)
Remove an entry by key via linear probing.
Definition juno_map.c:153
JUNO_RESULT_POINTER_T JunoDs_MapGet(JUNO_MAP_ROOT_T *ptJunoMap, JUNO_POINTER_T tItem)
Retrieve an entry by key via linear probing.
Definition juno_map.c:108
#define JUNO_ASSERT_EXISTS(ptr)
Returns JUNO_STATUS_NULLPTR_ERROR if the expression is falsy.
Definition macros.h:50
#define JUNO_MODULE_ROOT(API_T,...)
Implement a module root struct containing ptApi and failure fields.
Definition module.h:126
void(* JUNO_FAILURE_HANDLER_T)(JUNO_STATUS_T tStatus, const char *pcCustomMessage, JUNO_USER_DATA_T *pvUserData)
Failure handler callback signature.
Definition status.h:104
int32_t JUNO_STATUS_T
Canonical status type for LibJuno functions.
Definition status.h:49
void JUNO_USER_DATA_T
Opaque user data type for failure callbacks.
Definition status.h:96
Common assertion and helper macros for LibJuno modules.
struct JUNO_MAP_ROOT_TAG JUNO_MAP_ROOT_T
Map root type holding state and API pointers.
Definition map_api.h:67
Module system and dependency injection primitives for LibJuno.
Pointer trait and helpers for memory operations.
struct JUNO_POINTER_TAG JUNO_POINTER_T
Definition pointer_api.h:49
Status codes and failure-handling helpers for LibJuno.
Map API vtable.
Definition map_api.h:101
JUNO_STATUS_T(* Remove)(JUNO_MAP_ROOT_T *ptJunoMap, JUNO_POINTER_T tKey)
Remove a key (and its value) from the map.
Definition map_api.h:119
JUNO_RESULT_POINTER_T(* Get)(JUNO_MAP_ROOT_T *ptJunoMap, JUNO_POINTER_T tReturnItem)
Retrieve the value for the provided key; returns pointer result.
Definition map_api.h:109
JUNO_STATUS_T(* Set)(JUNO_MAP_ROOT_T *ptJunoMap, JUNO_POINTER_T tItem)
Insert or update a key-value pair.
Definition map_api.h:114
Hashing and null-check operations for map keys/values.
Definition map_api.h:88
JUNO_RESULT_BOOL_T(* IsValueNull)(JUNO_POINTER_T tItem)
Determine if a value slot is logically empty/null.
Definition map_api.h:92
JUNO_RESULT_SIZE_T(* Hash)(JUNO_POINTER_T tItem)
Compute a hash value for the given key.
Definition map_api.h:90
Value-pointer operations API (equality by contents).
Definition pointer_api.h:94
Common module result type aliases used throughout LibJuno.