chore: clang-format and formatting

This commit is contained in:
paulhorn
2026-06-21 19:59:09 +02:00
parent 9ba08bee98
commit 41c990cf57
5 changed files with 137 additions and 150 deletions
+48
View File
@@ -0,0 +1,48 @@
BasedOnStyle: LLVM
# Pointer/Reference alignment: int * p, void (* callback)(...)
PointerAlignment: Middle
ReferenceAlignment: Middle
# Line length
ColumnLimit: 100
# Return type on its own line
BreakAfterReturnType: All
# Params each on their own line
BinPackParameters: false
# Indentation
IndentWidth: 4
TabWidth: 4
UseTab: Never
ContinuationIndentWidth: 4
# Braces always on their own line (Allman style)
BreakBeforeBraces: Allman
# No blank line after opening {
KeepEmptyLinesAtTheStartOfBlocks: false
# Space after C-style cast: (uint32_t) x
SpaceAfterCStyleCast: true
# Spaces
SpaceInEmptyParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
# Allow single-line if without braces
AllowShortIfStatementsOnASingleLine: WithoutElse
# Include sorting
SortIncludes: CaseSensitive
IncludeBlocks: Regroup
# Short constructs
AllowShortFunctionsOnASingleLine: Empty
AllowShortLoopsOnASingleLine: false
# Comments
ReflowComments: true
+29
View File
@@ -0,0 +1,29 @@
Checks: >
bugprone-*,
cert-*,
clang-analyzer-*,
misc-*,
performance-*,
portability-*,
readability-*,
-readability-magic-numbers,
-readability-identifier-length,
-readability-function-cognitive-complexity,
-readability-braces-around-statements,
-cert-err33-c,
-misc-include-cleaner
CheckOptions:
- key: bugprone-easily-swappable-parameters.MinimumLength
value: 3
- key: readability-identifier-naming.FunctionCase
value: lower_case
- key: readability-identifier-naming.VariableCase
value: lower_case
- key: readability-identifier-naming.MacroDefinitionCase
value: UPPER_CASE
- key: readability-identifier-naming.TypedefCase
value: CamelCase
HeaderFilterRegex: '.*'
FormatStyle: file
+14 -80
View File
@@ -2,112 +2,46 @@
#ifndef PAULDB_STORAGE_H
#define PAULDB_STORAGE_H
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
/* --- Page Management --- */
typedef struct Page Page;
Page *
page_create
(
uint32_t page_id
);
Page * page_create(uint32_t page_id);
int
page_insert
(
Page *p,
const void *data,
size_t len
);
int page_insert(Page * p, const void * data, size_t len);
void *
page_get
(
Page *p,
uint16_t slot_id,
size_t *out_len
);
void * page_get(Page * p, uint16_t slot_id, size_t * out_len);
void
page_free
(
Page *p
);
void page_free(Page * p);
/* --- Heap (Multi-Page Row Store / Delta) --- */
typedef struct Heap Heap;
Heap *
heap_create
(
void
);
Heap * heap_create(void);
int
heap_insert
(
Heap *h,
const void *data,
size_t len
);
int heap_insert(Heap * h, const void * data, size_t len);
void
heap_full_scan
(
Heap *h,
void (*callback)
(
const void *,
size_t
)
);
void heap_full_scan(Heap * h, void (*callback)(const void *, size_t));
void
heap_free
(
Heap *h
);
void heap_free(Heap * h);
/* --- B+Tree Index --- */
typedef struct BTree BTree;
BTree *
btree_create
(
void
);
BTree * btree_create(void);
int
btree_insert
(
BTree *bt,
int64_t key,
uint32_t page_id,
uint16_t slot_id
);
int btree_insert(BTree * bt, int64_t key, uint32_t page_id, uint16_t slot_id);
int
btree_lookup
(
BTree *bt,
int64_t key,
uint32_t *out_page,
uint16_t *out_slot
);
int btree_lookup(BTree * bt, int64_t key, uint32_t * out_page, uint16_t * out_slot);
void
btree_free
(
BTree *bt
);
void btree_free(BTree * bt);
#ifdef __cplusplus
}
+29 -49
View File
@@ -26,90 +26,70 @@
typedef struct
{
uint32_t page_id;
uint16_t num_slots;
uint16_t free_space_offset;
uint32_t page_id;
uint16_t num_slots;
uint16_t free_space_offset;
} PageHeader;
typedef struct
{
uint16_t offset;
uint16_t length;
uint16_t offset;
uint16_t length;
} Slot;
/* oeffentliche Page-Struktur (opak nach aussen) */
struct Page
{
uint8_t raw[PAGE_SIZE];
uint8_t raw[PAGE_SIZE];
};
/* ---- Hilfsfunktionen ---- */
static PageHeader *
header
(
Page *p
)
header(Page * p)
{
return (PageHeader *) p->raw;
return (PageHeader *) p->raw;
}
/* ---- API ---- */
Page *
page_create
(
uint32_t page_id
)
page_create(uint32_t page_id)
{
Page *p = malloc(sizeof(Page));
if (!p)
return NULL;
Page * p = malloc(sizeof(Page));
if (!p) return NULL;
memset(p->raw, 0, PAGE_SIZE);
memset(p->raw, 0, PAGE_SIZE);
PageHeader *h = header(p);
h->page_id = page_id;
h->num_slots = 0;
h->free_space_offset = PAGE_SIZE;
PageHeader * h = header(p);
h->page_id = page_id;
h->num_slots = 0;
h->free_space_offset = PAGE_SIZE;
return p;
return p;
}
void
page_free
(
Page *p
)
page_free(Page * p)
{
free(p);
free(p);
}
/* page_insert und page_get folgen im naechsten TDD-Zyklus */
int
page_insert
(
Page *p,
const void *data,
size_t len
)
page_insert(Page * p, const void * data, size_t len)
{
(void) p;
(void) data;
(void) len;
return -1; /* noch nicht implementiert */
(void) p;
(void) data;
(void) len;
return -1; /* noch nicht implementiert */
}
void *
page_get
(
Page *p,
uint16_t slot_id,
size_t *out_len
)
page_get(Page * p, uint16_t slot_id, size_t * out_len)
{
(void) p;
(void) slot_id;
(void) out_len;
return NULL; /* noch nicht implementiert */
(void) p;
(void) slot_id;
(void) out_len;
return NULL; /* noch nicht implementiert */
}
+15 -19
View File
@@ -4,31 +4,27 @@
* RED -> diese Datei schreiben, noch kein page.c -> Linker-Fehler
* GREEN -> page_create() + page_free() in page.c implementieren
*/
#include "pauldb/storage.h"
#include <assert.h>
#include <stdio.h>
#include "pauldb/storage.h"
static void
test_create_returns_non_null(void)
{
Page * p = page_create(42);
assert(p != NULL);
page_free(p);
printf(" OK: page_create(42) returns non-NULL\n");
}
static void
test_create_returns_non_null
(
void
)
{
Page *p = page_create(42);
assert(p != NULL);
page_free(p);
printf(" OK: page_create(42) returns non-NULL\n");
}
int
main
(
void
)
main(void)
{
printf("=== test_page ===\n");
test_create_returns_non_null();
printf("All tests passed.\n");
return 0;
printf("=== test_page ===\n");
test_create_returns_non_null();
printf("All tests passed.\n");
return 0;
}