diff options
| author | Tyge Løvset <[email protected]> | 2020-09-16 09:59:18 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-09-16 09:59:18 +0200 |
| commit | 47b5b5ce53ed4607bf557e2b53a1286bc8041e94 (patch) | |
| tree | 71219fd9554c957b4e120d34096318fc11f8fc80 /examples | |
| parent | d3d68271e1c4ff0f56d06730f79349197f46850c (diff) | |
| download | STC-modified-47b5b5ce53ed4607bf557e2b53a1286bc8041e94.tar.gz STC-modified-47b5b5ce53ed4607bf557e2b53a1286bc8041e94.zip | |
Changed earlier declare_<container>(..) macro to typedef_<container>(..)
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/README.md | 4 | ||||
| -rw-r--r-- | examples/advanced.c | 4 | ||||
| -rw-r--r-- | examples/benchmark.c | 240 | ||||
| -rw-r--r-- | examples/birthday.c | 6 | ||||
| -rw-r--r-- | examples/complex.c | 8 | ||||
| -rw-r--r-- | examples/demos.c | 16 | ||||
| -rw-r--r-- | examples/ex_gaussian.c | 4 | ||||
| -rw-r--r-- | examples/heap.c | 4 | ||||
| -rw-r--r-- | examples/inits.c | 12 | ||||
| -rw-r--r-- | examples/list.c | 2 | ||||
| -rw-r--r-- | examples/mapmap.c | 4 | ||||
| -rw-r--r-- | examples/phonebook.c | 2 | ||||
| -rw-r--r-- | examples/priority.c | 4 | ||||
| -rw-r--r-- | examples/queue.c | 4 | ||||
| -rw-r--r-- | examples/stack.c | 8 | ||||
| -rw-r--r-- | examples/words.c | 6 |
16 files changed, 164 insertions, 164 deletions
diff --git a/examples/README.md b/examples/README.md index d12cc522..8820f5cf 100644 --- a/examples/README.md +++ b/examples/README.md @@ -51,9 +51,9 @@ static inline Viking viking_fromVw(VikingVw vw) { // note: parameter is by value Viking vk = {cstr(vw.name), cstr(vw.country)}; return vk;
}
```
-With this in place, we use the full c_cmap() macro to define {Viking -> int} hash map type:
+With this in place, we use the full typedef_cmap() macro to define {Viking -> int} hash map type:
```
-c_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
+typedef_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
viking_destroy, VikingVw, viking_toVw, viking_fromVw);
```
cmap_vk uses vikingvw_hash() for hash value calculations, and vikingvw_equals() for equality test. cmap_vk_destroy() will free all memory allocated for Viking keys and the hash table values.
diff --git a/examples/advanced.c b/examples/advanced.c index 0570ce55..2c736e2d 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -50,8 +50,8 @@ Viking viking_fromVw(VikingVw vw) { Viking vk = {cstr(vw.name), cstr(vw.country)}; return vk; } -// Using the full c_cmap() macro to define [Viking -> int] hash map type: -c_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash, +// Using the full typedef_cmap() macro to define [Viking -> int] hash map type: +typedef_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash, viking_destroy, VikingVw, viking_toVw, viking_fromVw); // cmap_vk uses vikingvw_hash() for hash value calculations, and vikingvw_equals() for equality test. diff --git a/examples/benchmark.c b/examples/benchmark.c index 0a492d3d..969cf3cc 100644 --- a/examples/benchmark.c +++ b/examples/benchmark.c @@ -22,7 +22,7 @@ static inline uint32_t fibonacci_hash(const void* data, size_t len) { }
// cmap and khash template expansion
-c_cmap(ii, int64_t, int64_t, c_default_destroy, c_default_equals, fibonacci_hash);
+typedef_cmap(ii, int64_t, int64_t, c_default_destroy, c_default_equals, fibonacci_hash);
KHASH_MAP_INIT_INT64(ii, int64_t)
@@ -34,100 +34,100 @@ crand_rng64_t rng; #define RAND(N) (crand_i64(&rng) & ((1 << N) - 1))
-#define CMAP_SETUP(tt, Key, Value) cmap_##tt map = cmap_ini \
- ; cmap_##tt##_set_load_factors(&map, max_load_factor, 0.0)
-#define CMAP_PUT(tt, key, val) cmap_##tt##_put(&map, key, val).first->second
-#define CMAP_EMPLACE(tt, key, val) cmap_##tt##_emplace(&map, key, val)
-#define CMAP_ERASE(tt, key) cmap_##tt##_erase(&map, key)
-#define CMAP_FIND(tt, key) (cmap_##tt##_find(map, key) != NULL)
-#define CMAP_FOR(tt, i) c_foreach (i, cmap_##tt, map)
-#define CMAP_ITEM(tt, i) i.get->second
-#define CMAP_SIZE(tt) cmap_size(map)
-#define CMAP_BUCKETS(tt) cmap_bucket_count(map)
-#define CMAP_CLEAR(tt) cmap_##tt##_clear(&map)
-#define CMAP_DTOR(tt) cmap_##tt##_destroy(&map)
-
-#define KMAP_SETUP(tt, Key, Value) khash_t(ii)* map = kh_init(ii); khiter_t ki; int ret
-#define KMAP_PUT(tt, key, val) (*(ki = kh_put(ii, map, key, &ret), map->vals[ki] = val, &map->vals[ki]))
-#define KMAP_EMPLACE(tt, key, val) (ki = kh_put(ii, map, key, &ret), ret ? (map->vals[ki] = val) : val)
-#define KMAP_ERASE(tt, key) ((ki = kh_get(ii, map, key)) != kh_end(map) ? kh_del(ii, map, ki), 1 : 0)
-#define KMAP_FIND(tt, key) (kh_get(ii, map, key) != kh_end(map))
-#define KMAP_SIZE(tt) kh_size(map)
-#define KMAP_BUCKETS(tt) kh_n_buckets(map)
-#define KMAP_CLEAR(tt) kh_clear(ii, map)
-#define KMAP_DTOR(tt) kh_destroy(ii, map)
-
-#define UMAP_SETUP(tt, Key, Value) std::unordered_map<Key, Value> map; map.max_load_factor(max_load_factor)
-#define UMAP_PUT(tt, key, val) (map[key] = val)
-#define UMAP_EMPLACE(tt, key, val) map.emplace(key, val)
-#define UMAP_FIND(tt, key) (map.find(key) != map.end())
-#define UMAP_ERASE(tt, key) map.erase(key)
-#define UMAP_FOR(tt, i) for (auto i: map)
-#define UMAP_ITEM(tt, i) i.second
-#define UMAP_SIZE(tt) map.size()
-#define UMAP_BUCKETS(tt) map.bucket_count()
-#define UMAP_CLEAR(tt) map.clear()
-#define UMAP_DTOR(tt) destroy_me(map)
-
-#define BMAP_SETUP(tt, Key, Value) ska::bytell_hash_map<Key, Value> map; map.max_load_factor(max_load_factor)
-#define BMAP_PUT(tt, key, val) UMAP_PUT(tt, key, val)
-#define BMAP_EMPLACE(tt, key, val) UMAP_EMPLACE(tt, key, val)
-#define BMAP_FIND(tt, key) UMAP_FIND(tt, key)
-#define BMAP_ERASE(tt, key) UMAP_ERASE(tt, key)
-#define BMAP_FOR(tt, i) UMAP_FOR(tt, i)
-#define BMAP_ITEM(tt, i) UMAP_ITEM(tt, i)
-#define BMAP_SIZE(tt) UMAP_SIZE(tt)
-#define BMAP_BUCKETS(tt) UMAP_BUCKETS(tt)
-#define BMAP_CLEAR(tt) UMAP_CLEAR(tt)
-#define BMAP_DTOR(tt) UMAP_DTOR(tt)
-
-#define FMAP_SETUP(tt, Key, Value) ska::flat_hash_map<Key, Value> map; map.max_load_factor(max_load_factor)
-#define FMAP_PUT(tt, key, val) UMAP_PUT(tt, key, val)
-#define FMAP_EMPLACE(tt, key, val) UMAP_EMPLACE(tt, key, val)
-#define FMAP_FIND(tt, key) UMAP_FIND(tt, key)
-#define FMAP_ERASE(tt, key) UMAP_ERASE(tt, key)
-#define FMAP_FOR(tt, i) UMAP_FOR(tt, i)
-#define FMAP_ITEM(tt, i) UMAP_ITEM(tt, i)
-#define FMAP_SIZE(tt) UMAP_SIZE(tt)
-#define FMAP_BUCKETS(tt) UMAP_BUCKETS(tt)
-#define FMAP_CLEAR(tt) UMAP_CLEAR(tt)
-#define FMAP_DTOR(tt) UMAP_DTOR(tt)
-
-#define HMAP_SETUP(tt, Key, Value) tsl::hopscotch_map<Key, Value> map; map.max_load_factor(max_load_factor)
-#define HMAP_PUT(tt, key, val) UMAP_PUT(tt, key, val)
-#define HMAP_EMPLACE(tt, key, val) UMAP_EMPLACE(tt, key, val)
-#define HMAP_FIND(tt, key) UMAP_FIND(tt, key)
-#define HMAP_ERASE(tt, key) UMAP_ERASE(tt, key)
-#define HMAP_FOR(tt, i) UMAP_FOR(tt, i)
-#define HMAP_ITEM(tt, i) UMAP_ITEM(tt, i)
-#define HMAP_SIZE(tt) UMAP_SIZE(tt)
-#define HMAP_BUCKETS(tt) UMAP_BUCKETS(tt)
-#define HMAP_CLEAR(tt) UMAP_CLEAR(tt)
-#define HMAP_DTOR(tt) UMAP_DTOR(tt)
-
-#define RMAP_SETUP(tt, Key, Value) robin_hood::unordered_map<Key, Value> map
-#define RMAP_PUT(tt, key, val) UMAP_PUT(tt, key, val)
-#define RMAP_EMPLACE(tt, key, val) UMAP_EMPLACE(tt, key, val)
-#define RMAP_FIND(tt, key) UMAP_FIND(tt, key)
-#define RMAP_ERASE(tt, key) UMAP_ERASE(tt, key)
-#define RMAP_FOR(tt, i) UMAP_FOR(tt, i)
-#define RMAP_ITEM(tt, i) UMAP_ITEM(tt, i)
-#define RMAP_SIZE(tt) UMAP_SIZE(tt)
-#define RMAP_BUCKETS(tt) map.mask()
-#define RMAP_CLEAR(tt) UMAP_CLEAR(tt)
-#define RMAP_DTOR(tt) UMAP_DTOR(tt)
-
-#define SMAP_SETUP(tt, Key, Value) spp::sparse_hash_map<Key, Value> map; map.max_load_factor(max_load_factor)
-#define SMAP_PUT(tt, key, val) UMAP_PUT(tt, key, val)
-#define SMAP_EMPLACE(tt, key, val) UMAP_EMPLACE(tt, key, val)
-#define SMAP_FIND(tt, key) UMAP_FIND(tt, key)
-#define SMAP_ERASE(tt, key) UMAP_ERASE(tt, key)
-#define SMAP_FOR(tt, i) UMAP_FOR(tt, i)
-#define SMAP_ITEM(tt, i) UMAP_ITEM(tt, i)
-#define SMAP_SIZE(tt) UMAP_SIZE(tt)
-#define SMAP_BUCKETS(tt) UMAP_BUCKETS(tt)
-#define SMAP_CLEAR(tt) UMAP_CLEAR(tt)
-#define SMAP_DTOR(tt) UMAP_DTOR(tt)
+#define CMAP_SETUP(X, Key, Value) cmap_##X map = cmap_ini \
+ ; cmap_##X##_set_load_factors(&map, max_load_factor, 0.0)
+#define CMAP_PUT(X, key, val) cmap_##X##_put(&map, key, val).first->second
+#define CMAP_EMPLACE(X, key, val) cmap_##X##_emplace(&map, key, val)
+#define CMAP_ERASE(X, key) cmap_##X##_erase(&map, key)
+#define CMAP_FIND(X, key) (cmap_##X##_find(map, key) != NULL)
+#define CMAP_FOR(X, i) c_foreach (i, cmap_##X, map)
+#define CMAP_ITEM(X, i) i.get->second
+#define CMAP_SIZE(X) cmap_size(map)
+#define CMAP_BUCKETS(X) cmap_##X##_bucket_count(map)
+#define CMAP_CLEAR(X) cmap_##X##_clear(&map)
+#define CMAP_DTOR(X) cmap_##X##_destroy(&map)
+
+#define KMAP_SETUP(X, Key, Value) khash_t(ii)* map = kh_init(ii); khiter_t ki; int ret
+#define KMAP_PUT(X, key, val) (*(ki = kh_put(ii, map, key, &ret), map->vals[ki] = val, &map->vals[ki]))
+#define KMAP_EMPLACE(X, key, val) (ki = kh_put(ii, map, key, &ret), ret ? (map->vals[ki] = val) : val)
+#define KMAP_ERASE(X, key) ((ki = kh_get(ii, map, key)) != kh_end(map) ? kh_del(ii, map, ki), 1 : 0)
+#define KMAP_FIND(X, key) (kh_get(ii, map, key) != kh_end(map))
+#define KMAP_SIZE(X) kh_size(map)
+#define KMAP_BUCKETS(X) kh_n_buckets(map)
+#define KMAP_CLEAR(X) kh_clear(ii, map)
+#define KMAP_DTOR(X) kh_destroy(ii, map)
+
+#define UMAP_SETUP(X, Key, Value) std::unordered_map<Key, Value> map; map.max_load_factor(max_load_factor)
+#define UMAP_PUT(X, key, val) (map[key] = val)
+#define UMAP_EMPLACE(X, key, val) map.emplace(key, val)
+#define UMAP_FIND(X, key) (map.find(key) != map.end())
+#define UMAP_ERASE(X, key) map.erase(key)
+#define UMAP_FOR(X, i) for (auto i: map)
+#define UMAP_ITEM(X, i) i.second
+#define UMAP_SIZE(X) map.size()
+#define UMAP_BUCKETS(X) map.bucket_count()
+#define UMAP_CLEAR(X) map.clear()
+#define UMAP_DTOR(X) destroy_me(map)
+
+#define BMAP_SETUP(X, Key, Value) ska::bytell_hash_map<Key, Value> map; map.max_load_factor(max_load_factor)
+#define BMAP_PUT(X, key, val) UMAP_PUT(X, key, val)
+#define BMAP_EMPLACE(X, key, val) UMAP_EMPLACE(X, key, val)
+#define BMAP_FIND(X, key) UMAP_FIND(X, key)
+#define BMAP_ERASE(X, key) UMAP_ERASE(X, key)
+#define BMAP_FOR(X, i) UMAP_FOR(X, i)
+#define BMAP_ITEM(X, i) UMAP_ITEM(X, i)
+#define BMAP_SIZE(X) UMAP_SIZE(X)
+#define BMAP_BUCKETS(X) UMAP_BUCKETS(X)
+#define BMAP_CLEAR(X) UMAP_CLEAR(X)
+#define BMAP_DTOR(X) UMAP_DTOR(X)
+
+#define FMAP_SETUP(X, Key, Value) ska::flat_hash_map<Key, Value> map; map.max_load_factor(max_load_factor)
+#define FMAP_PUT(X, key, val) UMAP_PUT(X, key, val)
+#define FMAP_EMPLACE(X, key, val) UMAP_EMPLACE(X, key, val)
+#define FMAP_FIND(X, key) UMAP_FIND(X, key)
+#define FMAP_ERASE(X, key) UMAP_ERASE(X, key)
+#define FMAP_FOR(X, i) UMAP_FOR(X, i)
+#define FMAP_ITEM(X, i) UMAP_ITEM(X, i)
+#define FMAP_SIZE(X) UMAP_SIZE(X)
+#define FMAP_BUCKETS(X) UMAP_BUCKETS(X)
+#define FMAP_CLEAR(X) UMAP_CLEAR(X)
+#define FMAP_DTOR(X) UMAP_DTOR(X)
+
+#define HMAP_SETUP(X, Key, Value) tsl::hopscotch_map<Key, Value> map; map.max_load_factor(max_load_factor)
+#define HMAP_PUT(X, key, val) UMAP_PUT(X, key, val)
+#define HMAP_EMPLACE(X, key, val) UMAP_EMPLACE(X, key, val)
+#define HMAP_FIND(X, key) UMAP_FIND(X, key)
+#define HMAP_ERASE(X, key) UMAP_ERASE(X, key)
+#define HMAP_FOR(X, i) UMAP_FOR(X, i)
+#define HMAP_ITEM(X, i) UMAP_ITEM(X, i)
+#define HMAP_SIZE(X) UMAP_SIZE(X)
+#define HMAP_BUCKETS(X) UMAP_BUCKETS(X)
+#define HMAP_CLEAR(X) UMAP_CLEAR(X)
+#define HMAP_DTOR(X) UMAP_DTOR(X)
+
+#define RMAP_SETUP(X, Key, Value) robin_hood::unordered_map<Key, Value> map
+#define RMAP_PUT(X, key, val) UMAP_PUT(X, key, val)
+#define RMAP_EMPLACE(X, key, val) UMAP_EMPLACE(X, key, val)
+#define RMAP_FIND(X, key) UMAP_FIND(X, key)
+#define RMAP_ERASE(X, key) UMAP_ERASE(X, key)
+#define RMAP_FOR(X, i) UMAP_FOR(X, i)
+#define RMAP_ITEM(X, i) UMAP_ITEM(X, i)
+#define RMAP_SIZE(X) UMAP_SIZE(X)
+#define RMAP_BUCKETS(X) map.mask()
+#define RMAP_CLEAR(X) UMAP_CLEAR(X)
+#define RMAP_DTOR(X) UMAP_DTOR(X)
+
+#define SMAP_SETUP(X, Key, Value) spp::sparse_hash_map<Key, Value> map; map.max_load_factor(max_load_factor)
+#define SMAP_PUT(X, key, val) UMAP_PUT(X, key, val)
+#define SMAP_EMPLACE(X, key, val) UMAP_EMPLACE(X, key, val)
+#define SMAP_FIND(X, key) UMAP_FIND(X, key)
+#define SMAP_ERASE(X, key) UMAP_ERASE(X, key)
+#define SMAP_FOR(X, i) UMAP_FOR(X, i)
+#define SMAP_ITEM(X, i) UMAP_ITEM(X, i)
+#define SMAP_SIZE(X) UMAP_SIZE(X)
+#define SMAP_BUCKETS(X) UMAP_BUCKETS(X)
+#define SMAP_CLEAR(X) UMAP_CLEAR(X)
+#define SMAP_DTOR(X) UMAP_DTOR(X)
enum {
FAC = 3,
@@ -140,68 +140,68 @@ enum { int rr = RR;
-#define MAP_TEST1(M, tt) \
+#define MAP_TEST1(M, X) \
{ \
- M##_SETUP(tt, int64_t, int64_t); \
+ M##_SETUP(X, int64_t, int64_t); \
uint64_t checksum = 0, erased = 0; \
SEED(seed); \
clock_t difference, before = clock(); \
for (size_t i = 0; i < N1; ++i) { \
- checksum += ++ M##_PUT(tt, RAND(rr), i); \
- erased += M##_ERASE(tt, RAND(rr)); \
+ checksum += ++ M##_PUT(X, RAND(rr), i); \
+ erased += M##_ERASE(X, RAND(rr)); \
} \
difference = clock() - before; \
printf(#M ": size: %zu, buckets: %8zu, time: %5.02f, sum: %zu, erased %zu\n", \
- (size_t) M##_SIZE(tt), (size_t) M##_BUCKETS(tt), (float) difference / CLOCKS_PER_SEC, checksum, erased); \
- M##_CLEAR(tt); \
+ (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), (float) difference / CLOCKS_PER_SEC, checksum, erased); \
+ M##_CLEAR(X); \
}
-#define MAP_TEST2(M, tt) \
+#define MAP_TEST2(M, X) \
{ \
- M##_SETUP(tt, int64_t, int64_t); \
+ M##_SETUP(X, int64_t, int64_t); \
size_t erased = 0; \
clock_t difference, before = clock(); \
for (size_t i = 0; i < N2; ++i) \
- M##_PUT(tt, i, i); \
+ M##_PUT(X, i, i); \
for (size_t i = 0; i < N2; ++i) \
- erased += M##_ERASE(tt, i); \
+ erased += M##_ERASE(X, i); \
difference = clock() - before; \
printf(#M ": size: %zu, buckets: %8zu, time: %5.02f, erased %zu\n", \
- (size_t) M##_SIZE(tt), (size_t) M##_BUCKETS(tt), (float) difference / CLOCKS_PER_SEC, erased); \
- M##_CLEAR(tt); \
+ (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), (float) difference / CLOCKS_PER_SEC, erased); \
+ M##_CLEAR(X); \
}
-#define MAP_TEST3(M, tt) \
+#define MAP_TEST3(M, X) \
{ \
- M##_SETUP(tt, int64_t, int64_t); \
+ M##_SETUP(X, int64_t, int64_t); \
size_t erased = 0; \
clock_t difference, before = clock(); \
SEED(seed); \
for (size_t i = 0; i < N3; ++i) \
- M##_PUT(tt, RAND(rr), i); \
+ M##_PUT(X, RAND(rr), i); \
SEED(seed); \
for (size_t i = 0; i < N3; ++i) \
- erased += M##_ERASE(tt, RAND(rr)); \
+ erased += M##_ERASE(X, RAND(rr)); \
difference = clock() - before; \
printf(#M ": size: %zu, buckets: %8zu, time: %5.02f, erased %zu\n", \
- (size_t) M##_SIZE(tt), (size_t) M##_BUCKETS(tt), (float) difference / CLOCKS_PER_SEC, erased); \
- M##_CLEAR(tt); \
+ (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), (float) difference / CLOCKS_PER_SEC, erased); \
+ M##_CLEAR(X); \
}
-#define MAP_TEST4(M, tt) \
+#define MAP_TEST4(M, X) \
{ \
- M##_SETUP(tt, int64_t, int64_t); \
+ M##_SETUP(X, int64_t, int64_t); \
size_t sum = 0; \
SEED(seed); \
for (size_t i = 0; i < N4; ++i) \
- M##_PUT(tt, RAND(rr), i); \
+ M##_PUT(X, RAND(rr), i); \
clock_t difference, before = clock(); \
- for (int k=0; k<5; k++) M##_FOR (tt, i) \
- sum += M##_ITEM(tt, i); \
+ for (int k=0; k<5; k++) M##_FOR (X, i) \
+ sum += M##_ITEM(X, i); \
difference = clock() - before; \
printf(#M ": size: %zu, buckets: %8zu, time: %5.02f, sum %zu\n", \
- (size_t) M##_SIZE(tt), (size_t) M##_BUCKETS(tt), (float) difference / CLOCKS_PER_SEC, sum); \
- M##_CLEAR(tt); \
+ (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), (float) difference / CLOCKS_PER_SEC, sum); \
+ M##_CLEAR(X); \
}
diff --git a/examples/birthday.c b/examples/birthday.c index 1cd57066..e085e25c 100644 --- a/examples/birthday.c +++ b/examples/birthday.c @@ -7,7 +7,7 @@ #include <stc/cvec.h>
#include <stc/cstr.h>
-c_cmap(ic, uint64_t, uint8_t);
+typedef_cmap(ic, uint64_t, uint8_t);
const static uint64_t seed = 1234;
const static uint64_t N = 1ull << 27;
@@ -29,8 +29,8 @@ void repeats(void) }
-c_cmap(x, uint32_t, uint64_t);
-c_cvec(x, uint64_t);
+typedef_cmap(x, uint32_t, uint64_t);
+typedef_cvec(x, uint64_t);
void distribution(void)
{
diff --git a/examples/complex.c b/examples/complex.c index aa746b90..e0bc5200 100644 --- a/examples/complex.c +++ b/examples/complex.c @@ -5,10 +5,10 @@ void check_destroy(float* v) {printf("destroy %g\n", *v);}
-c_carray(f, float, check_destroy); // normally omit the last argument - float type need no destroy.
-c_clist(y, carray2f, carray2f_destroy, c_no_compare);
-c_cmap(g, int, clist_y, clist_y_destroy);
-c_cmap_strkey(s, cmap_g, cmap_g_destroy);
+typedef_carray(f, float, check_destroy); // normally omit the last argument - float type need no destroy.
+typedef_clist(y, carray2f, carray2f_destroy, c_no_compare);
+typedef_cmap(g, int, clist_y, clist_y_destroy);
+typedef_cmap_strkey(s, cmap_g, cmap_g_destroy);
int main() {
int xdim = 4, ydim = 6;
diff --git a/examples/demos.c b/examples/demos.c index 0247945d..634e4dde 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -34,7 +34,7 @@ void stringdemo1() }
-c_cvec(ix, int64_t); // ix is just an example tag name.
+typedef_cvec(ix, int64_t); // ix is just an example tag name.
void vectordemo1()
{
@@ -55,7 +55,7 @@ void vectordemo1() -c_cvec_str();
+typedef_cvec_str();
void vectordemo2()
{
@@ -73,7 +73,7 @@ void vectordemo2() cvec_str_destroy(&names);
}
-c_clist(ix, int);
+typedef_clist(ix, int);
void listdemo1()
{
@@ -100,7 +100,7 @@ void listdemo1() clist_ix_destroy(&nums);
}
-c_cset(i, int);
+typedef_cset(i, int);
void setdemo1()
{
@@ -115,7 +115,7 @@ void setdemo1() }
-c_cmap(ii, int, int);
+typedef_cmap(ii, int, int);
void mapdemo1()
{
@@ -128,7 +128,7 @@ void mapdemo1() }
-c_cmap_strkey(si, int); // Shorthand macro for the general c_cmap expansion.
+typedef_cmap_strkey(si, int); // Shorthand macro for the general typedef_cmap expansion.
void mapdemo2()
{
@@ -150,7 +150,7 @@ void mapdemo2() }
-c_cmap_str();
+typedef_cmap_str();
void mapdemo3()
{
@@ -172,7 +172,7 @@ void mapdemo3() }
-c_carray(f, float);
+typedef_carray(f, float);
void arraydemo1()
{
diff --git a/examples/ex_gaussian.c b/examples/ex_gaussian.c index 559512ce..3c3a05bf 100644 --- a/examples/ex_gaussian.c +++ b/examples/ex_gaussian.c @@ -7,14 +7,14 @@ #include <stc/cvec.h>
// Declare int -> int hashmap. Uses typetag 'i' for ints.
-c_cmap(i, int, size_t);
+typedef_cmap(i, int, size_t);
// Declare int vector with map entries that can be sorted by map keys.
static int compare(cmap_i_entry_t *a, cmap_i_entry_t *b) {
return c_default_compare(&a->first, &b->first);
}
// Vector: typetag 'e' for (map) entry
-c_cvec(e, cmap_i_entry_t, c_default_destroy, compare);
+typedef_cvec(e, cmap_i_entry_t, c_default_destroy, compare);
int main()
{
diff --git a/examples/heap.c b/examples/heap.c index 99806c17..18ba247c 100644 --- a/examples/heap.c +++ b/examples/heap.c @@ -4,8 +4,8 @@ #include <stc/cvec.h>
#include <stc/cpqueue.h>
-c_cvec(f, float);
-c_cpqueue(f, cvec_f, >);
+typedef_cvec(f, float);
+typedef_cpqueue(f, cvec_f, >);
int main()
{
diff --git a/examples/inits.c b/examples/inits.c index 6540290a..4d07cb02 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -5,19 +5,19 @@ #include <stc/cpqueue.h>
#include <stc/clist.h>
-c_cmap(id, int, cstr_t, cstr_destroy); // Map of int -> cstr_t
-c_cmap_strkey(cnt, int);
+typedef_cmap(id, int, cstr_t, cstr_destroy); // Map of int -> cstr_t
+typedef_cmap_strkey(cnt, int);
typedef struct {int x, y;} ipair_t;
inline static int ipair_compare(const ipair_t* a, const ipair_t* b) {
int c = c_default_compare(&a->x, &b->x);
return c != 0 ? c : c_default_compare(&a->y, &b->y);
}
-c_cvec(ip, ipair_t, c_default_destroy, ipair_compare);
-c_clist(ip, ipair_t, c_default_destroy, ipair_compare);
+typedef_cvec(ip, ipair_t, c_default_destroy, ipair_compare);
+typedef_clist(ip, ipair_t, c_default_destroy, ipair_compare);
-c_cvec(f, float);
-c_cpqueue(f, cvec_f, >);
+typedef_cvec(f, float);
+typedef_cpqueue(f, cvec_f, >);
int main(void) {
diff --git a/examples/list.c b/examples/list.c index a0a3b456..55e6c419 100644 --- a/examples/list.c +++ b/examples/list.c @@ -2,7 +2,7 @@ #include <time.h>
#include <stc/clist.h>
#include <stc/crandom.h>
-c_clist(fx, double);
+typedef_clist(fx, double);
int main() {
int k, n = 100000;
diff --git a/examples/mapmap.c b/examples/mapmap.c index 50806e3d..f40d6be5 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -3,8 +3,8 @@ #include <stc/cmap.h>
#include <stc/cstr.h>
-c_cmap_str();
-c_cmap_strkey(cfg, cmap_str, cmap_str_destroy);
+typedef_cmap_str();
+typedef_cmap_strkey(cfg, cmap_str, cmap_str_destroy);
int main(void) {
cmap_cfg config = cmap_ini;
diff --git a/examples/phonebook.c b/examples/phonebook.c index 5395d774..66b54e33 100644 --- a/examples/phonebook.c +++ b/examples/phonebook.c @@ -25,7 +25,7 @@ #include <stc/cmap.h>
#include <stc/cstr.h>
-c_cmap_str();
+typedef_cmap_str();
void print_phone_book(cmap_str phone_book)
{
diff --git a/examples/priority.c b/examples/priority.c index 1a8eff78..d35ec4c7 100644 --- a/examples/priority.c +++ b/examples/priority.c @@ -6,8 +6,8 @@ #include <stc/cmap.h>
#include <stc/crandom.h>
-c_cvec(i, int64_t);
-c_cpqueue(i, cvec_i, >); // min-heap (increasing values)
+typedef_cvec(i, int64_t);
+typedef_cpqueue(i, cvec_i, >); // min-heap (increasing values)
int main() {
size_t N = 10000000;
diff --git a/examples/queue.c b/examples/queue.c index addecaa6..330e79fe 100644 --- a/examples/queue.c +++ b/examples/queue.c @@ -2,8 +2,8 @@ #include <stc/cqueue.h>
#include <stdio.h>
-c_clist(i, int);
-c_cqueue(i, clist_i); // min-heap (increasing values)
+typedef_clist(i, int);
+typedef_cqueue(i, clist_i); // min-heap (increasing values)
int main() {
int n = 10000000;
diff --git a/examples/stack.c b/examples/stack.c index ba7de082..c51c420c 100644 --- a/examples/stack.c +++ b/examples/stack.c @@ -3,10 +3,10 @@ #include <stc/cstr.h>
#include <stc/cstack.h>
-c_cvec(i, int);
-c_cvec(c, char);
-c_cstack(i, cvec_i);
-c_cstack(c, cvec_c);
+typedef_cvec(i, int);
+typedef_cvec(c, char);
+typedef_cstack(i, cvec_i);
+typedef_cstack(c, cvec_c);
int main() {
cstack_i stack = cstack_i_init();
diff --git a/examples/words.c b/examples/words.c index fe738d0d..70a4878f 100644 --- a/examples/words.c +++ b/examples/words.c @@ -4,9 +4,9 @@ #include <stc/clist.h> #include <stc/cvec.h> -c_cvec_str(); -c_clist_str(); -c_cmap_strkey(si, int); +typedef_cvec_str(); +typedef_clist_str(); +typedef_cmap_strkey(si, int); int main1() |
