12 Commits
Author SHA1 Message Date
Leonardo Vencovsky 6b57d8e949 Merge EXT into default code 2023-12-14 02:00:15 +01:00
Leonardo Vencovsky 47ece66520 Move everything out of src folder 2023-12-13 15:14:46 +01:00
Leonardo Vencovsky 2c1eb41280 Quickfix flags 2023-12-11 02:31:30 +01:00
Leonardo Vencovsky 53960a3bce List stabilization part 2 2023-12-10 20:44:17 +01:00
Leonardo Vencovsky e4dbeae46d List stabilization part 1 2023-12-10 20:44:17 +01:00
Leonardo Vencovsky 32deb8356c Add install dev deps target 2023-08-28 09:09:01 +02:00
Leonardo Vencovsky 3593957bb8 add phony targets 2023-08-21 08:56:45 +02:00
Leonardo Vencovsky a8735889c7 Quickfix for ALLOC_NODE 2023-03-09 16:51:48 +01:00
Leonardo Vencovsky 655b7fa825 Added FTABLE flag 2023-03-03 21:28:04 +01:00
Leonardo Vencovsky 78fe5c2b09 Libray 2023-02-28 16:42:49 +01:00
Leonardo Vencovsky 015d14216f Callbacks redone 2023-02-28 16:42:02 +01:00
Leonardo Vencovsky a46ba1f255 Add CNAME 2023-02-24 11:15:45 +01:00
153 changed files with 2717 additions and 4450 deletions

No files matched your search

+7
View File
@@ -8,6 +8,7 @@ help:
@echo - bench: runs benchmarks
@echo - docbuild: builds documentation to ./docs
@echo - docserve: serves mdbook docs
@echo - install_dev_deps: install dev dependencies
tests:
make -C ./tests
@@ -26,3 +27,9 @@ docbuild:
docserve:
mdbook serve documentation
install_dev_deps:
sudo apt install gcc make valgrind lcov clang-format hyperfine
cargo install mdbook
.PHONY: tests tests_dev format bench docbuild docserve install_dev_deps
+5 -1
View File
@@ -1,7 +1,11 @@
CC=gcc
INCLUDE=-I ../src
INCLUDE=-I ..
CFLAGS=-Wall -Wextra -Werror
benchmark: benchmark.c
$(CC) $(CFLAGS) $(INCLUDE) $< -o ./$@.exe -lm
./$@.exe
clean:
rm *.exe -f
rm *.txt -f
+3 -2
View File
@@ -1,4 +1,4 @@
INCLUDE=-I ../../../src
INCLUDE=-I ../../..
CFLAGS=-O3 -Wall -Wextra -Werror -DCOUNT=20000000 -DCMC_NO_CALLBACKS
# Install hyperfine
@@ -15,4 +15,5 @@ build:
g++ unorderedmap.cpp $(INCLUDE) -o unorderedmap.exe $(CFLAGS)
clean:
rm *.exe
rm *.exe -f
rm *.txt -f
+15 -21
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -65,28 +65,22 @@
* PFX - functions prefix
*/
/* Structs definition */
#include "cmc/bitset/struct.h"
#if !defined(CMC_STRUCT) && !defined(CMC_HEADER) && !defined(CMC_CODE)
#include "bitset/struct.h"
#include "bitset/header.h"
#include "bitset/code.h"
#endif
/* Function declaration */
#include "cmc/bitset/header.h"
#ifdef CMC_STRUCT
#include "bitset/struct.h"
#endif /* CMC_STRUCT */
/* Function implementation */
#include "cmc/bitset/code.h"
#ifdef CMC_HEADER
#include "bitset/header.h"
#endif /* CMC_HEADER */
/**
* Extensions
*
* INIT - Initializes the struct on the stack
* ITER - bitset iterator
* STR - Print helper functions
*/
#define CMC_EXT_BITSET_PARTS INIT, ITER, STR
/**/
#include "cmc/bitset/ext/struct.h"
/**/
#include "cmc/bitset/ext/header.h"
/**/
#include "cmc/bitset/ext/code.h"
#ifdef CMC_CODE
#include "bitset/code.h"
#endif /* CMC_CODE */
#include "cor/undef.h"
+14 -17
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -34,8 +34,7 @@ struct SNAME *CMC_(PFX, _new)(size_t n_bits)
return CMC_(PFX, _new_custom)(n_bits, NULL, NULL);
}
struct SNAME *CMC_(PFX, _new_custom)(size_t n_bits, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks)
struct SNAME *CMC_(PFX, _new_custom)(size_t n_bits, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -81,8 +80,7 @@ struct SNAME CMC_(PFX, _init)(size_t n_bits)
return CMC_(PFX, _init_custom)(n_bits, NULL, NULL);
}
struct SNAME CMC_(PFX, _init_custom)(size_t n_bits, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *CMC_UNUSED(callbacks))
struct SNAME CMC_(PFX, _init_custom)(size_t n_bits, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -132,8 +130,7 @@ void CMC_(PFX, _release)(struct SNAME _bitset_)
free(_bitset_.buffer);
}
void CMC_(PFX, _customize)(struct SNAME *_bitset_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks)
void CMC_(PFX, _customize)(struct SNAME *_bitset_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -169,7 +166,7 @@ bool CMC_(PFX, _set)(struct SNAME *_bitset_, size_t bit_index)
_bitset_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_bitset_, create);
CMC_CALLBACKS_CALL(_bitset_);
return true;
}
@@ -220,7 +217,7 @@ bool CMC_(PFX, _set_range)(struct SNAME *_bitset_, size_t from, size_t to)
_bitset_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_bitset_, create);
CMC_CALLBACKS_CALL(_bitset_);
return true;
}
@@ -243,7 +240,7 @@ bool CMC_(PFX, _clear)(struct SNAME *_bitset_, size_t bit_index)
_bitset_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_bitset_, delete);
CMC_CALLBACKS_CALL(_bitset_);
return true;
}
@@ -294,7 +291,7 @@ bool CMC_(PFX, _clear_range)(struct SNAME *_bitset_, size_t from, size_t to)
_bitset_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_bitset_, delete);
CMC_CALLBACKS_CALL(_bitset_);
return true;
}
@@ -317,7 +314,7 @@ bool CMC_(PFX, _flip)(struct SNAME *_bitset_, size_t bit_index)
_bitset_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_bitset_, update);
CMC_CALLBACKS_CALL(_bitset_);
return true;
}
@@ -368,7 +365,7 @@ bool CMC_(PFX, _flip_range)(struct SNAME *_bitset_, size_t from, size_t to)
_bitset_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_bitset_, update);
CMC_CALLBACKS_CALL(_bitset_);
return true;
}
@@ -408,7 +405,7 @@ bool CMC_(PFX, _set_all)(struct SNAME *_bitset_)
_bitset_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_bitset_, create);
CMC_CALLBACKS_CALL(_bitset_);
return true;
}
@@ -424,7 +421,7 @@ bool CMC_(PFX, _clear_all)(struct SNAME *_bitset_)
_bitset_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_bitset_, delete);
CMC_CALLBACKS_CALL(_bitset_);
return true;
}
@@ -440,7 +437,7 @@ bool CMC_(PFX, _flip_all)(struct SNAME *_bitset_)
_bitset_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_bitset_, create);
CMC_CALLBACKS_CALL(_bitset_);
return true;
}
@@ -507,7 +504,7 @@ bool CMC_(PFX, _impl_resize)(struct SNAME *_bitset_, size_t n_bits, bool do_resi
_bitset_->capacity = words;
CMC_CALLBACKS_CALL(_bitset_, resize);
CMC_CALLBACKS_CALL(_bitset_);
_bitset_->flag = CMC_FLAG_OK;
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -24,15 +24,12 @@
/* Collection Allocation and Deallocation */
struct SNAME *CMC_(PFX, _new)(size_t n_bits);
struct SNAME *CMC_(PFX, _new_custom)(size_t n_bits, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
struct SNAME *CMC_(PFX, _new_custom)(size_t n_bits, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
struct SNAME CMC_(PFX, _init)(size_t n_bits);
struct SNAME CMC_(PFX, _init_custom)(size_t n_bits, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
struct SNAME CMC_(PFX, _init_custom)(size_t n_bits, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _free)(struct SNAME *_bitset_);
void CMC_(PFX, _release)(struct SNAME _bitset_);
void CMC_(PFX, _customize)(struct SNAME *_bitset_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
void CMC_(PFX, _customize)(struct SNAME *_bitset_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
/* Collection Input and Output */
bool CMC_(PFX, _set)(struct SNAME *_bitset_, size_t bit_index);
bool CMC_(PFX, _set_range)(struct SNAME *_bitset_, size_t from, size_t to);
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -36,7 +36,7 @@ struct SNAME
/* Flags indicating errors or success */
int flag;
/* Custom allocation functions */
struct CMC_ALLOC_NODE_NAME *alloc;
CMC_ALLOC_TYPE alloc;
/* Custom callback functions */
CMC_CALLBACKS_DECL;
};
+4 -2
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -44,7 +44,6 @@
#endif
#include "core.h"
/**
* struct cmc_alloc_node
*
@@ -52,6 +51,9 @@
* functions. The cmc_alloc_node_default is the default heap allocator provided
* by the standard library.
*/
#define CMC_ALLOC_TYPE struct CMC_ALLOC_NODE_NAME *
static struct CMC_ALLOC_NODE_NAME
{
void *(*malloc)(size_t);
+1 -1
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+15 -37
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -35,49 +35,27 @@
#ifndef CMC_COR_CALLBACKS_H
#define CMC_COR_CALLBACKS_H
#ifdef CMC_CAMEL_CASE
#define CMC_CALLBACKS_NAME CMCCallbacks
#else
#define CMC_CALLBACKS_NAME cmc_callbacks
#endif
typedef void (*cmc_callback)(const char func_name[], void *self);
#define CMC_CALLBACK_TYPE cmc_callback
#ifdef CMC_NO_CALLBACKS
#ifdef CMC_CALLBACKS
#define CMC_CALLBACKS_DECL cmc_callback callbacks
#define CMC_CALLBACKS_MAYBE_UNUSED(param)
#define CMC_CALLBACKS_GET(ds) (ds)->callbacks
#define CMC_CALLBACKS_ASSIGN(ds, cb) CMC_CALLBACKS_GET(ds) = cb
#define CMC_CALLBACKS_CALL(ds) \
if (CMC_CALLBACKS_GET(ds)) \
CMC_CALLBACKS_GET(ds)(__func__, (void *)ds);
#else
#define CMC_CALLBACKS_DECL
#define CMC_CALLBACKS_MAYBE_UNUSED(param) CMC_UNUSED_PARAM(param) /* Prevent -Wunused-parameter */
#define CMC_CALLBACKS_GET(ds) NULL /* Helps with compatibility */
#define CMC_CALLBACKS_ASSIGN(ds, cb)
#define CMC_CALLBACKS_CALL(ds, cb)
#else
#define CMC_CALLBACKS_DECL struct CMC_CALLBACKS_NAME *callbacks
#define CMC_CALLBACKS_MAYBE_UNUSED(param)
#define CMC_CALLBACKS_GET(ds) (ds)->callbacks
#define CMC_CALLBACKS_ASSIGN(ds, cb) CMC_CALLBACKS_GET(ds) = cb
#define CMC_CALLBACKS_CALL(ds, cb) \
if (CMC_CALLBACKS_GET(ds) && CMC_CALLBACKS_GET(ds)->cb) \
CMC_CALLBACKS_GET(ds)->cb();
#define CMC_CALLBACKS_CALL(ds)
#endif
/**
* struct cmc_callbacks
*
* Callback node. Each collection will call one of these functions when:
* - create : an element was successfully added to the collection
* - read : the collection was successfully queried about an element
* - update : an element in the collection was successfully updated
* - delete : an element was successfully removed from the collection
* - resize : the collection was full and successfully resized
*/
struct CMC_CALLBACKS_NAME
{
void (*create)(void);
void (*read)(void);
void (*update)(void);
void (*delete)(void);
void (*resize)(void);
};
#endif /* CMC_COR_CALLBACKS_H */
+1 -1
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+3 -1
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -39,6 +39,8 @@
* Macros for tracing and debugging data structures when CMC_DEV is enabled
*/
#ifndef CMC_DEV_FCALL
#define CMC_DEV_FCALL cmc_log_trace("fcall")
#endif
#endif /* CMC_COR_DEV_H */
+5 -3
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -56,6 +56,7 @@ enum cmc_flags
CMC_FLAG_THREAD = 8, // Generic error regarding threads
CMC_FLAG_MUTEX = 9, // Generic error regarding mutexes
CMC_FLAG_FULL = 10, // When a collection that doesn't resize is full
CMC_FLAG_FTABLE = 11, // When a required ftable function is missing
};
// clang-format on
@@ -64,7 +65,8 @@ enum cmc_flags
*
* Maps the error codes to their character representation.
*/
CMC_UNUSED static const char *cmc_flags_to_str[11] = { "OK", "ALLOC", "EMPTY", "NOT_FOUND", "INVALID", "RANGE",
"DUPLICATE", "ERROR", "THREAD", "MUTEX", "FULL" };
CMC_UNUSED static const char *cmc_flags_to_str[12] = {
"OK", "ALLOC", "EMPTY", "NOT_FOUND", "INVALID", "RANGE", "DUPLICATE", "ERROR", "THREAD", "MUTEX", "FULL", "FTABLE"
};
#endif /* CMC_COR_FLAGS_H */
+1 -1
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+15 -21
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -65,28 +65,22 @@
* PFX - functions prefix
*/
/* Structs definition */
#include "cmc/deque/struct.h"
#if !defined(CMC_STRUCT) && !defined(CMC_HEADER) && !defined(CMC_CODE)
#include "deque/struct.h"
#include "deque/header.h"
#include "deque/code.h"
#endif
/* Function declaration */
#include "cmc/deque/header.h"
#ifdef CMC_STRUCT
#include "deque/struct.h"
#endif /* CMC_STRUCT */
/* Function implementation */
#include "cmc/deque/code.h"
#ifdef CMC_HEADER
#include "deque/header.h"
#endif /* CMC_HEADER */
/**
* Extensions
*
* INIT - Initializes the struct on the stack
* ITER - Deque iterator
* STR - Print helper functions
*/
#define CMC_EXT_DEQUE_PARTS INIT, ITER, STR
/**/
#include "cmc/deque/ext/struct.h"
/**/
#include "cmc/deque/ext/header.h"
/**/
#include "cmc/deque/ext/code.h"
#ifdef CMC_CODE
#include "deque/code.h"
#endif /* CMC_CODE */
#include "cor/undef.h"
+409 -13
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -34,8 +34,8 @@ struct SNAME *CMC_(PFX, _new)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_va
return CMC_(PFX, _new_custom)(capacity, f_val, NULL, NULL);
}
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -122,8 +122,72 @@ void CMC_(PFX, _free)(struct SNAME *_deque_)
_deque_->alloc->free(_deque_);
}
void CMC_(PFX, _customize)(struct SNAME *_deque_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks)
struct SNAME CMC_(PFX, _init)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
return CMC_(PFX, _init_custom)(capacity, f_val, NULL, NULL);
}
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);
struct SNAME _deque_ = { 0 };
if (capacity < 1)
return _deque_;
if (!f_val)
return _deque_;
if (!alloc)
alloc = &cmc_alloc_node_default;
_deque_.buffer = alloc->calloc(capacity, sizeof(V));
if (!_deque_.buffer)
return _deque_;
_deque_.capacity = capacity;
_deque_.count = 0;
_deque_.front = 0;
_deque_.back = 0;
_deque_.flag = CMC_FLAG_OK;
_deque_.f_val = f_val;
_deque_.alloc = alloc;
CMC_CALLBACKS_ASSIGN(&_deque_, callbacks);
return _deque_;
}
void CMC_(PFX, _release)(struct SNAME _deque_)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (_deque_.f_val->free)
{
for (size_t i = _deque_.front, j = 0; j < _deque_.count; j++)
{
_deque_.f_val->free(_deque_.buffer[i]);
i = (i + 1) % _deque_.capacity;
}
}
_deque_.alloc->free(_deque_.buffer);
}
void CMC_(PFX, _customize)(struct SNAME *_deque_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -160,7 +224,7 @@ bool CMC_(PFX, _push_front)(struct SNAME *_deque_, V value)
_deque_->count++;
_deque_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_deque_, create);
CMC_CALLBACKS_CALL(_deque_);
return true;
}
@@ -184,7 +248,7 @@ bool CMC_(PFX, _push_back)(struct SNAME *_deque_, V value)
_deque_->count++;
_deque_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_deque_, create);
CMC_CALLBACKS_CALL(_deque_);
return true;
}
@@ -208,7 +272,7 @@ bool CMC_(PFX, _pop_front)(struct SNAME *_deque_)
_deque_->count--;
_deque_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_deque_, delete);
CMC_CALLBACKS_CALL(_deque_);
return true;
}
@@ -232,7 +296,7 @@ bool CMC_(PFX, _pop_back)(struct SNAME *_deque_)
_deque_->count--;
_deque_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_deque_, delete);
CMC_CALLBACKS_CALL(_deque_);
return true;
}
@@ -251,7 +315,7 @@ V CMC_(PFX, _front)(struct SNAME *_deque_)
_deque_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_deque_, read);
CMC_CALLBACKS_CALL(_deque_);
return _deque_->buffer[_deque_->front];
}
@@ -270,7 +334,7 @@ V CMC_(PFX, _back)(struct SNAME *_deque_)
_deque_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_deque_, read);
CMC_CALLBACKS_CALL(_deque_);
return _deque_->buffer[(_deque_->back == 0) ? _deque_->capacity - 1 : _deque_->back - 1];
}
@@ -296,7 +360,7 @@ bool CMC_(PFX, _contains)(struct SNAME *_deque_, V value)
i = (i + 1) % _deque_->capacity;
}
CMC_CALLBACKS_CALL(_deque_, read);
CMC_CALLBACKS_CALL(_deque_);
return result;
}
@@ -387,7 +451,7 @@ bool CMC_(PFX, _resize)(struct SNAME *_deque_, size_t capacity)
success:
CMC_CALLBACKS_CALL(_deque_, resize);
CMC_CALLBACKS_CALL(_deque_);
return true;
}
@@ -460,3 +524,335 @@ bool CMC_(PFX, _equals)(struct SNAME *_deque1_, struct SNAME *_deque2_)
return true;
}
/**
* ITER
*
* Deque bi-directional iterator.
*/
#ifdef CMC_EXT_ITER
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME *target)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
struct CMC_DEF_ITER(SNAME) iter;
iter.target = target;
iter.cursor = target->front;
iter.index = 0;
iter.start = true;
iter.end = CMC_(PFX, _empty)(target);
return iter;
}
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME *target)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
struct CMC_DEF_ITER(SNAME) iter;
iter.target = target;
if (!CMC_(PFX, _empty)(target))
{
if (iter.target->back == 0)
iter.cursor = iter.target->capacity - 1;
else
iter.cursor = iter.target->back - 1;
iter.index = iter.target->count - 1;
}
else
{
iter.cursor = 0;
iter.index = 0;
}
iter.start = CMC_(PFX, _empty)(target);
iter.end = true;
return iter;
}
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
return CMC_(PFX, _empty)(iter->target) || iter->start;
}
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
return CMC_(PFX, _empty)(iter->target) || iter->end;
}
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (!CMC_(PFX, _empty)(iter->target))
{
iter->cursor = iter->target->front;
iter->index = 0;
iter->start = true;
iter->end = false;
return true;
}
return false;
}
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (!CMC_(PFX, _empty)(iter->target))
{
if (iter->target->back == 0)
iter->cursor = iter->target->capacity - 1;
else
iter->cursor = iter->target->back - 1;
iter->index = iter->target->count - 1;
iter->start = false;
iter->end = true;
return true;
}
return false;
}
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (iter->end)
return false;
if (iter->index + 1 == iter->target->count)
{
iter->end = true;
return false;
}
iter->start = CMC_(PFX, _empty)(iter->target);
iter->cursor = (iter->cursor + 1) % (iter->target->capacity);
iter->index++;
return true;
}
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (iter->start)
return false;
if (iter->index == 0)
{
iter->start = true;
return false;
}
iter->end = CMC_(PFX, _empty)(iter->target);
iter->cursor = (iter->cursor == 0) ? iter->target->capacity - 1 : iter->cursor - 1;
iter->index--;
return true;
}
/* Returns true only if the iterator moved */
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (iter->end)
return false;
if (iter->index + 1 == iter->target->count)
{
iter->end = true;
return false;
}
if (steps == 0 || iter->index + steps >= iter->target->count)
return false;
iter->start = CMC_(PFX, _empty)(iter->target);
iter->index += steps;
iter->cursor = (iter->cursor + steps) % iter->target->capacity;
return true;
}
/* Returns true only if the iterator moved */
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (iter->start)
return false;
if (iter->index == 0)
{
iter->start = true;
return false;
}
if (steps == 0 || iter->index < steps)
return false;
iter->end = CMC_(PFX, _empty)(iter->target);
iter->index -= steps;
/* Prevent underflow */
if (iter->cursor < steps)
iter->cursor += iter->target->capacity;
iter->cursor -= steps;
return true;
}
/* Returns true only if the iterator was able to be positioned at the */
/* given index */
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (index >= iter->target->count)
return false;
if (iter->index > index)
return CMC_(PFX, _iter_rewind)(iter, iter->index - index);
else if (iter->index < index)
return CMC_(PFX, _iter_advance)(iter, index - iter->index);
return true;
}
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (CMC_(PFX, _empty)(iter->target))
return (V){ 0 };
return iter->target->buffer[iter->cursor];
}
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (CMC_(PFX, _empty)(iter->target))
return NULL;
return &(iter->target->buffer[iter->cursor]);
}
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
return iter->index;
}
#endif /* CMC_EXT_ITER */
/**
* STR
*
* Print helper functions.
*/
#ifdef CMC_EXT_STR
bool CMC_(PFX, _to_string)(struct SNAME *_deque_, FILE *fptr)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
struct SNAME *d_ = _deque_;
return 0 <= fprintf(fptr,
"struct %s<%s> "
"at %p { "
"buffer:%p, "
"capacity:%" PRIuMAX ", "
"count:%" PRIuMAX ", "
"front:%" PRIuMAX ", "
"back:%" PRIuMAX ", "
"flag:%d, "
"f_val:%p, "
"alloc:%p, "
"callbacks:%p }",
CMC_TO_STRING(SNAME), CMC_TO_STRING(V), d_, d_->buffer, d_->capacity, d_->count, d_->front,
d_->back, d_->flag, d_->f_val, d_->alloc, CMC_CALLBACKS_GET(d_));
}
bool CMC_(PFX, _print)(struct SNAME *_deque_, FILE *fptr, const char *start, const char *separator, const char *end)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
fprintf(fptr, "%s", start);
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++)
{
if (!_deque_->f_val->str(fptr, _deque_->buffer[i]))
return false;
i = (i + 1) % _deque_->capacity;
if (j + 1 < _deque_->count)
fprintf(fptr, "%s", separator);
}
fprintf(fptr, "%s", end);
return true;
}
#endif /* CMC_EXT_STR */
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -22,20 +22,55 @@
* SOFTWARE.
*/
/**
* INIT
*
* The part 'INIT' gives a new way of initializing a collection. The collection
* struct is not heap allocated, only its internal structure (nodes, buffers).
*/
#ifdef CMC_EXT_INIT
/* Value function table */
struct CMC_DEF_FVAL(SNAME)
{
/* Comparator function */
CMC_DEF_FTAB_CMP(V);
/* Copy function */
CMC_DEF_FTAB_CPY(V);
/* To string function */
CMC_DEF_FTAB_STR(V);
/* Free from memory function */
CMC_DEF_FTAB_FREE(V);
/* Hash function */
CMC_DEF_FTAB_HASH(V);
/* Priority function */
CMC_DEF_FTAB_PRI(V);
};
/* Collection Allocation and Deallocation */
struct SNAME *CMC_(PFX, _new)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _clear)(struct SNAME *_deque_);
void CMC_(PFX, _free)(struct SNAME *_deque_);
/* Collection Allocation and Deallocation */
struct SNAME CMC_(PFX, _init)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks);
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _release)(struct SNAME _deque_);
#endif /* CMC_EXT_INIT */
/* Customization of Allocation and Callbacks */
void CMC_(PFX, _customize)(struct SNAME *_deque_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
/* Collection Input and Output */
bool CMC_(PFX, _push_front)(struct SNAME *_deque_, V value);
bool CMC_(PFX, _push_back)(struct SNAME *_deque_, V value);
bool CMC_(PFX, _pop_front)(struct SNAME *_deque_);
bool CMC_(PFX, _pop_back)(struct SNAME *_deque_);
/* Element Access */
V CMC_(PFX, _front)(struct SNAME *_deque_);
V CMC_(PFX, _back)(struct SNAME *_deque_);
/* Collection State */
bool CMC_(PFX, _contains)(struct SNAME *_deque_, V value);
bool CMC_(PFX, _empty)(struct SNAME *_deque_);
bool CMC_(PFX, _full)(struct SNAME *_deque_);
size_t CMC_(PFX, _count)(struct SNAME *_deque_);
size_t CMC_(PFX, _capacity)(struct SNAME *_deque_);
int CMC_(PFX, _flag)(struct SNAME *_deque_);
/* Collection Utility */
bool CMC_(PFX, _resize)(struct SNAME *_deque_, size_t capacity);
struct SNAME *CMC_(PFX, _copy_of)(struct SNAME *_deque_);
bool CMC_(PFX, _equals)(struct SNAME *_deque1_, struct SNAME *_deque2_);
/**
* ITER
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -39,7 +39,31 @@ struct SNAME
/* Functions Table */
struct CMC_DEF_FVAL(SNAME) * f_val;
/* Custom allocation functions */
struct CMC_ALLOC_NODE_NAME *alloc;
CMC_ALLOC_TYPE alloc;
/* Custom callback functions */
CMC_CALLBACKS_DECL;
};
/**
* ITER
*
* Deque bi-directional iterator.
*/
#ifdef CMC_EXT_ITER
/* Deque Iterator */
struct CMC_DEF_ITER(SNAME)
{
/* Target deque */
struct SNAME *target;
/* Cursor's position (index) */
size_t cursor;
/* Keeps track of relative index to the iteration of elements */
size_t index;
/* If the iterator has reached the start of the iteration */
bool start;
/* If the iterator has reached the end of the iteration */
bool end;
};
#endif /* CMC_EXT_ITER */
+15 -21
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -62,28 +62,22 @@
* PFX - functions prefix
*/
/* Structs definition */
#include "cmc/hashbidimap/struct.h"
#if !defined(CMC_STRUCT) && !defined(CMC_HEADER) && !defined(CMC_CODE)
#include "hashbidimap/struct.h"
#include "hashbidimap/header.h"
#include "hashbidimap/code.h"
#endif
/* Function declaration */
#include "cmc/hashbidimap/header.h"
#ifdef CMC_STRUCT
#include "hashbidimap/struct.h"
#endif /* CMC_STRUCT */
/* Function implementation */
#include "cmc/hashbidimap/code.h"
#ifdef CMC_HEADER
#include "hashbidimap/header.h"
#endif /* CMC_HEADER */
/**
* Extensions
*
* INIT - Initializes the struct on the stack
* ITER - Hashbidimap iterator
* STR - Print helper functions
*/
#define CMC_EXT_HASHBIDIMAP_PARTS INIT, ITER, STR
/**/
#include "cmc/hashbidimap/ext/struct.h"
/**/
#include "cmc/hashbidimap/ext/header.h"
/**/
#include "cmc/hashbidimap/ext/code.h"
#ifdef CMC_CODE
#include "hashbidimap/code.h"
#endif /* CMC_CODE */
#include "cor/undef.h"
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -43,8 +43,8 @@ struct SNAME *CMC_(PFX, _new)(size_t capacity, double load, struct CMC_DEF_FKEY(
}
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks)
struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -134,7 +134,73 @@ void CMC_(PFX, _free)(struct SNAME *_map_)
_map_->alloc->free(_map_);
}
void CMC_(PFX, _customize)(struct SNAME *_map_, struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
struct SNAME CMC_(PFX, _init)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
return CMC_(PFX, _init_custom)(capacity, load, f_key, f_val, NULL, NULL);
}
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);
struct SNAME _map_ = { 0 };
if (capacity == 0 || load <= 0 || load >= 1)
return _map_;
/* Prevent integer overflow */
if (capacity >= (double)UINTMAX_MAX * load)
return _map_;
if (!f_key || !f_val)
return _map_;
size_t real_capacity = CMC_(PFX, _impl_calculate_size)(capacity / load);
if (!alloc)
alloc = &cmc_alloc_node_default;
_map_.buffer = alloc->calloc(real_capacity, sizeof(struct CMC_DEF_ENTRY(SNAME) *[2]));
if (!_map_.buffer)
return _map_;
_map_.count = 0;
_map_.capacity = real_capacity;
_map_.load = load;
_map_.flag = CMC_FLAG_OK;
_map_.f_key = f_key;
_map_.f_val = f_val;
_map_.flag = CMC_FLAG_OK;
_map_.alloc = alloc;
CMC_CALLBACKS_ASSIGN(&_map_, callbacks);
return _map_;
}
void CMC_(PFX, _release)(struct SNAME _map_)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
CMC_(PFX, _clear)(&_map_);
_map_.alloc->free(_map_.buffer);
}
void CMC_(PFX, _customize)(struct SNAME *_map_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -193,7 +259,7 @@ bool CMC_(PFX, _insert)(struct SNAME *_map_, K key, V value)
_map_->count++;
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, create);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -260,7 +326,7 @@ success:
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, update);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -328,7 +394,7 @@ success:
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, update);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -377,7 +443,7 @@ bool CMC_(PFX, _remove_by_key)(struct SNAME *_map_, K key, K *out_key, V *out_va
_map_->count--;
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, delete);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -426,7 +492,7 @@ bool CMC_(PFX, _remove_by_val)(struct SNAME *_map_, V val, K *out_key, V *out_va
_map_->count--;
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, delete);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -447,7 +513,7 @@ K CMC_(PFX, _get_key)(struct SNAME *_map_, V val)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return (*entry)->key;
}
@@ -468,7 +534,7 @@ V CMC_(PFX, _get_val)(struct SNAME *_map_, K key)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return (*entry)->value;
}
@@ -483,7 +549,7 @@ bool CMC_(PFX, _contains_key)(struct SNAME *_map_, K key)
bool result = CMC_(PFX, _impl_get_entry_by_key)(_map_, key) != NULL;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return result;
}
@@ -498,7 +564,7 @@ bool CMC_(PFX, _contains_val)(struct SNAME *_map_, V val)
bool result = CMC_(PFX, _impl_get_entry_by_val)(_map_, val) != NULL;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return result;
}
@@ -649,7 +715,7 @@ bool CMC_(PFX, _resize)(struct SNAME *_map_, size_t capacity)
success:
CMC_CALLBACKS_CALL(_map_, resize);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -959,3 +1025,377 @@ static size_t CMC_(PFX, _impl_calculate_size)(size_t required)
return cmc_hashtable_primes[i];
}
/**
* ITER
*
* Hashbidimap bi-directional iterator.
*/
#ifdef CMC_EXT_ITER
struct CMC_DEF_ITER(SNAME) * CMC_(PFX, _iter_new)(struct SNAME *target)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
struct CMC_DEF_ITER(SNAME) *iter = target->alloc->malloc(sizeof(struct CMC_DEF_ITER(SNAME)));
if (!iter)
return NULL;
CMC_(PFX, _iter_init)(iter, target);
return iter;
}
void CMC_(PFX, _iter_free)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
iter->target->alloc->free(iter);
}
void CMC_(PFX, _iter_init)(struct CMC_DEF_ITER(SNAME) * iter, struct SNAME *target)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
memset(iter, 0, sizeof(struct CMC_DEF_ITER(SNAME)));
iter->target = target;
iter->start = true;
iter->end = CMC_(PFX, _empty)(target);
if (!CMC_(PFX, _empty)(target))
{
for (size_t i = 0; i < target->capacity; i++)
{
struct CMC_DEF_ENTRY(SNAME) *entry = target->buffer[i][0];
if (entry && entry != CMC_ENTRY_DELETED)
{
iter->first = i;
break;
}
}
iter->cursor = iter->first;
for (size_t i = target->capacity; i > 0; i--)
{
struct CMC_DEF_ENTRY(SNAME) *entry = target->buffer[i - 1][0];
if (entry && entry != CMC_ENTRY_DELETED)
{
iter->last = i - 1;
break;
}
}
}
}
bool CMC_(PFX, _iter_start)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
return CMC_(PFX, _empty)(iter->target) || iter->start;
}
bool CMC_(PFX, _iter_end)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
return CMC_(PFX, _empty)(iter->target) || iter->end;
}
void CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (!CMC_(PFX, _empty)(iter->target))
{
iter->cursor = iter->first;
iter->index = 0;
iter->start = true;
iter->end = false;
}
}
void CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (!CMC_(PFX, _empty)(iter->target))
{
iter->cursor = iter->last;
iter->index = iter->target->count - 1;
iter->start = false;
iter->end = true;
}
}
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (iter->end)
return false;
if (iter->index + 1 == iter->target->count)
{
iter->end = true;
return false;
}
iter->start = CMC_(PFX, _empty)(iter->target);
struct CMC_DEF_ENTRY(SNAME) *scan = iter->target->buffer[iter->cursor][0];
iter->index++;
while (1)
{
iter->cursor++;
scan = iter->target->buffer[iter->cursor][0];
if (scan != NULL && scan != CMC_ENTRY_DELETED)
break;
}
return true;
}
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (iter->start)
return false;
if (iter->index == 0)
{
iter->start = true;
return false;
}
iter->end = CMC_(PFX, _empty)(iter->target);
struct CMC_DEF_ENTRY(SNAME) *scan = iter->target->buffer[iter->cursor][0];
iter->index--;
while (1)
{
iter->cursor--;
scan = iter->target->buffer[iter->cursor][0];
if (scan != NULL && scan != CMC_ENTRY_DELETED)
break;
}
return true;
}
/* Returns true only if the iterator moved */
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (iter->end)
return false;
if (iter->index + 1 == iter->target->count)
{
iter->end = true;
return false;
}
if (steps == 0 || iter->index + steps >= iter->target->count)
return false;
for (size_t i = 0; i < steps; i++)
CMC_(PFX, _iter_next)(iter);
return true;
}
/* Returns true only if the iterator moved */
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (iter->start)
return false;
if (iter->index == 0)
{
iter->start = true;
return false;
}
if (steps == 0 || iter->index < steps)
return false;
for (size_t i = 0; i < steps; i++)
CMC_(PFX, _iter_prev)(iter);
return true;
}
/* Returns true only if the iterator was able to be positioned at */
/* the given index */
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (index >= iter->target->count)
return false;
if (iter->index > index)
return CMC_(PFX, _iter_rewind)(iter, iter->index - index);
else if (iter->index < index)
return CMC_(PFX, _iter_advance)(iter, index - iter->index);
return true;
}
K CMC_(PFX, _iter_key)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (CMC_(PFX, _empty)(iter->target))
{
iter->target->flag = CMC_FLAG_EMPTY;
return (K){ 0 };
}
return iter->target->buffer[iter->cursor][0]->key;
}
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (CMC_(PFX, _empty)(iter->target))
{
iter->target->flag = CMC_FLAG_EMPTY;
return (V){ 0 };
}
return iter->target->buffer[iter->cursor][0]->value;
}
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
return iter->index;
}
#endif /* CMC_EXT_ITER */
/**
* STR
*
* Print helper functions.
*/
#ifdef CMC_EXT_STR
bool CMC_(PFX, _to_string)(struct SNAME *_map_, FILE *fptr)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
struct SNAME *m_ = _map_;
return 0 <= fprintf(fptr,
"struct %s<%s, %s> "
"at %p { "
"buffer:%p, "
"capacity:%" PRIuMAX ", "
"count:%" PRIuMAX ", "
"load:%lf, "
"flag:%d, "
"f_key:%p, "
"f_val:%p, "
"alloc:%p, "
"callbacks:%p }",
CMC_TO_STRING(SNAME), CMC_TO_STRING(K), CMC_TO_STRING(V), m_, m_->buffer, m_->capacity,
m_->count, m_->load, m_->flag, m_->f_key, m_->f_val, m_->alloc, CMC_CALLBACKS_GET(m_));
}
bool CMC_(PFX, _print)(struct SNAME *_map_, FILE *fptr, const char *start, const char *separator, const char *end,
const char *key_val_sep)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
fprintf(fptr, "%s", start);
size_t last = 0;
for (size_t i = _map_->capacity; i > 0; i--)
{
struct CMC_DEF_ENTRY(SNAME) *entry = _map_->buffer[i - 1][0];
if (entry && entry != CMC_ENTRY_DELETED)
{
last = i - 1;
break;
}
}
for (size_t i = 0; i < _map_->capacity; i++)
{
struct CMC_DEF_ENTRY(SNAME) *entry = _map_->buffer[i][0];
if (entry && entry != CMC_ENTRY_DELETED)
{
if (!_map_->f_key->str(fptr, entry->key))
return false;
fprintf(fptr, "%s", key_val_sep);
if (!_map_->f_val->str(fptr, entry->value))
return false;
if (i + 1 < last)
fprintf(fptr, "%s", separator);
}
}
fprintf(fptr, "%s", end);
return true;
}
#endif /* CMC_EXT_STR */
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -60,13 +60,19 @@ struct CMC_DEF_FVAL(SNAME)
struct SNAME *CMC_(PFX, _new)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _clear)(struct SNAME *_map_);
void CMC_(PFX, _free)(struct SNAME *_map_);
/* Collection Allocation and Deallocation */
struct SNAME CMC_(PFX, _init)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _release)(struct SNAME _map_);
/* Customization of Allocation and Callbacks */
void CMC_(PFX, _customize)(struct SNAME *_map_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
void CMC_(PFX, _customize)(struct SNAME *_map_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
/* Collection Input and Output */
bool CMC_(PFX, _insert)(struct SNAME *_map_, K key, V value);
bool CMC_(PFX, _update_key)(struct SNAME *_map_, V val, K new_key);
@@ -89,3 +95,49 @@ int CMC_(PFX, _flag)(struct SNAME *_map_);
bool CMC_(PFX, _resize)(struct SNAME *_map_, size_t capacity);
struct SNAME *CMC_(PFX, _copy_of)(struct SNAME *_map_);
bool CMC_(PFX, _equals)(struct SNAME *_map1_, struct SNAME *_map2_);
/**
* ITER
*
* Hashbidimap bi-directional iterator.
*/
#ifdef CMC_EXT_ITER
/* Iterator Functions */
/* Iterator Allocation and Deallocation */
struct CMC_DEF_ITER(SNAME) * CMC_(PFX, _iter_new)(struct SNAME *target);
void CMC_(PFX, _iter_free)(struct CMC_DEF_ITER(SNAME) * iter);
/* Iterator Initialization */
void CMC_(PFX, _iter_init)(struct CMC_DEF_ITER(SNAME) * iter, struct SNAME *target);
/* Iterator State */
bool CMC_(PFX, _iter_start)(struct CMC_DEF_ITER(SNAME) * iter);
bool CMC_(PFX, _iter_end)(struct CMC_DEF_ITER(SNAME) * iter);
/* Iterator Movement */
void CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter);
void CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter);
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter);
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter);
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps);
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps);
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index);
/* Iterator Access */
K CMC_(PFX, _iter_key)(struct CMC_DEF_ITER(SNAME) * iter);
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter);
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
#endif /* CMC_EXT_ITER */
/**
* STR
*
* Print helper functions.
*/
#ifdef CMC_EXT_STR
/* Debug prints the struct to fptr */
bool CMC_(PFX, _to_string)(struct SNAME *_map_, FILE *fptr);
/* Prints each item in the hashbidimap as an array */
bool CMC_(PFX, _print)(struct SNAME *_map_, FILE *fptr, const char *start, const char *separator, const char *end,
const char *key_val_sep);
#endif /* CMC_EXT_STR */
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -39,7 +39,7 @@ struct SNAME
/* Value function table */
struct CMC_DEF_FVAL(SNAME) * f_val;
/* Custom allocation functions */
struct CMC_ALLOC_NODE_NAME *alloc;
CMC_ALLOC_TYPE alloc;
/* Custom callback functions */
CMC_CALLBACKS_DECL;
/* Methods */
@@ -67,3 +67,31 @@ struct CMC_DEF_ENTRY(SNAME)
/* ref[1] is relative to V -> K */
struct CMC_DEF_ENTRY(SNAME) * *ref[2];
};
/**
* ITER
*
* Hashbidimap bi-directional iterator.
*/
#ifdef CMC_EXT_ITER
/* HashBidiMap Iterator */
struct CMC_DEF_ITER(SNAME)
{
/* Target hashbidimap */
struct SNAME *target;
/* Cursor's position (index) */
size_t cursor;
/* Keeps track of relative index to the iteration of elements */
size_t index;
/* The index of the first element */
size_t first;
/* The index of the last element */
size_t last;
/* If the iterator has reached the start of the iteration */
bool start;
/* If the iterator has reached the end of the iteration */
bool end;
};
#endif /* CMC_EXT_ITER */
+15 -21
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -55,28 +55,22 @@
* PFX - functions prefix
*/
/* Structs definition */
#include "cmc/hashmap/struct.h"
#if !defined(CMC_STRUCT) && !defined(CMC_HEADER) && !defined(CMC_CODE)
#include "hashmap/struct.h"
#include "hashmap/header.h"
#include "hashmap/code.h"
#endif
/* Function declaration */
#include "cmc/hashmap/header.h"
#ifdef CMC_STRUCT
#include "hashmap/struct.h"
#endif /* CMC_STRUCT */
/* Function implementation */
#include "cmc/hashmap/code.h"
#ifdef CMC_HEADER
#include "hashmap/header.h"
#endif /* CMC_HEADER */
/**
* Extensions
*
* INIT - Initializes the struct on the stack
* ITER - hashmap iterator
* STR - Print helper functions
*/
#define CMC_EXT_HASHMAP_PARTS INIT, ITER, STR
/**/
#include "cmc/hashmap/ext/struct.h"
/**/
#include "cmc/hashmap/ext/header.h"
/**/
#include "cmc/hashmap/ext/code.h"
#ifdef CMC_CODE
#include "hashmap/code.h"
#endif /* CMC_CODE */
#include "cor/undef.h"
+494 -13
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -33,8 +33,8 @@ struct SNAME *CMC_(PFX, _new)(size_t capacity, double load, struct CMC_DEF_FKEY(
}
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks)
struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -136,7 +136,82 @@ void CMC_(PFX, _free)(struct SNAME *_map_)
_map_->alloc->free(_map_);
}
void CMC_(PFX, _customize)(struct SNAME *_map_, struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
struct SNAME CMC_(PFX, _init)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
return CMC_(PFX, _init_custom)(capacity, load, f_key, f_val, NULL, NULL);
}
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
CMC_CALLBACKS_MAYBE_UNUSED(callbacks);
struct SNAME _map_ = { 0 };
if (capacity == 0 || load <= 0 || load >= 1)
return _map_;
/* Prevent integer overflow */
if (capacity >= (double)UINTMAX_MAX * load)
return _map_;
if (!f_key || !f_val)
return _map_;
size_t real_capacity = CMC_(PFX, _impl_calculate_size)(capacity / load);
if (!alloc)
alloc = &cmc_alloc_node_default;
_map_.buffer = alloc->calloc(real_capacity, sizeof(struct CMC_DEF_ENTRY(SNAME)));
if (!_map_.buffer)
return _map_;
_map_.count = 0;
_map_.capacity = real_capacity;
_map_.load = load;
_map_.flag = CMC_FLAG_OK;
_map_.f_key = f_key;
_map_.f_val = f_val;
_map_.alloc = alloc;
CMC_CALLBACKS_ASSIGN(&_map_, callbacks);
return _map_;
}
void CMC_(PFX, _release)(struct SNAME _map_)
{
if (_map_.f_key->free || _map_.f_val->free)
{
for (size_t i = 0; i < _map_.capacity; i++)
{
struct CMC_DEF_ENTRY(SNAME) *entry = &(_map_.buffer[i]);
if (entry->state == CMC_ES_FILLED)
{
if (_map_.f_key->free)
_map_.f_key->free(entry->key);
if (_map_.f_val->free)
_map_.f_val->free(entry->value);
}
}
}
_map_.alloc->free(_map_.buffer);
}
void CMC_(PFX, _customize)(struct SNAME *_map_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -221,7 +296,7 @@ bool CMC_(PFX, _insert)(struct SNAME *_map_, K key, V value)
_map_->count++;
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, create);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -253,7 +328,7 @@ bool CMC_(PFX, _update)(struct SNAME *_map_, K key, V new_value, V *old_value)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, update);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -289,7 +364,7 @@ bool CMC_(PFX, _remove)(struct SNAME *_map_, K key, V *out_value)
_map_->count--;
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, delete);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -335,7 +410,7 @@ bool CMC_(PFX, _max)(struct SNAME *_map_, K *key, V *value)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -381,7 +456,7 @@ bool CMC_(PFX, _min)(struct SNAME *_map_, K *key, V *value)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -408,7 +483,7 @@ V CMC_(PFX, _get)(struct SNAME *_map_, K key)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return entry->value;
}
@@ -435,7 +510,7 @@ V *CMC_(PFX, _get_ref)(struct SNAME *_map_, K key)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return &(entry->value);
}
@@ -450,7 +525,7 @@ bool CMC_(PFX, _contains)(struct SNAME *_map_, K key)
bool result = CMC_(PFX, _impl_get_entry)(_map_, key) != NULL;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return result;
}
@@ -587,7 +662,7 @@ bool CMC_(PFX, _resize)(struct SNAME *_map_, size_t capacity)
success:
CMC_CALLBACKS_CALL(_map_, resize);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -726,3 +801,409 @@ static size_t CMC_(PFX, _impl_calculate_size)(size_t required)
return cmc_hashtable_primes[i];
}
/**
* ITER
*
* Hashmap bi-directional iterator.
*/
#ifdef CMC_EXT_ITER
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME *target)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
struct CMC_DEF_ITER(SNAME) iter;
iter.target = target;
iter.cursor = 0;
iter.index = 0;
iter.first = 0;
iter.last = 0;
iter.start = true;
iter.end = CMC_(PFX, _empty)(target);
if (!CMC_(PFX, _empty)(target))
{
for (size_t i = 0; i < target->capacity; i++)
{
if (target->buffer[i].state == CMC_ES_FILLED)
{
iter.first = i;
break;
}
}
iter.cursor = iter.first;
for (size_t i = target->capacity; i > 0; i--)
{
if (target->buffer[i - 1].state == CMC_ES_FILLED)
{
iter.last = i - 1;
break;
}
}
}
return iter;
}
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME *target)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
struct CMC_DEF_ITER(SNAME) iter;
iter.target = target;
iter.cursor = 0;
iter.index = 0;
iter.first = 0;
iter.last = 0;
iter.start = CMC_(PFX, _empty)(target);
iter.end = true;
if (!CMC_(PFX, _empty)(target))
{
for (size_t i = 0; i < target->capacity; i++)
{
if (target->buffer[i].state == CMC_ES_FILLED)
{
iter.first = i;
break;
}
}
for (size_t i = target->capacity; i > 0; i--)
{
if (target->buffer[i - 1].state == CMC_ES_FILLED)
{
iter.last = i - 1;
break;
}
}
iter.cursor = iter.last;
iter.index = target->count - 1;
}
return iter;
}
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
return CMC_(PFX, _empty)(iter->target) || iter->start;
}
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
return CMC_(PFX, _empty)(iter->target) || iter->end;
}
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (!CMC_(PFX, _empty)(iter->target))
{
iter->cursor = iter->first;
iter->index = 0;
iter->start = true;
iter->end = CMC_(PFX, _empty)(iter->target);
return true;
}
return false;
}
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (!CMC_(PFX, _empty)(iter->target))
{
iter->cursor = iter->last;
iter->index = iter->target->count - 1;
iter->start = CMC_(PFX, _empty)(iter->target);
iter->end = true;
return true;
}
return false;
}
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (iter->end)
return false;
if (iter->index + 1 == iter->target->count)
{
iter->end = true;
return false;
}
iter->start = CMC_(PFX, _empty)(iter->target);
struct CMC_DEF_ENTRY(SNAME) *scan = &(iter->target->buffer[iter->cursor]);
iter->index++;
while (1)
{
iter->cursor++;
scan = &(iter->target->buffer[iter->cursor]);
if (scan->state == CMC_ES_FILLED)
break;
}
return true;
}
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (iter->start)
return false;
if (iter->index == 0)
{
iter->start = true;
return false;
}
iter->end = CMC_(PFX, _empty)(iter->target);
struct CMC_DEF_ENTRY(SNAME) *scan = &(iter->target->buffer[iter->cursor]);
iter->index--;
while (1)
{
iter->cursor--;
scan = &(iter->target->buffer[iter->cursor]);
if (scan->state == CMC_ES_FILLED)
break;
}
return true;
}
/* Returns true only if the iterator moved */
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (iter->end)
return false;
if (iter->index + 1 == iter->target->count)
{
iter->end = true;
return false;
}
if (steps == 0 || iter->index + steps >= iter->target->count)
return false;
for (size_t i = 0; i < steps; i++)
CMC_(PFX, _iter_next)(iter);
return true;
}
/* Returns true only if the iterator moved */
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (iter->start)
return false;
if (iter->index == 0)
{
iter->start = true;
return false;
}
if (steps == 0 || iter->index < steps)
return false;
for (size_t i = 0; i < steps; i++)
CMC_(PFX, _iter_prev)(iter);
return true;
}
/* Returns true only if the iterator was able to be positioned at the */
/* given index */
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (index >= iter->target->count)
return false;
if (iter->index > index)
return CMC_(PFX, _iter_rewind)(iter, iter->index - index);
else if (iter->index < index)
return CMC_(PFX, _iter_advance)(iter, index - iter->index);
return true;
}
K CMC_(PFX, _iter_key)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (CMC_(PFX, _empty)(iter->target))
return (K){ 0 };
return iter->target->buffer[iter->cursor].key;
}
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (CMC_(PFX, _empty)(iter->target))
return (V){ 0 };
return iter->target->buffer[iter->cursor].value;
}
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (CMC_(PFX, _empty)(iter->target))
return NULL;
return &(iter->target->buffer[iter->cursor].value);
}
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
return iter->index;
}
#endif /* CMC_EXT_ITER */
/**
* STR
*
* Print helper functions.
*/
#ifdef CMC_EXT_STR
bool CMC_(PFX, _to_string)(struct SNAME *_map_, FILE *fptr)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
struct SNAME *m_ = _map_;
return 0 <= fprintf(fptr,
"struct %s<%s, %s> "
"at %p { "
"buffer:%p, "
"capacity:%" PRIuMAX ", "
"count:%" PRIuMAX ", "
"load:%lf, "
"flag:%d, "
"f_key:%p, "
"f_val:%p, "
"alloc:%p, "
"callbacks:%p }",
CMC_TO_STRING(SNAME), CMC_TO_STRING(K), CMC_TO_STRING(V), m_, m_->buffer, m_->capacity,
m_->count, m_->load, m_->flag, m_->f_key, m_->f_val, m_->alloc, CMC_CALLBACKS_GET(m_));
}
bool CMC_(PFX, _print)(struct SNAME *_map_, FILE *fptr, const char *start, const char *separator, const char *end,
const char *key_val_sep)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
fprintf(fptr, "%s", start);
size_t last = 0;
for (size_t i = _map_->capacity; i > 0; i--)
{
if ((_map_->buffer[i - 1]).state == CMC_ES_FILLED)
{
last = i - 1;
break;
}
}
for (size_t i = 0; i < _map_->capacity; i++)
{
struct CMC_DEF_ENTRY(SNAME) *entry = &(_map_->buffer[i]);
if (entry->state == CMC_ES_FILLED)
{
if (!_map_->f_key->str(fptr, entry->key))
return false;
fprintf(fptr, "%s", key_val_sep);
if (!_map_->f_val->str(fptr, entry->value))
return false;
if (i + 1 < last)
fprintf(fptr, "%s", separator);
}
}
fprintf(fptr, "%s", end);
return true;
}
#endif /* CMC_EXT_STR */
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -60,13 +60,19 @@ struct CMC_DEF_FVAL(SNAME)
struct SNAME *CMC_(PFX, _new)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _clear)(struct SNAME *_map_);
void CMC_(PFX, _free)(struct SNAME *_map_);
/* Collection Allocation and Deallocation */
struct SNAME CMC_(PFX, _init)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _release)(struct SNAME _map_);
/* Customization of Allocation and Callbacks */
void CMC_(PFX, _customize)(struct SNAME *_map_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
void CMC_(PFX, _customize)(struct SNAME *_map_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
/* Collection Input and Output */
bool CMC_(PFX, _insert)(struct SNAME *_map_, K key, V value);
bool CMC_(PFX, _update)(struct SNAME *_map_, K key, V new_value, V *old_value);
@@ -88,3 +94,45 @@ int CMC_(PFX, _flag)(struct SNAME *_map_);
bool CMC_(PFX, _resize)(struct SNAME *_map_, size_t capacity);
struct SNAME *CMC_(PFX, _copy_of)(struct SNAME *_map_);
bool CMC_(PFX, _equals)(struct SNAME *_map1_, struct SNAME *_map2_);
/**
* ITER
*
* Hashmap bi-directional iterator.
*/
#ifdef CMC_EXT_ITER
/* Iterator Initialization */
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME *target);
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME *target);
/* Iterator State */
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter);
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter);
/* Iterator Movement */
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter);
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter);
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter);
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter);
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps);
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps);
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index);
/* Iterator Access */
K CMC_(PFX, _iter_key)(struct CMC_DEF_ITER(SNAME) * iter);
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter);
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter);
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
#endif /* CMC_EXT_ITER */
/**
* STR
*
* Print helper functions.
*/
#ifdef CMC_EXT_STR
bool CMC_(PFX, _to_string)(struct SNAME *_map_, FILE *fptr);
bool CMC_(PFX, _print)(struct SNAME *_map_, FILE *fptr, const char *start, const char *separator, const char *end,
const char *key_val_sep);
#endif /* CMC_EXT_STR */
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -40,7 +40,7 @@ struct SNAME
/* Value function table */
struct CMC_DEF_FVAL(SNAME) * f_val;
/* Custom allocation functions */
struct CMC_ALLOC_NODE_NAME *alloc;
CMC_ALLOC_TYPE alloc;
/* Custom callback functions */
CMC_CALLBACKS_DECL;
};
@@ -58,3 +58,31 @@ struct CMC_DEF_ENTRY(SNAME)
/* The sate of this node (DELETED, EMPTY, FILLED) */
enum cmc_entry_state state;
};
/**
* ITER
*
* Hashmap bi-directional iterator.
*/
#ifdef CMC_EXT_ITER
/* HashMap Iterator */
struct CMC_DEF_ITER(SNAME)
{
/* Target hashmap */
struct SNAME *target;
/* Cursor's position (index) */
size_t cursor;
/* Keeps track of relative index to the iteration of elements */
size_t index;
/* The index of the first element */
size_t first;
/* The index of the last element */
size_t last;
/* If the iterator has reached the start of the iteration */
bool start;
/* If the iterator has reached the end of the iteration */
bool end;
};
#endif /* CMC_EXT_ITER */
+15 -21
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -80,28 +80,22 @@
* PFX - functions prefix
*/
/* Structs definition */
#include "cmc/hashmultimap/struct.h"
#if !defined(CMC_STRUCT) && !defined(CMC_HEADER) && !defined(CMC_CODE)
#include "hashmultimap/struct.h"
#include "hashmultimap/header.h"
#include "hashmultimap/code.h"
#endif
/* Function declaration */
#include "cmc/hashmultimap/header.h"
#ifdef CMC_STRUCT
#include "hashmultimap/struct.h"
#endif /* CMC_STRUCT */
/* Function implementation */
#include "cmc/hashmultimap/code.h"
#ifdef CMC_HEADER
#include "hashmultimap/header.h"
#endif /* CMC_HEADER */
/**
* Extensions
*
* INIT - Initializes the struct on the stack
* ITER - hashmultimap iterator
* STR - Print helper functions
*/
#define CMC_EXT_HASHMULTIMAP_PARTS INIT, ITER, STR
/**/
#include "cmc/hashmultimap/ext/struct.h"
/**/
#include "cmc/hashmultimap/ext/header.h"
/**/
#include "cmc/hashmultimap/ext/code.h"
#ifdef CMC_CODE
#include "hashmultimap/code.h"
#endif /* CMC_CODE */
#include "cor/undef.h"
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -39,8 +39,8 @@ struct SNAME *CMC_(PFX, _new)(size_t capacity, double load, struct CMC_DEF_FKEY(
}
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks)
struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -167,7 +167,15 @@ void CMC_(PFX, _free)(struct SNAME *_map_)
_map_->alloc->free(_map_);
}
void CMC_(PFX, _customize)(struct SNAME *_map_, struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
// TODO
// struct SNAME CMC_(PFX, _init)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
// struct CMC_DEF_FVAL(SNAME) * f_val);
// struct SNAME CMC_(PFX, _init_custom)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
// struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
// CMC_CALLBACK_TYPE callbacks);
// void CMC_(PFX, _release)(struct SNAME _map_);
void CMC_(PFX, _customize)(struct SNAME *_map_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -218,7 +226,7 @@ bool CMC_(PFX, _insert)(struct SNAME *_map_, K key, V value)
_map_->count++;
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, create);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -250,7 +258,7 @@ bool CMC_(PFX, _update)(struct SNAME *_map_, K key, V new_value, V *old_value)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, update);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -314,7 +322,7 @@ size_t CMC_(PFX, _update_all)(struct SNAME *_map_, K key, V new_value, V **old_v
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, update);
CMC_CALLBACKS_CALL(_map_);
return index;
}
@@ -401,7 +409,7 @@ bool CMC_(PFX, _remove)(struct SNAME *_map_, K key, V *out_value)
_map_->count--;
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, delete);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -496,7 +504,7 @@ size_t CMC_(PFX, _remove_all)(struct SNAME *_map_, K key, V **out_values)
_map_->count -= index;
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, delete);
CMC_CALLBACKS_CALL(_map_);
return index;
}
@@ -547,7 +555,7 @@ bool CMC_(PFX, _max)(struct SNAME *_map_, K *key, V *value)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -598,7 +606,7 @@ bool CMC_(PFX, _min)(struct SNAME *_map_, K *key, V *value)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -625,7 +633,7 @@ V CMC_(PFX, _get)(struct SNAME *_map_, K key)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return entry->value;
}
@@ -652,7 +660,7 @@ V *CMC_(PFX, _get_ref)(struct SNAME *_map_, K key)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return &(entry->value);
}
@@ -667,7 +675,7 @@ bool CMC_(PFX, _contains)(struct SNAME *_map_, K key)
bool result = CMC_(PFX, _impl_get_entry)(_map_, key) != NULL;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return result;
}
@@ -813,7 +821,7 @@ bool CMC_(PFX, _resize)(struct SNAME *_map_, size_t capacity)
success:
CMC_CALLBACKS_CALL(_map_, resize);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -984,3 +992,435 @@ size_t CMC_(PFX, _impl_calculate_size)(size_t required)
return cmc_hashtable_primes[i];
}
/**
* ITER
*
* List bi-directional iterator.
*/
#ifdef CMC_EXT_ITER
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME *target)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
struct CMC_DEF_ITER(SNAME) iter;
iter.target = target;
iter.curr_entry = NULL;
iter.cursor = 0;
iter.index = 0;
iter.first = 0;
iter.last = 0;
iter.start = true;
iter.end = CMC_(PFX, _empty)(target);
if (!CMC_(PFX, _empty)(target))
{
for (size_t i = 0; i < target->capacity; i++)
{
struct CMC_DEF_ENTRY(SNAME) *entry = target->buffer[i][0];
if (entry && entry != CMC_ENTRY_DELETED)
{
iter.curr_entry = target->buffer[i][0];
iter.first = i;
break;
}
}
iter.cursor = iter.first;
for (size_t i = target->capacity; i > 0; i--)
{
struct CMC_DEF_ENTRY(SNAME) *entry = target->buffer[i - 1][1];
if (entry && entry != CMC_ENTRY_DELETED)
{
iter.last = i - 1;
break;
}
}
}
return iter;
}
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME *target)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
struct CMC_DEF_ITER(SNAME) iter;
iter.target = target;
iter.curr_entry = NULL;
iter.cursor = 0;
iter.index = 0;
iter.first = 0;
iter.last = 0;
iter.start = CMC_(PFX, _empty)(target);
iter.end = true;
if (!CMC_(PFX, _empty)(target))
{
for (size_t i = 0; i < target->capacity; i++)
{
struct CMC_DEF_ENTRY(SNAME) *entry = target->buffer[i][0];
if (entry && entry != CMC_ENTRY_DELETED)
{
iter.first = i;
break;
}
}
for (size_t i = target->capacity; i > 0; i--)
{
struct CMC_DEF_ENTRY(SNAME) *entry = target->buffer[i - 1][1];
if (entry && entry != CMC_ENTRY_DELETED)
{
iter.curr_entry = target->buffer[i - 1][1];
iter.last = i - 1;
break;
}
}
iter.cursor = iter.last;
iter.index = target->count - 1;
}
return iter;
}
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
return CMC_(PFX, _empty)(iter->target) || iter->start;
}
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
return CMC_(PFX, _empty)(iter->target) || iter->end;
}
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (!CMC_(PFX, _empty)(iter->target))
{
iter->cursor = iter->first;
iter->index = 0;
iter->start = true;
iter->end = CMC_(PFX, _empty)(iter->target);
iter->curr_entry = iter->target->buffer[iter->first][0];
return true;
}
return false;
}
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (!CMC_(PFX, _empty)(iter->target))
{
iter->cursor = iter->last;
iter->index = iter->target->count - 1;
iter->start = CMC_(PFX, _empty)(iter->target);
iter->end = true;
iter->curr_entry = iter->target->buffer[iter->last][1];
return true;
}
return false;
}
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (iter->end)
return false;
if (iter->curr_entry->next != NULL)
{
iter->curr_entry = iter->curr_entry->next;
iter->index++;
}
else
{
if (iter->cursor == iter->last)
{
iter->end = true;
return false;
}
iter->cursor++;
while (iter->target->buffer[iter->cursor][0] == NULL)
iter->cursor++;
iter->curr_entry = iter->target->buffer[iter->cursor][0];
iter->index++;
}
iter->start = CMC_(PFX, _empty)(iter->target);
return true;
}
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (iter->start)
return false;
if (iter->curr_entry->prev != NULL)
{
iter->curr_entry = iter->curr_entry->prev;
iter->index--;
}
else
{
if (iter->cursor == iter->first)
{
iter->start = true;
return false;
}
iter->cursor--;
while (iter->target->buffer[iter->cursor][1] == NULL)
iter->cursor--;
iter->curr_entry = iter->target->buffer[iter->cursor][1];
iter->index--;
}
iter->end = CMC_(PFX, _empty)(iter->target);
return true;
}
/* Returns true only if the iterator moved */
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (iter->end)
return false;
if (iter->index + 1 == iter->target->count)
{
iter->end = true;
return false;
}
if (steps == 0 || iter->index + steps >= iter->target->count)
return false;
for (size_t i = 0; i < steps; i++)
CMC_(PFX, _iter_next)(iter);
return true;
}
/* Returns true only if the iterator moved */
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (iter->start)
return false;
if (iter->index == 0)
{
iter->start = true;
return false;
}
if (steps == 0 || iter->index < steps)
return false;
for (size_t i = 0; i < steps; i++)
CMC_(PFX, _iter_prev)(iter);
return true;
}
/* Returns true only if the iterator was able to be positioned at the */
/* given index */
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (index >= iter->target->count)
return false;
if (iter->index > index)
return CMC_(PFX, _iter_rewind)(iter, iter->index - index);
else if (iter->index < index)
return CMC_(PFX, _iter_advance)(iter, index - iter->index);
return true;
}
K CMC_(PFX, _iter_key)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (CMC_(PFX, _empty)(iter->target))
return (K){ 0 };
return iter->curr_entry->key;
}
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (CMC_(PFX, _empty)(iter->target))
return (V){ 0 };
return iter->curr_entry->value;
}
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
if (CMC_(PFX, _empty)(iter->target))
return NULL;
return &(iter->curr_entry->value);
}
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
return iter->index;
}
#endif /* CMC_EXT_ITER */
/**
* STR
*
* Print helper functions.
*/
#ifdef CMC_EXT_STR
bool CMC_(PFX, _to_string)(struct SNAME *_map_, FILE *fptr)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
struct SNAME *m_ = _map_;
return 0 <= fprintf(fptr,
"struct %s<%s, %s> "
"at %p { "
"buffer:%p, "
"capacity:%" PRIuMAX ", "
"count:%" PRIuMAX ", "
"load:%lf, "
"flag:%d, "
"f_key:%p, "
"f_val:%p, "
"alloc:%p, "
"callbacks:%p }",
CMC_TO_STRING(SNAME), CMC_TO_STRING(K), CMC_TO_STRING(V), m_, m_->buffer, m_->capacity,
m_->count, m_->load, m_->flag, m_->f_key, m_->f_val, m_->alloc, CMC_CALLBACKS_GET(m_));
}
bool CMC_(PFX, _print)(struct SNAME *_map_, FILE *fptr, const char *start, const char *separator, const char *end,
const char *key_val_sep)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
#endif
fprintf(fptr, "%s", start);
size_t last = 0;
for (size_t i = _map_->capacity; i > 0; i--)
{
struct CMC_DEF_ENTRY(SNAME) *entry = _map_->buffer[i - 1][1];
if (entry && entry != CMC_ENTRY_DELETED)
{
last = i - 1;
break;
}
}
for (size_t i = 0; i < _map_->capacity; i++)
{
struct CMC_DEF_ENTRY(SNAME) *scan = _map_->buffer[i][0];
while (scan != NULL)
{
if (!_map_->f_key->str(fptr, scan->key))
return false;
fprintf(fptr, "%s", key_val_sep);
if (!_map_->f_val->str(fptr, scan->value))
return false;
scan = scan->next;
if (i + 1 < last)
fprintf(fptr, "%s", separator);
}
}
fprintf(fptr, "%s", end);
return true;
}
#endif /* CMC_EXT_STR */
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -60,13 +60,20 @@ struct CMC_DEF_FVAL(SNAME)
struct SNAME *CMC_(PFX, _new)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _clear)(struct SNAME *_map_);
void CMC_(PFX, _free)(struct SNAME *_map_);
/* Collection Allocation and Deallocation */
// TODO
// struct SNAME CMC_(PFX, _init)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
// struct CMC_DEF_FVAL(SNAME) * f_val);
// struct SNAME CMC_(PFX, _init_custom)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key,
// struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
// CMC_CALLBACK_TYPE callbacks);
// void CMC_(PFX, _release)(struct SNAME _map_);
/* Customization of Allocation and Callbacks */
void CMC_(PFX, _customize)(struct SNAME *_map_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
void CMC_(PFX, _customize)(struct SNAME *_map_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
/* Collection Input and Output */
bool CMC_(PFX, _insert)(struct SNAME *_map_, K key, V value);
bool CMC_(PFX, _update)(struct SNAME *_map_, K key, V new_value, V *old_value);
@@ -91,3 +98,45 @@ int CMC_(PFX, _flag)(struct SNAME *_map_);
bool CMC_(PFX, _resize)(struct SNAME *_map_, size_t capacity);
struct SNAME *CMC_(PFX, _copy_of)(struct SNAME *_map_);
bool CMC_(PFX, _equals)(struct SNAME *_map1_, struct SNAME *_map2_);
/**
* ITER
*
* Hashmultimap bi-directional iterator.
*/
#ifdef CMC_EXT_ITER
/* Iterator Initialization */
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME *target);
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME *target);
/* Iterator State */
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter);
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter);
/* Iterator Movement */
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter);
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter);
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter);
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter);
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps);
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps);
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index);
/* Iterator Access */
K CMC_(PFX, _iter_key)(struct CMC_DEF_ITER(SNAME) * iter);
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter);
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter);
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
#endif /* CMC_EXT_ITER */
/**
* STR
*
* Print helper functions.
*/
#ifdef CMC_EXT_STR
bool CMC_(PFX, _to_string)(struct SNAME *_map_, FILE *fptr);
bool CMC_(PFX, _print)(struct SNAME *_map_, FILE *fptr, const char *start, const char *separator, const char *end,
const char *key_val_sep);
#endif /* CMC_EXT_STR */
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -40,7 +40,7 @@ struct SNAME
/* Value function table */
struct CMC_DEF_FVAL(SNAME) * f_val;
/* Custom allocation functions */
struct CMC_ALLOC_NODE_NAME *alloc;
CMC_ALLOC_TYPE alloc;
/* Custom callback functions */
CMC_CALLBACKS_DECL;
};
@@ -57,3 +57,33 @@ struct CMC_DEF_ENTRY(SNAME)
/* Previous entry on the linked list */
struct CMC_DEF_ENTRY(SNAME) * prev;
};
/**
* ITER
*
* Hashmultimap bi-directional iterator.
*/
#ifdef CMC_EXT_ITER
/* HashMultiMap Iterator */
struct CMC_DEF_ITER(SNAME)
{
/* Target hashmultimap */
struct SNAME *target;
/* Current entry */
struct CMC_DEF_ENTRY(SNAME) * curr_entry;
/* Cursor`s position (index) */
size_t cursor;
/* Keeps track of relative index to the iteration of elements */
size_t index;
/* The index of the first element */
size_t first;
/* The index of the last element */
size_t last;
/* If the iterator has reached the start of the iteration */
bool start;
/* If the iterator has reached the end of the iteration */
bool end;
};
#endif /* CMC_EXT_ITER */
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -37,7 +37,7 @@ struct SNAME *CMC_(PFX, _new)(size_t capacity, double load, struct CMC_DEF_FVAL(
}
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -133,7 +133,7 @@ void CMC_(PFX, _free)(struct SNAME *_set_)
_set_->alloc->free(_set_);
}
void CMC_(PFX, _customize)(struct SNAME *_set_, struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
void CMC_(PFX, _customize)(struct SNAME *_set_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -173,7 +173,7 @@ bool CMC_(PFX, _insert)(struct SNAME *_set_, V value)
_set_->cardinality++;
_set_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_set_, create);
CMC_CALLBACKS_CALL(_set_);
return true;
}
@@ -208,7 +208,7 @@ success:
_set_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_set_, create);
CMC_CALLBACKS_CALL(_set_);
return true;
}
@@ -257,7 +257,7 @@ success:
_set_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_set_, update);
CMC_CALLBACKS_CALL(_set_);
return true;
}
@@ -297,7 +297,7 @@ bool CMC_(PFX, _remove)(struct SNAME *_set_, V value)
_set_->cardinality--;
_set_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_set_, delete);
CMC_CALLBACKS_CALL(_set_);
return true;
}
@@ -333,7 +333,7 @@ size_t CMC_(PFX, _remove_all)(struct SNAME *_set_, V value)
_set_->cardinality -= removed;
_set_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_set_, delete);
CMC_CALLBACKS_CALL(_set_);
return removed;
}
@@ -374,7 +374,7 @@ bool CMC_(PFX, _max)(struct SNAME *_set_, V *value)
_set_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_set_, read);
CMC_CALLBACKS_CALL(_set_);
return true;
}
@@ -415,7 +415,7 @@ bool CMC_(PFX, _min)(struct SNAME *_set_, V *value)
_set_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_set_, read);
CMC_CALLBACKS_CALL(_set_);
return true;
}
@@ -430,7 +430,7 @@ size_t CMC_(PFX, _multiplicity_of)(struct SNAME *_set_, V value)
_set_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_set_, read);
CMC_CALLBACKS_CALL(_set_);
if (!entry)
return 0;
@@ -448,7 +448,7 @@ bool CMC_(PFX, _contains)(struct SNAME *_set_, V value)
bool result = CMC_(PFX, _impl_get_entry)(_set_, value) != NULL;
CMC_CALLBACKS_CALL(_set_, read);
CMC_CALLBACKS_CALL(_set_);
return result;
}
@@ -594,7 +594,7 @@ bool CMC_(PFX, _resize)(struct SNAME *_set_, size_t capacity)
success:
CMC_CALLBACKS_CALL(_set_, resize);
CMC_CALLBACKS_CALL(_set_);
return true;
}
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -42,12 +42,11 @@ struct CMC_DEF_FVAL(SNAME)
/* Collection Allocation and Deallocation */
struct SNAME *CMC_(PFX, _new)(size_t capacity, double load, struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks);
CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _clear)(struct SNAME *_set_);
void CMC_(PFX, _free)(struct SNAME *_set_);
/* Customization of Allocation and Callbacks */
void CMC_(PFX, _customize)(struct SNAME *_set_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
void CMC_(PFX, _customize)(struct SNAME *_set_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
/* Collection Input and Output */
bool CMC_(PFX, _insert)(struct SNAME *_set_, V value);
bool CMC_(PFX, _insert_many)(struct SNAME *_set_, V value, size_t count);
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -39,7 +39,7 @@ struct SNAME
/* Key function table */
struct CMC_DEF_FVAL(SNAME) * f_val;
/* Custom allocation functions */
struct CMC_ALLOC_NODE_NAME *alloc;
CMC_ALLOC_TYPE alloc;
/* Custom callback functions */
CMC_CALLBACKS_DECL;
};
+1 -1
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -36,7 +36,7 @@ struct SNAME *CMC_(PFX, _new)(size_t capacity, double load, struct CMC_DEF_FVAL(
}
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -131,7 +131,7 @@ void CMC_(PFX, _free)(struct SNAME *_set_)
_set_->alloc->free(_set_);
}
void CMC_(PFX, _customize)(struct SNAME *_set_, struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
void CMC_(PFX, _customize)(struct SNAME *_set_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -211,7 +211,7 @@ bool CMC_(PFX, _insert)(struct SNAME *_set_, V value)
_set_->count++;
_set_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_set_, create);
CMC_CALLBACKS_CALL(_set_);
return true;
}
@@ -243,7 +243,7 @@ bool CMC_(PFX, _remove)(struct SNAME *_set_, V value)
_set_->count--;
_set_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_set_, delete);
CMC_CALLBACKS_CALL(_set_);
return true;
}
@@ -284,7 +284,7 @@ bool CMC_(PFX, _max)(struct SNAME *_set_, V *value)
_set_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_set_, read);
CMC_CALLBACKS_CALL(_set_);
return true;
}
@@ -325,7 +325,7 @@ bool CMC_(PFX, _min)(struct SNAME *_set_, V *value)
_set_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_set_, read);
CMC_CALLBACKS_CALL(_set_);
return true;
}
@@ -340,7 +340,7 @@ bool CMC_(PFX, _contains)(struct SNAME *_set_, V value)
bool result = CMC_(PFX, _impl_get_entry)(_set_, value) != NULL;
CMC_CALLBACKS_CALL(_set_, read);
CMC_CALLBACKS_CALL(_set_);
return result;
}
@@ -474,7 +474,7 @@ bool CMC_(PFX, _resize)(struct SNAME *_set_, size_t capacity)
success:
CMC_CALLBACKS_CALL(_set_, resize);
CMC_CALLBACKS_CALL(_set_);
return true;
}
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -42,12 +42,11 @@ struct CMC_DEF_FVAL(SNAME)
/* Collection Allocation and Deallocation */
struct SNAME *CMC_(PFX, _new)(size_t capacity, double load, struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks);
CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _clear)(struct SNAME *_set_);
void CMC_(PFX, _free)(struct SNAME *_set_);
/* Customization of Allocation and Callbacks */
void CMC_(PFX, _customize)(struct SNAME *_set_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
void CMC_(PFX, _customize)(struct SNAME *_set_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
/* Collection Input and Output */
bool CMC_(PFX, _insert)(struct SNAME *_set_, V value);
bool CMC_(PFX, _remove)(struct SNAME *_set_, V value);
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -38,7 +38,7 @@ struct SNAME
/* Value function table */
struct CMC_DEF_FVAL(SNAME) * f_val;
/* Custom allocation functions */
struct CMC_ALLOC_NODE_NAME *alloc;
CMC_ALLOC_TYPE alloc;
/* Custom callback functions */
CMC_CALLBACKS_DECL;
};
+1 -1
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+8 -9
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -36,7 +36,7 @@ struct SNAME *CMC_(PFX, _new)(size_t capacity, enum cmc_heap_order HO, struct CM
}
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, enum cmc_heap_order HO, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -118,8 +118,7 @@ void CMC_(PFX, _free)(struct SNAME *_heap_)
_heap_->alloc->free(_heap_);
}
void CMC_(PFX, _customize)(struct SNAME *_heap_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks)
void CMC_(PFX, _customize)(struct SNAME *_heap_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -158,7 +157,7 @@ bool CMC_(PFX, _insert)(struct SNAME *_heap_, V value)
_heap_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_heap_, create);
CMC_CALLBACKS_CALL(_heap_);
return true;
}
@@ -184,7 +183,7 @@ bool CMC_(PFX, _remove)(struct SNAME *_heap_)
_heap_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_heap_, delete);
CMC_CALLBACKS_CALL(_heap_);
return true;
}
@@ -203,7 +202,7 @@ V CMC_(PFX, _peek)(struct SNAME *_heap_)
_heap_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_heap_, read);
CMC_CALLBACKS_CALL(_heap_);
return _heap_->buffer[0];
}
@@ -227,7 +226,7 @@ bool CMC_(PFX, _contains)(struct SNAME *_heap_, V value)
}
}
CMC_CALLBACKS_CALL(_heap_, read);
CMC_CALLBACKS_CALL(_heap_);
return result;
}
@@ -309,7 +308,7 @@ bool CMC_(PFX, _resize)(struct SNAME *_heap_, size_t capacity)
success:
CMC_CALLBACKS_CALL(_heap_, resize);
CMC_CALLBACKS_CALL(_heap_);
return true;
}
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -42,12 +42,11 @@ struct CMC_DEF_FVAL(SNAME)
/* Collection Allocation and Deallocation */
struct SNAME *CMC_(PFX, _new)(size_t capacity, enum cmc_heap_order HO, struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, enum cmc_heap_order HO, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks);
CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _clear)(struct SNAME *_heap_);
void CMC_(PFX, _free)(struct SNAME *_heap_);
/* Customization of Allocation and Callbacks */
void CMC_(PFX, _customize)(struct SNAME *_heap_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
void CMC_(PFX, _customize)(struct SNAME *_heap_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
/* Collection Input and Output */
bool CMC_(PFX, _insert)(struct SNAME *_heap_, V value);
bool CMC_(PFX, _remove)(struct SNAME *_heap_);
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -37,7 +37,7 @@ struct SNAME
/* Value function table */
struct CMC_DEF_FVAL(SNAME) * f_val;
/* Custom allocation functions */
struct CMC_ALLOC_NODE_NAME *alloc;
CMC_ALLOC_TYPE alloc;
/* Custom callback functions */
CMC_CALLBACKS_DECL;
};
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -37,8 +37,8 @@ struct SNAME *CMC_(PFX, _new)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_va
return CMC_(PFX, _new_custom)(capacity, f_val, NULL, NULL);
}
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -121,8 +121,7 @@ void CMC_(PFX, _free)(struct SNAME *_heap_)
_heap_->alloc->free(_heap_);
}
void CMC_(PFX, _customize)(struct SNAME *_heap_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks)
void CMC_(PFX, _customize)(struct SNAME *_heap_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -195,7 +194,7 @@ bool CMC_(PFX, _insert)(struct SNAME *_heap_, V value)
/* else no float up required */
}
CMC_CALLBACKS_CALL(_heap_, create);
CMC_CALLBACKS_CALL(_heap_);
return true;
}
@@ -251,7 +250,7 @@ success:
_heap_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_heap_, delete);
CMC_CALLBACKS_CALL(_heap_);
return true;
}
@@ -307,7 +306,7 @@ success:
_heap_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_heap_, delete);
CMC_CALLBACKS_CALL(_heap_);
return true;
}
@@ -347,7 +346,7 @@ bool CMC_(PFX, _update_max)(struct SNAME *_heap_, V value)
_heap_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_heap_, update);
CMC_CALLBACKS_CALL(_heap_);
return true;
}
@@ -387,7 +386,7 @@ bool CMC_(PFX, _update_min)(struct SNAME *_heap_, V value)
_heap_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_heap_, update);
CMC_CALLBACKS_CALL(_heap_);
return true;
}
@@ -406,7 +405,7 @@ V CMC_(PFX, _max)(struct SNAME *_heap_)
_heap_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_heap_, read);
CMC_CALLBACKS_CALL(_heap_);
/* If there is only one element, then the maximum element is the */
/* same as the one in the MinHeap */
@@ -430,7 +429,7 @@ V CMC_(PFX, _min)(struct SNAME *_heap_)
_heap_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_heap_, read);
CMC_CALLBACKS_CALL(_heap_);
return _heap_->buffer[0][0];
}
@@ -454,7 +453,7 @@ bool CMC_(PFX, _contains)(struct SNAME *_heap_, V value)
}
}
CMC_CALLBACKS_CALL(_heap_, read);
CMC_CALLBACKS_CALL(_heap_);
return result;
}
@@ -549,7 +548,7 @@ success:
_heap_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_heap_, resize);
CMC_CALLBACKS_CALL(_heap_);
return true;
}
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -42,13 +42,12 @@ struct CMC_DEF_FVAL(SNAME)
/* Collection Functions */
/* Collection Allocation and Deallocation */
struct SNAME *CMC_(PFX, _new)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _clear)(struct SNAME *_heap_);
void CMC_(PFX, _free)(struct SNAME *_heap_);
/* Customization of Allocation and Callbacks */
void CMC_(PFX, _customize)(struct SNAME *_heap_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
void CMC_(PFX, _customize)(struct SNAME *_heap_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
/* Collection Input and Output */
bool CMC_(PFX, _insert)(struct SNAME *_heap_, V value);
bool CMC_(PFX, _remove_max)(struct SNAME *_heap_);
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -38,7 +38,7 @@ struct SNAME
/* Value function table */
struct CMC_DEF_FVAL(SNAME) * f_val;
/* Custom allocation functions */
struct CMC_ALLOC_NODE_NAME *alloc;
CMC_ALLOC_TYPE alloc;
/* Custom callback functions */
CMC_CALLBACKS_DECL;
};
+1 -1
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -35,8 +35,8 @@ struct SNAME *CMC_(PFX, _new)(struct CMC_DEF_FVAL(SNAME) * f_val)
return CMC_(PFX, _new_custom)(f_val, NULL, NULL);
}
struct SNAME *CMC_(PFX, _new_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks)
struct SNAME *CMC_(PFX, _new_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -105,8 +105,7 @@ void CMC_(PFX, _free)(struct SNAME *_list_)
_list_->alloc->free(_list_);
}
void CMC_(PFX, _customize)(struct SNAME *_list_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks)
void CMC_(PFX, _customize)(struct SNAME *_list_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -150,7 +149,7 @@ bool CMC_(PFX, _push_front)(struct SNAME *_list_, V value)
_list_->count++;
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, create);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -191,7 +190,7 @@ bool CMC_(PFX, _push_at)(struct SNAME *_list_, V value, size_t index)
_list_->count++;
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, create);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -222,7 +221,7 @@ bool CMC_(PFX, _push_back)(struct SNAME *_list_, V value)
_list_->count++;
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, create);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -252,7 +251,7 @@ bool CMC_(PFX, _pop_front)(struct SNAME *_list_)
_list_->count--;
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, delete);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -297,7 +296,7 @@ bool CMC_(PFX, _pop_at)(struct SNAME *_list_, size_t index)
_list_->count--;
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, delete);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -327,7 +326,7 @@ bool CMC_(PFX, _pop_back)(struct SNAME *_list_)
_list_->count--;
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, delete);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -346,7 +345,7 @@ V CMC_(PFX, _front)(struct SNAME *_list_)
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, read);
CMC_CALLBACKS_CALL(_list_);
return _list_->head->value;
}
@@ -374,7 +373,7 @@ V CMC_(PFX, _get)(struct SNAME *_list_, size_t index)
if (scan == NULL)
return (V){ 0 };
CMC_CALLBACKS_CALL(_list_, read);
CMC_CALLBACKS_CALL(_list_);
return scan->value;
}
@@ -402,7 +401,7 @@ V *CMC_(PFX, _get_ref)(struct SNAME *_list_, size_t index)
if (scan == NULL)
return NULL;
CMC_CALLBACKS_CALL(_list_, read);
CMC_CALLBACKS_CALL(_list_);
return &(scan->value);
}
@@ -421,7 +420,7 @@ V CMC_(PFX, _back)(struct SNAME *_list_)
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, read);
CMC_CALLBACKS_CALL(_list_);
return _list_->tail->value;
}
@@ -449,7 +448,7 @@ bool CMC_(PFX, _contains)(struct SNAME *_list_, V value)
scan = scan->next;
}
CMC_CALLBACKS_CALL(_list_, read);
CMC_CALLBACKS_CALL(_list_);
return result;
}
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -42,13 +42,12 @@ struct CMC_DEF_FVAL(SNAME)
/* Collection Functions */
/* Collection Allocation and Deallocation */
struct SNAME *CMC_(PFX, _new)(struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME *CMC_(PFX, _new_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
struct SNAME *CMC_(PFX, _new_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _clear)(struct SNAME *_list_);
void CMC_(PFX, _free)(struct SNAME *_list_);
/* Customization of Allocation and Callbacks */
void CMC_(PFX, _customize)(struct SNAME *_list_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
void CMC_(PFX, _customize)(struct SNAME *_list_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
/* Collection Input and Output */
bool CMC_(PFX, _push_front)(struct SNAME *_list_, V value);
bool CMC_(PFX, _push_at)(struct SNAME *_list_, V value, size_t index);
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -41,7 +41,7 @@ struct SNAME
struct CMC_DEF_FVAL(SNAME) * f_val;
/* Custom allocation functions */
struct CMC_ALLOC_NODE_NAME *alloc;
CMC_ALLOC_TYPE alloc;
/* Custom callback functions */
CMC_CALLBACKS_DECL;
+1 -1
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+43 -29
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -43,11 +43,11 @@ struct SNAME *CMC_(PFX, _new)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_va
}
#ifdef CMC_SAC
struct SNAME *CMC_(PFX, _new_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks)
struct SNAME *CMC_(PFX, _new_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
#else
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
#endif
{
#ifdef CMC_DEV
@@ -61,9 +61,6 @@ struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME)
return NULL;
#endif
if (!f_val)
return NULL;
if (!alloc)
alloc = &cmc_alloc_node_default;
@@ -104,7 +101,7 @@ void CMC_(PFX, _clear)(struct SNAME *_list_)
CMC_DEV_FCALL;
#endif
if (_list_->f_val->free)
if (_list_->f_val && _list_->f_val->free)
{
for (size_t i = 0; i < _list_->count; i++)
_list_->f_val->free(_list_->buffer[i]);
@@ -126,7 +123,7 @@ void CMC_(PFX, _free)(struct SNAME *_list_)
CMC_DEV_FCALL;
#endif
if (_list_->f_val->free)
if (_list_->f_val && _list_->f_val->free)
{
for (size_t i = 0; i < _list_->count; i++)
_list_->f_val->free(_list_->buffer[i]);
@@ -138,8 +135,7 @@ void CMC_(PFX, _free)(struct SNAME *_list_)
_list_->alloc->free(_list_);
}
void CMC_(PFX, _customize)(struct SNAME *_list_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks)
void CMC_(PFX, _customize)(struct SNAME *_list_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -188,7 +184,7 @@ bool CMC_(PFX, _push_front)(struct SNAME *_list_, V value)
_list_->count++;
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, create);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -222,7 +218,7 @@ bool CMC_(PFX, _push_at)(struct SNAME *_list_, V value, size_t index)
_list_->count++;
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, create);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -247,7 +243,7 @@ bool CMC_(PFX, _push_back)(struct SNAME *_list_, V value)
_list_->buffer[_list_->count++] = value;
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, create);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -269,7 +265,7 @@ bool CMC_(PFX, _pop_front)(struct SNAME *_list_)
_list_->buffer[--_list_->count] = (V){ 0 };
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, delete);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -297,7 +293,7 @@ bool CMC_(PFX, _pop_at)(struct SNAME *_list_, size_t index)
_list_->buffer[--_list_->count] = (V){ 0 };
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, delete);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -309,12 +305,16 @@ bool CMC_(PFX, _pop_back)(struct SNAME *_list_)
#endif
if (CMC_(PFX, _empty)(_list_))
{
_list_->flag = CMC_FLAG_EMPTY;
CMC_CALLBACKS_CALL(_list_);
return false;
}
_list_->buffer[--_list_->count] = (V){ 0 };
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, delete);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -333,7 +333,7 @@ V CMC_(PFX, _front)(struct SNAME *_list_)
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, read);
CMC_CALLBACKS_CALL(_list_);
return _list_->buffer[0];
}
@@ -347,18 +347,20 @@ V CMC_(PFX, _get)(struct SNAME *_list_, size_t index)
if (CMC_(PFX, _empty)(_list_))
{
_list_->flag = CMC_FLAG_EMPTY;
CMC_CALLBACKS_CALL(_list_);
return (V){ 0 };
}
if (index >= _list_->count)
{
_list_->flag = CMC_FLAG_RANGE;
CMC_CALLBACKS_CALL(_list_);
return (V){ 0 };
}
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, read);
CMC_CALLBACKS_CALL(_list_);
return _list_->buffer[index];
}
@@ -383,7 +385,7 @@ V *CMC_(PFX, _get_ref)(struct SNAME *_list_, size_t index)
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, read);
CMC_CALLBACKS_CALL(_list_);
return &(_list_->buffer[index]);
}
@@ -402,7 +404,7 @@ V CMC_(PFX, _back)(struct SNAME *_list_)
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, read);
CMC_CALLBACKS_CALL(_list_);
return _list_->buffer[_list_->count - 1];
}
@@ -413,6 +415,12 @@ size_t CMC_(PFX, _index_of)(struct SNAME *_list_, V value, bool from_start)
CMC_DEV_FCALL;
#endif
if (_list_->f_val == NULL || _list_->f_val->cmp == NULL)
{
_list_->flag = CMC_FLAG_FTABLE;
return 0;
}
_list_->flag = CMC_FLAG_OK;
size_t result = _list_->count;
@@ -421,7 +429,7 @@ size_t CMC_(PFX, _index_of)(struct SNAME *_list_, V value, bool from_start)
{
for (size_t i = 0; i < _list_->count; i++)
{
if (_list_->f_val->cmp(_list_->buffer[i], value) == 0)
if (0 == _list_->f_val->cmp(_list_->buffer[i], value))
{
result = i;
break;
@@ -432,7 +440,7 @@ size_t CMC_(PFX, _index_of)(struct SNAME *_list_, V value, bool from_start)
{
for (size_t i = _list_->count; i > 0; i--)
{
if (_list_->f_val->cmp(_list_->buffer[i - 1], value) == 0)
if (0 == _list_->f_val->cmp(_list_->buffer[i - 1], value))
{
result = i - 1;
break;
@@ -440,7 +448,7 @@ size_t CMC_(PFX, _index_of)(struct SNAME *_list_, V value, bool from_start)
}
}
CMC_CALLBACKS_CALL(_list_, read);
CMC_CALLBACKS_CALL(_list_);
return result;
}
@@ -451,20 +459,26 @@ bool CMC_(PFX, _contains)(struct SNAME *_list_, V value)
CMC_DEV_FCALL;
#endif
if (_list_->f_val == NULL || _list_->f_val->cmp == NULL)
{
_list_->flag = CMC_FLAG_FTABLE;
return false;
}
_list_->flag = CMC_FLAG_OK;
bool result = false;
for (size_t i = 0; i < _list_->count; i++)
{
if (_list_->f_val->cmp(_list_->buffer[i], value) == 0)
if (0 == _list_->f_val->cmp(_list_->buffer[i], value))
{
result = true;
break;
}
}
CMC_CALLBACKS_CALL(_list_, read);
CMC_CALLBACKS_CALL(_list_);
return result;
}
@@ -567,7 +581,7 @@ bool CMC_(PFX, _resize)(struct SNAME *_list_, size_t capacity)
_list_->buffer = new_buffer;
_list_->capacity = capacity;
CMC_CALLBACKS_CALL(_list_, resize);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -593,7 +607,7 @@ struct SNAME *CMC_(PFX, _copy_of)(struct SNAME *_list_)
CMC_CALLBACKS_ASSIGN(result, _list_->callbacks);
if (_list_->f_val->cpy)
if (_list_->f_val && _list_->f_val->cpy)
{
for (size_t i = 0; i < _list_->count; i++)
result->buffer[i] = _list_->f_val->cpy(_list_->buffer[i]);
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -48,11 +48,11 @@ struct SNAME CMC_(PFX, _init)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_va
}
#ifdef CMC_SAC
struct SNAME CMC_(PFX, _init_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks)
struct SNAME CMC_(PFX, _init_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
#else
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
#endif
{
#ifdef CMC_DEV
@@ -397,7 +397,7 @@ bool CMC_(PFX, _seq_push_front)(struct SNAME *_list_, V *values, size_t size)
_list_->count += size;
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, create);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -443,7 +443,7 @@ bool CMC_(PFX, _seq_push_at)(struct SNAME *_list_, V *values, size_t size, size_
_list_->count += size;
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, create);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -476,7 +476,7 @@ bool CMC_(PFX, _seq_push_back)(struct SNAME *_list_, V *values, size_t size)
_list_->count += size;
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, create);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -508,7 +508,7 @@ bool CMC_(PFX, _seq_pop_at)(struct SNAME *_list_, size_t from, size_t to)
_list_->count -= to - from + 1;
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, delete);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -556,7 +556,7 @@ struct SNAME *CMC_(PFX, _seq_sublist)(struct SNAME *_list_, size_t from, size_t
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, delete);
CMC_CALLBACKS_CALL(_list_);
return result;
}
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -32,12 +32,12 @@
#ifdef CMC_SAC
struct SNAME CMC_(PFX, _init)(struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME CMC_(PFX, _init_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
struct SNAME CMC_(PFX, _init_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
#else
struct SNAME CMC_(PFX, _init)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks);
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
#endif
void CMC_(PFX, _release)(struct SNAME _list_);
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -42,18 +42,17 @@ struct CMC_DEF_FVAL(SNAME)
/* Collection Allocation and Deallocation */
#ifdef CMC_SAC
struct SNAME *CMC_(PFX, _new)(struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME *CMC_(PFX, _new_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
struct SNAME *CMC_(PFX, _new_custom)(struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
#else
struct SNAME *CMC_(PFX, _new)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
#endif
void CMC_(PFX, _clear)(struct SNAME *_list_);
void CMC_(PFX, _free)(struct SNAME *_list_);
/* Customization of Allocation and Callbacks */
void CMC_(PFX, _customize)(struct SNAME *_list_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
void CMC_(PFX, _customize)(struct SNAME *_list_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
/* Collection Input and Output */
bool CMC_(PFX, _push_front)(struct SNAME *_list_, V value);
bool CMC_(PFX, _push_at)(struct SNAME *_list_, V value, size_t index);
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -39,7 +39,7 @@ struct SNAME
/* Value function table */
struct CMC_DEF_FVAL(SNAME) * f_val;
/* Custom allocation functions */
struct CMC_ALLOC_NODE_NAME *alloc;
CMC_ALLOC_TYPE alloc;
/* Custom callback functions */
CMC_CALLBACKS_DECL;
};
+1 -1
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+9 -10
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -34,8 +34,8 @@ struct SNAME *CMC_(PFX, _new)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_va
return CMC_(PFX, _new_custom)(capacity, f_val, NULL, NULL);
}
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -121,8 +121,7 @@ void CMC_(PFX, _free)(struct SNAME *_queue_)
_queue_->alloc->free(_queue_);
}
void CMC_(PFX, _customize)(struct SNAME *_queue_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks)
void CMC_(PFX, _customize)(struct SNAME *_queue_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -158,7 +157,7 @@ bool CMC_(PFX, _enqueue)(struct SNAME *_queue_, V value)
_queue_->count++;
_queue_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_queue_, create);
CMC_CALLBACKS_CALL(_queue_);
return true;
}
@@ -181,7 +180,7 @@ bool CMC_(PFX, _dequeue)(struct SNAME *_queue_)
_queue_->count--;
_queue_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_queue_, delete);
CMC_CALLBACKS_CALL(_queue_);
return true;
}
@@ -200,7 +199,7 @@ V CMC_(PFX, _peek)(struct SNAME *_queue_)
_queue_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_queue_, read);
CMC_CALLBACKS_CALL(_queue_);
return _queue_->buffer[_queue_->front];
}
@@ -226,7 +225,7 @@ bool CMC_(PFX, _contains)(struct SNAME *_queue_, V value)
i = (i + 1) % _queue_->capacity;
}
CMC_CALLBACKS_CALL(_queue_, read);
CMC_CALLBACKS_CALL(_queue_);
return result;
}
@@ -317,7 +316,7 @@ success:
_queue_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_queue_, resize);
CMC_CALLBACKS_CALL(_queue_);
return true;
}
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -39,8 +39,8 @@ struct SNAME CMC_(PFX, _init)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_va
return CMC_(PFX, _init_custom)(capacity, f_val, NULL, NULL);
}
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -31,8 +31,8 @@
#ifdef CMC_EXT_INIT
struct SNAME CMC_(PFX, _init)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks);
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _release)(struct SNAME _queue_);
#endif /* CMC_EXT_INIT */
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -41,13 +41,12 @@ struct CMC_DEF_FVAL(SNAME)
/* Collection Allocation and Deallocation */
struct SNAME *CMC_(PFX, _new)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _clear)(struct SNAME *_queue_);
void CMC_(PFX, _free)(struct SNAME *_queue_);
/* Customization of Allocation and Callbacks */
void CMC_(PFX, _customize)(struct SNAME *_queue_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
void CMC_(PFX, _customize)(struct SNAME *_queue_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
/* Collection Input and Output */
bool CMC_(PFX, _enqueue)(struct SNAME *_queue_, V value);
bool CMC_(PFX, _dequeue)(struct SNAME *_queue_);
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -39,7 +39,7 @@ struct SNAME
/* Value function table */
struct CMC_DEF_FVAL(SNAME) * f_val;
/* Custom allocation functions */
struct CMC_ALLOC_NODE_NAME *alloc;
CMC_ALLOC_TYPE alloc;
/* Custom callback functions */
CMC_CALLBACKS_DECL;
};
+1 -1
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -37,8 +37,8 @@ struct SNAME *CMC_(PFX, _new)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_va
return CMC_(PFX, _new_custom)(capacity, f_val, NULL, NULL);
}
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -110,8 +110,7 @@ void CMC_(PFX, _free)(struct SNAME *_list_)
_list_->alloc->free(_list_);
}
void CMC_(PFX, _customize)(struct SNAME *_list_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks)
void CMC_(PFX, _customize)(struct SNAME *_list_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -146,7 +145,7 @@ bool CMC_(PFX, _insert)(struct SNAME *_list_, V value)
_list_->is_sorted = false;
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, create);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -175,7 +174,7 @@ bool CMC_(PFX, _remove)(struct SNAME *_list_, size_t index)
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, delete);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -196,7 +195,7 @@ V CMC_(PFX, _max)(struct SNAME *_list_)
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, read);
CMC_CALLBACKS_CALL(_list_);
return _list_->buffer[_list_->count - 1];
}
@@ -217,7 +216,7 @@ V CMC_(PFX, _min)(struct SNAME *_list_)
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, read);
CMC_CALLBACKS_CALL(_list_);
return _list_->buffer[0];
}
@@ -244,7 +243,7 @@ V CMC_(PFX, _get)(struct SNAME *_list_, size_t index)
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, read);
CMC_CALLBACKS_CALL(_list_);
return _list_->buffer[index];
}
@@ -259,7 +258,7 @@ size_t CMC_(PFX, _index_of)(struct SNAME *_list_, V value, bool from_start)
CMC_(PFX, _sort)(_list_);
CMC_CALLBACKS_CALL(_list_, read);
CMC_CALLBACKS_CALL(_list_);
if (from_start)
{
@@ -282,7 +281,7 @@ bool CMC_(PFX, _contains)(struct SNAME *_list_, V value)
CMC_(PFX, _sort)(_list_);
CMC_CALLBACKS_CALL(_list_, read);
CMC_CALLBACKS_CALL(_list_);
return CMC_(PFX, _impl_binary_search_first)(_list_, value) < _list_->count;
}
@@ -364,7 +363,7 @@ success:
_list_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_list_, resize);
CMC_CALLBACKS_CALL(_list_);
return true;
}
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -41,13 +41,12 @@ struct CMC_DEF_FVAL(SNAME)
/* Collection Allocation and Deallocation */
struct SNAME *CMC_(PFX, _new)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _clear)(struct SNAME *_list_);
void CMC_(PFX, _free)(struct SNAME *_list_);
/* Customization of Allocation and Callbacks */
void CMC_(PFX, _customize)(struct SNAME *_list_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
void CMC_(PFX, _customize)(struct SNAME *_list_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
/* Collection Input and Output */
bool CMC_(PFX, _insert)(struct SNAME *_list_, V value);
bool CMC_(PFX, _remove)(struct SNAME *_list_, size_t index);
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -37,7 +37,7 @@ struct SNAME
/* Value function table */
struct CMC_DEF_FVAL(SNAME) * f_val;
/* Custom allocation functions */
struct CMC_ALLOC_NODE_NAME *alloc;
CMC_ALLOC_TYPE alloc;
/* Custom callback functions */
CMC_CALLBACKS_DECL;
};
+1 -1
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
+9 -10
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -34,8 +34,8 @@ struct SNAME *CMC_(PFX, _new)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_va
return CMC_(PFX, _new_custom)(capacity, f_val, NULL, NULL);
}
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -108,8 +108,7 @@ void CMC_(PFX, _free)(struct SNAME *_stack_)
_stack_->alloc->free(_stack_);
}
void CMC_(PFX, _customize)(struct SNAME *_stack_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks)
void CMC_(PFX, _customize)(struct SNAME *_stack_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -143,7 +142,7 @@ bool CMC_(PFX, _push)(struct SNAME *_stack_, V value)
_stack_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_stack_, create);
CMC_CALLBACKS_CALL(_stack_);
return true;
}
@@ -164,7 +163,7 @@ bool CMC_(PFX, _pop)(struct SNAME *_stack_)
_stack_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_stack_, delete);
CMC_CALLBACKS_CALL(_stack_);
return true;
}
@@ -183,7 +182,7 @@ V CMC_(PFX, _top)(struct SNAME *_stack_)
_stack_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_stack_, read);
CMC_CALLBACKS_CALL(_stack_);
return _stack_->buffer[_stack_->count - 1];
}
@@ -207,7 +206,7 @@ bool CMC_(PFX, _contains)(struct SNAME *_stack_, V value)
}
}
CMC_CALLBACKS_CALL(_stack_, read);
CMC_CALLBACKS_CALL(_stack_);
return result;
}
@@ -289,7 +288,7 @@ success:
_stack_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_stack_, resize);
CMC_CALLBACKS_CALL(_stack_);
return true;
}
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -39,8 +39,8 @@ struct SNAME CMC_(PFX, _init)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_va
return CMC_(PFX, _init_custom)(capacity, f_val, NULL, NULL);
}
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -31,8 +31,8 @@
#ifdef CMC_EXT_INIT
struct SNAME CMC_(PFX, _init)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks);
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _release)(struct SNAME _stack_);
#endif /* CMC_EXT_INIT */
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -41,13 +41,12 @@ struct CMC_DEF_FVAL(SNAME)
/* Collection Allocation and Deallocation */
struct SNAME *CMC_(PFX, _new)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks);
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, CMC_ALLOC_TYPE alloc,
CMC_CALLBACK_TYPE callbacks);
void CMC_(PFX, _clear)(struct SNAME *_stack_);
void CMC_(PFX, _free)(struct SNAME *_stack_);
/* Customization of Allocation and Callbacks */
void CMC_(PFX, _customize)(struct SNAME *_stack_, struct CMC_ALLOC_NODE_NAME *alloc,
struct CMC_CALLBACKS_NAME *callbacks);
void CMC_(PFX, _customize)(struct SNAME *_stack_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks);
/* Collection Input and Output */
bool CMC_(PFX, _push)(struct SNAME *_stack_, V value);
bool CMC_(PFX, _pop)(struct SNAME *_stack_);
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -36,7 +36,7 @@ struct SNAME
/* Value function table */
struct CMC_DEF_FVAL(SNAME) * f_val;
/* Custom allocation functions */
struct CMC_ALLOC_NODE_NAME *alloc;
CMC_ALLOC_TYPE alloc;
/* Custom callback functions */
CMC_CALLBACKS_DECL;
};
+1 -1
View File
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -41,7 +41,7 @@ struct SNAME *CMC_(PFX, _new)(struct CMC_DEF_FKEY(SNAME) * f_key, struct CMC_DEF
}
struct SNAME *CMC_(PFX, _new_custom)(struct CMC_DEF_FKEY(SNAME) * f_key, struct CMC_DEF_FVAL(SNAME) * f_val,
struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -152,7 +152,7 @@ void CMC_(PFX, _free)(struct SNAME *_map_)
_map_->alloc->free(_map_);
}
void CMC_(PFX, _customize)(struct SNAME *_map_, struct CMC_ALLOC_NODE_NAME *alloc, struct CMC_CALLBACKS_NAME *callbacks)
void CMC_(PFX, _customize)(struct SNAME *_map_, CMC_ALLOC_TYPE alloc, CMC_CALLBACK_TYPE callbacks)
{
#ifdef CMC_DEV
CMC_DEV_FCALL;
@@ -241,7 +241,7 @@ bool CMC_(PFX, _insert)(struct SNAME *_map_, K key, V value)
_map_->count++;
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, create);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -267,7 +267,7 @@ bool CMC_(PFX, _update)(struct SNAME *_map_, K key, V new_value, V *old_value)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, update);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -409,7 +409,7 @@ bool CMC_(PFX, _remove)(struct SNAME *_map_, K key, V *out_value)
_map_->count--;
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, delete);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -438,7 +438,7 @@ bool CMC_(PFX, _max)(struct SNAME *_map_, K *key, V *value)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -467,7 +467,7 @@ bool CMC_(PFX, _min)(struct SNAME *_map_, K *key, V *value)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return true;
}
@@ -494,7 +494,7 @@ V CMC_(PFX, _get)(struct SNAME *_map_, K key)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return node->value;
}
@@ -521,7 +521,7 @@ V *CMC_(PFX, _get_ref)(struct SNAME *_map_, K key)
_map_->flag = CMC_FLAG_OK;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return &(node->value);
}
@@ -534,7 +534,7 @@ bool CMC_(PFX, _contains)(struct SNAME *_map_, K key)
bool result = CMC_(PFX, _impl_get_node)(_map_, key) != NULL;
CMC_CALLBACKS_CALL(_map_, read);
CMC_CALLBACKS_CALL(_map_);
return result;
}
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2019 Leonardo Vencovsky
*
* This file is part of the C Macro Collections Libray.
* This file is part of the C Macro Collections Library.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Loaded 100 of 153 files, more files were not shown because too many files have changed in this diff. Show more