Skip to content

Commit

Permalink
.clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
AnyaCoder committed Oct 10, 2024
1 parent d2e6e1b commit 9c997f9
Show file tree
Hide file tree
Showing 30 changed files with 3,821 additions and 4,202 deletions.
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BasedOnStyle: LLVM
IndentWidth: 4
UseTab: ForIndentation
TabWidth: 4
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/.vs
/out
/out
198 changes: 99 additions & 99 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,101 +1,101 @@
{
"version": 3,
"configurePresets": [
{
"name": "windows-base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "x64-debug",
"displayName": "x64 Debug",
"inherits": "windows-base",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x64-release",
"displayName": "x64 Release",
"inherits": "x64-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "x86-debug",
"displayName": "x86 Debug",
"inherits": "windows-base",
"architecture": {
"value": "x86",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x86-release",
"displayName": "x86 Release",
"inherits": "x86-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "linux-debug",
"displayName": "Linux Debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"vendor": {
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
}
}
},
{
"name": "macos-debug",
"displayName": "macOS Debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
},
"vendor": {
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
}
}
}
]
"version": 3,
"configurePresets": [
{
"name": "windows-base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "x64-debug",
"displayName": "x64 Debug",
"inherits": "windows-base",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x64-release",
"displayName": "x64 Release",
"inherits": "x64-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "x86-debug",
"displayName": "x86 Debug",
"inherits": "windows-base",
"architecture": {
"value": "x86",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x86-release",
"displayName": "x86 Release",
"inherits": "x86-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "linux-debug",
"displayName": "Linux Debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"vendor": {
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
}
}
},
{
"name": "macos-debug",
"displayName": "macOS Debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
},
"vendor": {
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
}
}
}
]
}
11 changes: 4 additions & 7 deletions DataStructures/Common/Node.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

#include <string.h>

struct Node node_constructor(void* data, int size)
{
if (size < 1)
{
struct Node node_constructor(void *data, int size) {
if (size < 1) {
printf("Invalid data size for node...\n");
exit(1);
}
Expand All @@ -18,8 +16,7 @@ struct Node node_constructor(void* data, int size)
return node;
}

void node_destructor(struct Node* node)
{
void node_destructor(struct Node *node) {
free(node->data);
free(node);
}
}
19 changes: 9 additions & 10 deletions DataStructures/Common/Node.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#ifndef Node_h
#define Node_h

#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

struct Node
{
void* data;
struct Node* prev;
struct Node* next;
struct Node {
void *data;
struct Node *prev;
struct Node *next;
};

struct Node node_constructor(void* data, int size);
void node_destructor(struct Node* node);
struct Node node_constructor(void *data, int size);
void node_destructor(struct Node *node);

#endif // !Node_h
#endif // !Node_h
59 changes: 25 additions & 34 deletions DataStructures/Dictionary/Dictionary.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,53 @@
#include "Dictionary.h"
#include <string.h>

void insert_dict(struct Dictionary* dictionary, void* key, int key_size, void* value, int value_size);
void* search_dict(struct Dictionary* dictionary, void* key, int key_size);
void insert_dict(struct Dictionary *dictionary, void *key, int key_size,
void *value, int value_size);
void *search_dict(struct Dictionary *dictionary, void *key, int key_size);

struct Dictionary dictionary_constructor(int (*compare)(void* key_1, void* key_2))
{
struct Dictionary dictionary_constructor(int (*compare)(void *key_1,
void *key_2)) {
struct Dictionary dictionary;
dictionary.binary_search_tree = binary_search_tree_constructor(compare);
dictionary.insert = insert_dict;
dictionary.search = search_dict;
return dictionary;
}

void dictionary_destructor(struct Dictionary* dictionary)
{
void dictionary_destructor(struct Dictionary *dictionary) {
binary_search_tree_destructor(&dictionary->binary_search_tree);
}

void* search_dict(struct Dictionary* dictionary, void* key, int key_size)
{
void *search_dict(struct Dictionary *dictionary, void *key, int key_size) {
int dummy_value = 0;
struct Entry searchable = entry_constructor(key, key_size, &dummy_value, sizeof(dummy_value));
void* result =
dictionary->binary_search_tree
.search(&dictionary->binary_search_tree, &searchable, sizeof(searchable));
if (result)
{
return ((struct Entry*)result)->value;
}
else
{
struct Entry searchable =
entry_constructor(key, key_size, &dummy_value, sizeof(dummy_value));
void *result = dictionary->binary_search_tree.search(
&dictionary->binary_search_tree, &searchable, sizeof(searchable));
if (result) {
return ((struct Entry *)result)->value;
} else {
return NULL;
}
}


void insert_dict(struct Dictionary* dictionary, void* key, int key_size, void* value, int value_size)
{
void insert_dict(struct Dictionary *dictionary, void *key, int key_size,
void *value, int value_size) {
struct Entry entry = entry_constructor(key, key_size, value, value_size);

dictionary->binary_search_tree.insert(&dictionary->binary_search_tree, &entry, sizeof(entry));

dictionary->binary_search_tree.insert(&dictionary->binary_search_tree,
&entry, sizeof(entry));
}

// MARK: PUBLIC HELPER FUNCTIONS
int compare_string_keys(void* entry_1, void* entry_2)
{
if (strcmp((char*)((struct Entry*)entry_1)->key, (char*)((struct Entry*)entry_2)->key) > 0)
{
int compare_string_keys(void *entry_1, void *entry_2) {
if (strcmp((char *)((struct Entry *)entry_1)->key,
(char *)((struct Entry *)entry_2)->key) > 0) {
return 1;
}
else if (strcmp((char*)((struct Entry*)entry_1)->key, (char*)((struct Entry*)entry_2)->key) < 0)
{
} else if (strcmp((char *)((struct Entry *)entry_1)->key,
(char *)((struct Entry *)entry_2)->key) < 0) {
return -1;
}
else
{
} else {
return 0;
}
}
}
15 changes: 8 additions & 7 deletions DataStructures/Dictionary/Dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
#include "../Trees/BinarySearchTree.h"
#include "Entry.h"

struct Dictionary
{
struct Dictionary {
struct BinarySearchTree binary_search_tree;

void (*insert)(struct Dictionary* dictionary, void* key, int key_size, void* value, int value_size);
void* (*search)(struct Dictionary* dictionary, void* key, int key_size);
void (*insert)(struct Dictionary *dictionary, void *key, int key_size,
void *value, int value_size);
void *(*search)(struct Dictionary *dictionary, void *key, int key_size);
};

struct Dictionary dictionary_constructor(int (*compare)(void* key_1, void* key_2));
void dictionary_destructor(struct Dictionary* dictionary);
int compare_string_keys(void* entry_1, void* entry_2);
struct Dictionary dictionary_constructor(int (*compare)(void *key_1,
void *key_2));
void dictionary_destructor(struct Dictionary *dictionary);
int compare_string_keys(void *entry_1, void *entry_2);
#endif // !Dictionary_h
Loading

0 comments on commit 9c997f9

Please sign in to comment.