taskrambler
0.1.8
Web server and task management solution.
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <search.h>
#include <unistd.h>
#include "utils/memory.h"
#include "tree.h"
Go to the source code of this file.
Data Structures | |
struct | memSegment |
Macros | |
#define | _GNU_SOURCE |
Functions | |
struct memSegment * | newElement (size_t size) |
struct memSegment * | findElement (struct memSegment *tree, size_t size) |
struct memSegment * | grandparent (struct memSegment *node) |
struct memSegment * | uncle (struct memSegment *node) |
struct memSegment * | sibling (struct memSegment *node) |
void | rotateLeft (struct memSegment **tree, struct memSegment *node) |
void | rotateRight (struct memSegment **tree, struct memSegment *node) |
void | replaceNode (struct memSegment **tree, struct memSegment *node1, struct memSegment *node2) |
struct memSegment * | insertElement (struct memSegment **tree, struct memSegment *element) |
struct memSegment * | findInOrderSuccessor (struct memSegment *tree) |
struct memSegment * | deleteElement (struct memSegment **tree, struct memSegment *element) |
void | traverse (struct memSegment *tree, void(*cb)(struct memSegment *, int)) |
void | post (struct memSegment *tree, void(*cb)(struct memSegment *, int)) |
void | printElement (struct memSegment *node, int depth) |
void | cleanup (struct memSegment *node, int depth) |
static void | segmentFree (struct memSegment *segment, int depth) |
void * | memNewRef (void *mem) |
void * | memMalloc (size_t size) |
void * | memCalloc (size_t nmemb, size_t size) |
void | memFree (void **mem) |
size_t | memGetSize (void *mem) |
void | memCleanup () |
Variables | |
struct memSegment * | segments = NULL |
struct memSegment |
Data Fields | ||
---|---|---|
enum rbColor | color | |
struct memSegment * | last | |
struct memSegment * | left | |
struct memSegment * | next | |
struct memSegment * | parent | |
void * | ptr | |
size_t | ref_count | |
struct memSegment * | right | |
size_t | size |
void cleanup | ( | struct memSegment * | node, |
int | depth | ||
) |
struct memSegment* deleteElement | ( | struct memSegment ** | tree, |
struct memSegment * | element | ||
) |
Definition at line 389 of file memory.c.
References memSegment::color, findInOrderSuccessor(), memSegment::last, memSegment::left, memSegment::next, memSegment::parent, rbBlack, rbRed, replaceNode(), memSegment::right, rotateLeft(), rotateRight(), sibling(), and memSegment::size.
Referenced by memMalloc().
struct memSegment* findElement | ( | struct memSegment * | tree, |
size_t | size | ||
) |
find element in tree
Definition at line 100 of file memory.c.
References memSegment::left, memSegment::right, and memSegment::size.
Referenced by memMalloc().
struct memSegment* findInOrderSuccessor | ( | struct memSegment * | tree | ) |
delete element from tree
find minimum of the right subtree aka leftmost leaf of right subtree aka left in-order successor. We return the parent of the element in the out argument parent. This can be NULL wenn calling.
2: *successor = {size = 80, ptr = 0x603ae0, color = rbRed, parent = 0x603160, left = 0x0, right = 0x0} 1: *node = {size = 70, ptr = 0x603a60, color = rbBlack, parent = 0x603070, left = 0x6030e0, right = 0x6031e0}
Definition at line 377 of file memory.c.
References memSegment::left, and memSegment::right.
Referenced by deleteElement().
struct memSegment* grandparent | ( | struct memSegment * | node | ) |
Definition at line 126 of file memory.c.
References memSegment::parent.
Referenced by insertElement(), and uncle().
struct memSegment* insertElement | ( | struct memSegment ** | tree, |
struct memSegment * | element | ||
) |
insert element in tree
Definition at line 246 of file memory.c.
References memSegment::color, grandparent(), memSegment::last, memSegment::left, memSegment::next, memSegment::parent, rbBlack, rbRed, memSegment::right, rotateLeft(), rotateRight(), memSegment::size, and uncle().
Referenced by memFree().
void* memCalloc | ( | size_t | nmemb, |
size_t | size | ||
) |
this is a really memory wasting solution....just to be able to use calloc, which might be faster then malloc/memset solution.
Maybe this is a bad idea, as we need to memset the buffer anyway if it comes from our tree, which hopefully should be the majority of cases.
Definition at line 818 of file memory.c.
References memMalloc(), and size.
Referenced by applicationCtor(), applicationSessionCleanup(), classClone(), classNewParams(), hash_pw(), httpMessageCtor(), httpResponseCtor(), and serverCtor().
void memCleanup | ( | ) |
Definition at line 862 of file memory.c.
References post(), and segmentFree().
Referenced by main().
void memFree | ( | void ** | mem | ) |
Definition at line 829 of file memory.c.
References insertElement(), and memSegment::ref_count.
size_t memGetSize | ( | void * | mem | ) |
Definition at line 849 of file memory.c.
References memSegment::size.
Referenced by httpWriterWrite().
void* memMalloc | ( | size_t | size | ) |
Definition at line 783 of file memory.c.
References deleteElement(), findElement(), newElement(), memSegment::ptr, and size.
Referenced by authLdapCtor(), cbufCtor(), configCtor(), configValueCtor(), controllerCurrentuserRead(), controllerLocRead(), controllerRandvalRead(), controllerSessinfoRead(), controllerUserRead(), controllerVersionRead(), credentialCtor(), hashValueCtor(), httpCookieCtor(), httpHeaderCtor(), httpParserHeader(), httpParserParse(), httpParserRequestVars(), httpRequestCtor(), httpResponse404(), httpResponse500(), httpResponseJson(), httpWorkerCtor(), httpWriterWrite(), loggerLog(), memCalloc(), newEle(), storageCtor(), storageGet(), userCtor(), userSerialize(), and userUnserialize().
void* memNewRef | ( | void * | mem | ) |
struct memSegment* newElement | ( | size_t | size | ) |
Definition at line 77 of file memory.c.
References memSegment::color, memSegment::last, memSegment::left, memSegment::next, memSegment::parent, memSegment::ptr, rbRed, memSegment::ref_count, memSegment::right, size, and memSegment::size.
Referenced by memMalloc().
void post | ( | struct memSegment * | tree, |
void(*)(struct memSegment *, int) | cb | ||
) |
Definition at line 666 of file memory.c.
References cb, memSegment::left, memSegment::parent, and memSegment::right.
Referenced by memCleanup().
void printElement | ( | struct memSegment * | node, |
int | depth | ||
) |
Definition at line 721 of file memory.c.
References memSegment::color, memSegment::next, memSegment::ptr, rbRed, and memSegment::size.
void replaceNode | ( | struct memSegment ** | tree, |
struct memSegment * | node1, | ||
struct memSegment * | node2 | ||
) |
Definition at line 221 of file memory.c.
References memSegment::left, memSegment::parent, and memSegment::right.
Referenced by deleteElement().
void rotateLeft | ( | struct memSegment ** | tree, |
struct memSegment * | node | ||
) |
Definition at line 169 of file memory.c.
References memSegment::left, memSegment::parent, and memSegment::right.
Referenced by deleteElement(), and insertElement().
void rotateRight | ( | struct memSegment ** | tree, |
struct memSegment * | node | ||
) |
Definition at line 195 of file memory.c.
References memSegment::left, memSegment::parent, and memSegment::right.
Referenced by deleteElement(), and insertElement().
|
static |
Definition at line 760 of file memory.c.
References memSegment::next.
Referenced by memCleanup().
struct memSegment* sibling | ( | struct memSegment * | node | ) |
Definition at line 152 of file memory.c.
References memSegment::left, memSegment::parent, and memSegment::right.
Referenced by deleteElement().
void traverse | ( | struct memSegment * | tree, |
void(*)(struct memSegment *, int) | cb | ||
) |
Definition at line 616 of file memory.c.
References cb, memSegment::left, memSegment::parent, and memSegment::right.
struct memSegment* uncle | ( | struct memSegment * | node | ) |
Definition at line 136 of file memory.c.
References grandparent(), memSegment::left, memSegment::parent, and memSegment::right.
Referenced by insertElement().
struct memSegment* segments = NULL |