diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..31bc208 --- /dev/null +++ b/.clang-format @@ -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 diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..54b75f5 --- /dev/null +++ b/.clang-tidy @@ -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 diff --git a/include/pauldb/storage.h b/include/pauldb/storage.h index 4849bf1..5a2854c 100644 --- a/include/pauldb/storage.h +++ b/include/pauldb/storage.h @@ -2,115 +2,49 @@ #ifndef PAULDB_STORAGE_H #define PAULDB_STORAGE_H -#include #include +#include #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 } #endif -#endif /* PAULDB_STORAGE_H */ +#endif /* PAULDB_STORAGE_H */ \ No newline at end of file diff --git a/src/storage/page.c b/src/storage/page.c index 0abf22d..feee229 100644 --- a/src/storage/page.c +++ b/src/storage/page.c @@ -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 */ } diff --git a/test/storage/test_page.c b/test/storage/test_page.c index 67bb127..f971e5c 100644 --- a/test/storage/test_page.c +++ b/test/storage/test_page.c @@ -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 #include -#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; +} \ No newline at end of file