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 #ifndef PAULDB_STORAGE_H
#define PAULDB_STORAGE_H #define PAULDB_STORAGE_H
#include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif #endif
/* --- Page Management --- */ /* --- Page Management --- */
typedef struct Page Page; typedef struct Page Page;
Page * Page * page_create(uint32_t page_id);
page_create
(
uint32_t page_id
);
int int page_insert(Page * p, const void * data, size_t len);
page_insert
(
Page *p,
const void *data,
size_t len
);
void * 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 void page_free(Page * p);
page_free
(
Page *p
);
/* --- Heap (Multi-Page Row Store / Delta) --- */ /* --- Heap (Multi-Page Row Store / Delta) --- */
typedef struct Heap Heap; typedef struct Heap Heap;
Heap * Heap * heap_create(void);
heap_create
(
void
);
int int heap_insert(Heap * h, const void * data, size_t len);
heap_insert
(
Heap *h,
const void *data,
size_t len
);
void void heap_full_scan(Heap * h, void (*callback)(const void *, size_t));
heap_full_scan
(
Heap *h,
void (*callback)
(
const void *,
size_t
)
);
void void heap_free(Heap * h);
heap_free
(
Heap *h
);
/* --- B+Tree Index --- */ /* --- B+Tree Index --- */
typedef struct BTree BTree; typedef struct BTree BTree;
BTree * BTree * btree_create(void);
btree_create
(
void
);
int int btree_insert(BTree * bt, int64_t key, uint32_t page_id, uint16_t slot_id);
btree_insert
(
BTree *bt,
int64_t key,
uint32_t page_id,
uint16_t slot_id
);
int int btree_lookup(BTree * bt, int64_t key, uint32_t * out_page, uint16_t * out_slot);
btree_lookup
(
BTree *bt,
int64_t key,
uint32_t *out_page,
uint16_t *out_slot
);
void void btree_free(BTree * bt);
btree_free
(
BTree *bt
);
#ifdef __cplusplus #ifdef __cplusplus
} }
+8 -28
View File
@@ -46,10 +46,7 @@ struct Page
/* ---- Hilfsfunktionen ---- */ /* ---- Hilfsfunktionen ---- */
static PageHeader * static PageHeader *
header header(Page * p)
(
Page *p
)
{ {
return (PageHeader *) p->raw; return (PageHeader *) p->raw;
} }
@@ -57,18 +54,14 @@ header
/* ---- API ---- */ /* ---- API ---- */
Page * Page *
page_create page_create(uint32_t page_id)
(
uint32_t page_id
)
{ {
Page *p = malloc(sizeof(Page)); Page * p = malloc(sizeof(Page));
if (!p) if (!p) return NULL;
return NULL;
memset(p->raw, 0, PAGE_SIZE); memset(p->raw, 0, PAGE_SIZE);
PageHeader *h = header(p); PageHeader * h = header(p);
h->page_id = page_id; h->page_id = page_id;
h->num_slots = 0; h->num_slots = 0;
h->free_space_offset = PAGE_SIZE; h->free_space_offset = PAGE_SIZE;
@@ -77,22 +70,14 @@ page_create
} }
void void
page_free page_free(Page * p)
(
Page *p
)
{ {
free(p); free(p);
} }
/* page_insert und page_get folgen im naechsten TDD-Zyklus */ /* page_insert und page_get folgen im naechsten TDD-Zyklus */
int int
page_insert page_insert(Page * p, const void * data, size_t len)
(
Page *p,
const void *data,
size_t len
)
{ {
(void) p; (void) p;
(void) data; (void) data;
@@ -101,12 +86,7 @@ page_insert
} }
void * void *
page_get page_get(Page * p, uint16_t slot_id, size_t * out_len)
(
Page *p,
uint16_t slot_id,
size_t *out_len
)
{ {
(void) p; (void) p;
(void) slot_id; (void) slot_id;
+7 -11
View File
@@ -4,28 +4,24 @@
* RED -> diese Datei schreiben, noch kein page.c -> Linker-Fehler * RED -> diese Datei schreiben, noch kein page.c -> Linker-Fehler
* GREEN -> page_create() + page_free() in page.c implementieren * GREEN -> page_create() + page_free() in page.c implementieren
*/ */
#include "pauldb/storage.h"
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include "pauldb/storage.h"
static void static void
test_create_returns_non_null test_create_returns_non_null(void)
(
void
)
{ {
Page *p = page_create(42); Page * p = page_create(42);
assert(p != NULL); assert(p != NULL);
page_free(p); page_free(p);
printf(" OK: page_create(42) returns non-NULL\n"); printf(" OK: page_create(42) returns non-NULL\n");
} }
static void
int int
main main(void)
(
void
)
{ {
printf("=== test_page ===\n"); printf("=== test_page ===\n");
test_create_returns_non_null(); test_create_returns_non_null();