summaryrefslogtreecommitdiffstats
path: root/04_exercise/slotmap/slotmap.c
diff options
context:
space:
mode:
Diffstat (limited to '04_exercise/slotmap/slotmap.c')
-rw-r--r--04_exercise/slotmap/slotmap.c48
1 files changed, 0 insertions, 48 deletions
diff --git a/04_exercise/slotmap/slotmap.c b/04_exercise/slotmap/slotmap.c
deleted file mode 100644
index 57c4ef5..0000000
--- a/04_exercise/slotmap/slotmap.c
+++ /dev/null
@@ -1,48 +0,0 @@
-//
-// Created by stefan on 18.06.20.
-//
-
-#include "slotmap.h"
-#include <stdio.h>
-smHeader smInit(smEntry * slab, size_t size) {
- for (int i = 0; i < size; ++i) {
- slab[i].value = (intptr_t)NULL;
- }
- return (smHeader){.slab = slab, .size=size};
-}
-int smInsert(smHeader const * header, void * value) {
- for (size_t i = 0; i< header->size; ++i ) {
- intptr_t ptr = atomic_load(&header->slab[i].value);
- if((void *)ptr == NULL) {
- intptr_t expected = (intptr_t) NULL;
- if(atomic_compare_exchange_strong(&header->slab[i].value, &expected, (intptr_t) value)){
- return 0;
- }
- }
- }
- return -1;
-}
-void smDelete(smEntry * node) {
- intptr_t oldval = atomic_exchange(&node->value, (intptr_t)(NULL));
- if((void *) oldval == NULL) {
- fprintf(stderr, "A Node has been double deleted");
- }
-}
-void smDeleteValue(smHeader const * header, void * value){
- for (size_t i = 0; i< header->size; ++i ) {
- intptr_t ptr = atomic_load(&header->slab[i].value);
- if((void *)ptr == value) {
- smDelete(&header->slab[i]);
- }
- }
-}
-smEntry *smFindEntry(smHeader const * header, SearchFunction func){
- for (size_t i = 0; i< header->size; ++i ) {
- void * value = (void *) atomic_load(&header->slab[i].value);
-
- if(value != NULL && func(value)) {
- return &header->slab[i];
- }
- }
- return NULL;
-}