chore: clang-format and formatting
This commit is contained in:
@@ -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
@@ -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
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-49
@@ -26,90 +26,70 @@
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t page_id;
|
uint32_t page_id;
|
||||||
uint16_t num_slots;
|
uint16_t num_slots;
|
||||||
uint16_t free_space_offset;
|
uint16_t free_space_offset;
|
||||||
} PageHeader;
|
} PageHeader;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
uint16_t length;
|
uint16_t length;
|
||||||
} Slot;
|
} Slot;
|
||||||
|
|
||||||
/* oeffentliche Page-Struktur (opak nach aussen) */
|
/* oeffentliche Page-Struktur (opak nach aussen) */
|
||||||
struct Page
|
struct Page
|
||||||
{
|
{
|
||||||
uint8_t raw[PAGE_SIZE];
|
uint8_t raw[PAGE_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ---- Hilfsfunktionen ---- */
|
/* ---- Hilfsfunktionen ---- */
|
||||||
|
|
||||||
static PageHeader *
|
static PageHeader *
|
||||||
header
|
header(Page * p)
|
||||||
(
|
|
||||||
Page *p
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
return (PageHeader *) p->raw;
|
return (PageHeader *) p->raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---- 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;
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
(void) len;
|
(void) len;
|
||||||
return -1; /* noch nicht implementiert */
|
return -1; /* noch nicht implementiert */
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
(void) out_len;
|
(void) out_len;
|
||||||
return NULL; /* noch nicht implementiert */
|
return NULL; /* noch nicht implementiert */
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-19
@@ -4,31 +4,27 @@
|
|||||||
* 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
|
||||||
|
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
|
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
|
int
|
||||||
main
|
main(void)
|
||||||
(
|
|
||||||
void
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
printf("=== test_page ===\n");
|
printf("=== test_page ===\n");
|
||||||
test_create_returns_non_null();
|
test_create_returns_non_null();
|
||||||
printf("All tests passed.\n");
|
printf("All tests passed.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user