summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md42
-rw-r--r--stc/cdeq.h22
2 files changed, 33 insertions, 31 deletions
diff --git a/README.md b/README.md
index cf837d15..61c814fb 100644
--- a/README.md
+++ b/README.md
@@ -1,27 +1,27 @@
-STC - C99 Standard Container library
-====================================
+STC - Standard Template library for C
+=====================================
Introduction
------------
-An elegant, fully typesafe, generic, customizable, user-friendly, consistent, and very fast standard container library for C99. This is a small headers only library with the most used container components, and a few algorithms:
-- [***carray*** - Generic dynamic **multi-dimensional array**](docs/carray_api.md)
+An modern, fully typesafe, generic, customizable, user-friendly, consistent, and very fast standard container library for C99. This is a small headers only library with the most used container components, and a few algorithms:
- [***cstr*** - Powerful and compact **string** type](docs/cstr_api.md)
-- [***cbitset*** - A *std::bitset*/*boost::dynamic_bitset*-like **bitset** type](docs/cbitset_api.md)
-- [***clist*** - Generic circular **singly linked list** type](docs/clist_api.md)
-- [***cmap*** - Generic fast **unordered map** type](docs/cmap_api.md)
-- [***cset*** - Generic fast **unordered set** type](docs/cset_api.md)
-- [***cvec*** - Generic dynamic **vector** type](docs/cvec_api.md)
-- [***cdeq*** - Generic dynamic **dequeue** type](docs/cdeq_api.md)
-- [***cstack*** - A **stack** adapter type](docs/cstack_api.md)
-- [***cqueue*** - A **queue** adapter type](docs/cqueue_api.md)
-- [***cpque*** - A **priority queue** adapter type](docs/cpque_api.md)
-- [***cptr*** - Support for pointers and shared pointers in containers](docs/cptr_api.md)
-- [***copt*** - Implements *copt_get()*, a **getopt_long**-like function](docs/copt_api.md)
-- [***crand*** - A few very efficent modern **random number generators**](docs/crand_api.md)
-- [***ccommon*** - Collection of general definitions](docs/ccommon_api.md)
-
-The usage of the containers is quite similar to the C++ standard containers, so it should be easy if you are familiar with them.
+- [***crand*** - An extremely efficent modern **random number generator**](docs/crand_api.md)
+- [***clist*** - Templated **std::forward_list** alike type](docs/clist_api.md)
+- [***cmap*** - Templated **std::unordered_map** alike type](docs/cmap_api.md)
+- [***cset*** - Templated **std::unordered_set** alike type](docs/cset_api.md)
+- [***cvec*** - Templated **std::vector** alike type](docs/cvec_api.md)
+- [***cdeq*** - Templated **std::dequeue** alike type](docs/cdeq_api.md)
+- [***cstack*** - Templated **std::stack** alike adapter type](docs/cstack_api.md)
+- [***cqueue*** - Templated **std::queue** alike adapter type](docs/cqueue_api.md)
+- [***cpque*** - Templated **std::priority_queue** alike adapter type](docs/cpque_api.md)
+- [***carray*** - Templated **multi-dimensional array** type](docs/carray_api.md)
+- [***cptr*** - Container pointers and **std::shared_ptr** alike support](docs/cptr_api.md)
+- [***cbitset*** - A **std::bitset** / **boost::dynamic_bitset* alike type](docs/cbitset_api.md)
+- [***copt*** - Implements *copt_get()*, a **getopt_long** alike function](docs/copt_api.md)
+- [***ccommon*** - General definitions](docs/ccommon_api.md)
+
+The usage of the containers is similar to the C++ standard containers, so it should be easy if you are familiar with them.
All containers mentioned above, except cstr_t and cbitset_t, are generic and therefore typesafe (similar to templates in C++). No casting is used. A simple example:
```C
@@ -67,7 +67,7 @@ int main(void) {
Motivation
----------
-The aim of this project was to create a small **Standard Container Library for the C99 language**. It should
+The aim of this project was to create a small **Standard Template library for the C language**. It should
- be easy to use, have intuitive naming and consistency across the library.
- be type safe. Have minimal usage of casting and void* pointers.
- be highly efficient. Both in speed and memory usage.
@@ -174,7 +174,7 @@ The containers are memory efficent, i.e. they occupy as little memory as practic
cmap discussion
---------------
-**cmap/cset** uses open hashing and is among the fastest hash-tables for C and C++. The default max load-factor is 0.85.
+**cmap / cset** uses open hashing and is among the fastest hash-tables for C and C++. The default max load-factor is 0.85.
You can customize the destroy-, hash-, equals- functions, but also define a convertion from a raw/literal type to the key-type specified. This is very useful when e.g. having cstr as key, and therefore a few using-macros are pre-defined
for cmaps with cstr_t keys and/or values:
diff --git a/stc/cdeq.h b/stc/cdeq.h
index 780da83e..e2cde0dc 100644
--- a/stc/cdeq.h
+++ b/stc/cdeq.h
@@ -69,7 +69,7 @@
STC_API void \
cdeq_##X##_resize(cdeq_##X* self, size_t size, Value fill_val); \
STC_API void \
- _cdeq_##X##_expand(cdeq_##X* self, size_t n, bool front); \
+ _cdeq_##X##_expand(cdeq_##X* self, size_t n, bool at_front); \
STC_INLINE void \
cdeq_##X##_swap(cdeq_##X* a, cdeq_##X* b) {c_swap(cdeq_##X, *a, *b);} \
\
@@ -231,10 +231,10 @@
} \
\
STC_DEF void \
- _cdeq_##X##_expand(cdeq_##X* self, size_t n, bool front) { \
+ _cdeq_##X##_expand(cdeq_##X* self, size_t n, bool at_front) { \
size_t len = cdeq_size(*self), cap = cdeq_capacity(*self); \
size_t nfront = self->data - self->base, nback = cap - (nfront + len); \
- if (front && nfront >= n || !front && nback >= n) \
+ if (at_front && nfront >= n || !at_front && nback >= n) \
return; \
if (len + n > cap) { \
cap = (len + n + 6)*3/2; \
@@ -245,8 +245,8 @@
rep[1] = cap; \
} \
size_t unused = cap - (len + n); \
- size_t pos = front ? c_maxf(unused*0.7, (float) unused - nback) + n \
- : c_minf(unused*0.3, nfront); \
+ size_t pos = at_front ? c_maxf(unused*0.7, (float) unused - nback) + n \
+ : c_minf(unused*0.3, nfront); \
memmove(self->base + pos, self->data, len*sizeof(Value)); \
self->data = self->base + pos; \
} \
@@ -281,11 +281,12 @@
} \
\
STC_DEF cdeq_##X##_iter_t \
- cdeq_##X##_insert_range_p(cdeq_##X* self, cdeq_##X##_value_t* pos, const cdeq_##X##_value_t* first, const cdeq_##X##_value_t* finish) { \
+ cdeq_##X##_insert_range_p(cdeq_##X* self, cdeq_##X##_value_t* pos, \
+ const cdeq_##X##_value_t* first, const cdeq_##X##_value_t* finish) { \
size_t n = finish - first, idx = pos - self->data, size = cdeq_size(*self); \
- bool is_front = (pos == self->data); \
- _cdeq_##X##_expand(self, n, is_front); \
- if (is_front) \
+ bool at_front = (pos == self->data); \
+ _cdeq_##X##_expand(self, n, at_front); \
+ if (at_front) \
pos = (self->data -= n); \
else { \
pos = self->data + idx; \
@@ -304,7 +305,8 @@
if (len > 0) { \
cdeq_##X##_value_t* p = first, *end = self->data + _cdeq_size(self); \
while (p != finish) valueDestroy(p++); \
- memmove(first, finish, (end - finish) * sizeof(Value)); \
+ if (first == self->data) self->data += len; \
+ else memmove(first, finish, (end - finish) * sizeof(Value)); \
_cdeq_size(self) -= len; \
} \
cdeq_##X##_iter_t it = {first}; return it; \