summaryrefslogtreecommitdiff
path: root/src/data/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/map.c')
-rw-r--r--src/data/map.c74
1 files changed, 34 insertions, 40 deletions
diff --git a/src/data/map.c b/src/data/map.c
index 3c95dc2..b5c016e 100644
--- a/src/data/map.c
+++ b/src/data/map.c
@@ -1,12 +1,12 @@
/*:*
*: File: ./src/data/map.c
- *: A simple Fype interpreter
+ *: A simple interpreter
*:
- *: WWW: http://fype.buetow.org
- *: AUTHOR: http://paul.buetow.org
- *: E-Mail: fype at dev.buetow.org
+ *: WWW : http://fype.buetow.org
+ *: E-Mail : fype@dev.buetow.org
*:
- *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow
+ *: All rights reserved.
*:
*: Redistribution and use in source and binary forms, with or without modi-
*: fication, are permitted provided that the following conditions are met:
@@ -15,14 +15,14 @@
*: * Redistributions in binary form must reproduce the above copyright
*: notice, this list of conditions and the following disclaimer in the
*: documentation and/or other materials provided with the distribution.
- *: * Neither the name of buetow.org nor the names of its contributors may
+ *: * Neither the name of P. B. Labs nor the names of its contributors may
*: be used to endorse or promote products derived from this software
*: without specific prior written permission.
*:
- *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: THIS SOFTWARE IS PROVIDED BY Paul Buetow AS IS'' AND ANY EXPRESS OR
*: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
*: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: DISCLAIMED. IN NO EVENT SHALL Paul Buetow BE LIABLE FOR ANY DIRECT,
*: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
*: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
*: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@@ -36,7 +36,7 @@
Map*
map_new(int i_max_size) {
- return (map_new_named(i_max_size, "noname"));
+ return map_new_named(i_max_size, "noname");
}
Map*
@@ -55,29 +55,29 @@ map_new_named(int i_max_size, char *c_name) {
p_map->i_size = 0;
p_map->i_max_size = i_max_size;
- return (p_map);
+ return p_map;
}
_Bool
map_empty(Map *p_map) {
- return (p_map->i_size == 0);
+ return p_map->i_size == 0;
}
_Bool
map_full(Map *p_map) {
- return (p_map->i_size == p_map->i_max_size);
+ return p_map->i_size == p_map->i_max_size;
}
int
map_next_free_addr(Map *p_map) {
for (int i = 0; i < p_map->i_max_size; ++i)
if (p_map->pc_keys[i] == NULL)
- return (i);
+ return i;
ERROR("No free space left in the map (%s)", p_map->c_name);
// This point should not be reached!
- return (0);
+ return 0;
}
_Bool
@@ -90,14 +90,14 @@ map_insert(Map *p_map, char *c_key, void *p_val) {
p_map->pp_vals[i_free_addr] = p_val;
++p_map->i_size;
- return (true);
+ return true;
}
_Bool
map_insert2(Map *p_map, char *c_key1, char *c_key2, void *p_val) {
char c_key[HASH_MKEYLEN];
sprintf(c_key, "%s%s%s", c_key1, SEP, c_key2);
- return (map_insert(p_map, c_key, p_val));
+ return map_insert(p_map, c_key, p_val);
}
_Bool
@@ -105,11 +105,11 @@ map_insert_if_not_exists(Map *p_map, char *c_key, void *p_val) {
void *p_void = map_get(p_map, c_key);
if (p_void)
- return (false);
+ return false;
- return (map_insert(p_map, c_key, p_val));
+ return map_insert(p_map, c_key, p_val);
- return (true);
+ return true;
}
void
@@ -130,33 +130,33 @@ map_remove(Map *p_map, char *c_key) {
void*
map_get(Map *p_map, char *c_key) {
if (map_empty(p_map))
- return (NULL);
+ return NULL;
int i_index = map_get_addr(p_map, c_key);
- return (i_index >= 0 ? p_map->pp_vals[i_index] : NULL);
+ return i_index >= 0 ? p_map->pp_vals[i_index] : NULL;
}
void*
map_get2(Map *p_map, char *c_key1, char *c_key2) {
char c_key[HASH_MKEYLEN];
sprintf(c_key, "%s%s%s", c_key1, SEP, c_key2);
- return (map_get(p_map, c_key));
+ return map_get(p_map, c_key);
}
_Bool
map_exists(Map *p_map, char *c_key) {
if (map_empty(p_map))
- return (false);
+ return false;
int i_index = map_get_addr(p_map, c_key);
- return (i_index >= 0 ? true : false);
+ return i_index >= 0 ? true : false;
}
_Bool
map_exists2(Map *p_map, char *c_key1, char *c_key2) {
if (map_empty(p_map))
- return (false);
+ return false;
char c_key[HASH_MKEYLEN];
sprintf(c_key, "%s%s%s:", c_key1, SEP, c_key2);
@@ -168,25 +168,25 @@ map_exists2(Map *p_map, char *c_key1, char *c_key2) {
char*
map_get_key(Map *p_map, void *p_val) {
if (map_empty(p_map))
- return (NULL);
+ return NULL;
for (int i = 0; i < p_map->i_max_size; ++i)
if ((unsigned) p_map->pp_vals[i] == (unsigned) p_val)
- return (p_map->pc_keys[i]);
+ return p_map->pc_keys[i];
- return (NULL);
+ return NULL;
}
int
map_get_addr(Map *p_map, char *c_key) {
if (map_empty(p_map))
- return (-1);
+ return -1;
for (int i = 0; i < p_map->i_max_size; ++i)
if (p_map->pc_keys[i] != NULL && strcmp(p_map->pc_keys[i], c_key) == 0)
- return (i);
+ return i;
- return (-1);
+ return -1;
}
void
@@ -261,27 +261,21 @@ map_iterate2(Map *p_map, void (*func) (void *, void *), void *p_void) {
}
void
-map_iterate2_keys(Map *p_map,
- void (*func) (void *, void *, char *),
- void *p_void) {
+map_iterate2_keys(Map *p_map, void (*func) (void *, void *, char *), void *p_void) {
for (int i = 0; i < p_map->i_max_size; ++i)
if (p_map->pc_keys[i] != NULL)
(*func) (p_map->pp_vals[i], p_void, p_map->pc_keys[i]);
}
void
-map_iterate3(Map *p_map,
- void (*func) (void *, void *, void *),
- void *p_void1, void *p_void2) {
+map_iterate3(Map *p_map, void (*func) (void *, void *, void *), void *p_void1, void *p_void2) {
for (int i = 0; i < p_map->i_max_size; ++i)
if (p_map->pc_keys[i] != NULL)
(*func) (p_map->pp_vals[i], p_void1, p_void2);
}
void
-map_iterate3_keys(Map *p_map,
- void (*func) (void *, void *, void *, char *),
- void *p_void1, void *p_void2) {
+map_iterate3_keys(Map *p_map, void (*func) (void *, void *, void *, char *), void *p_void1, void *p_void2) {
for (int i = 0; i < p_map->i_max_size; ++i)
if (p_map->pc_keys[i] != NULL)
(*func) (p_map->pp_vals[i], p_void1, p_void2, p_map->pc_keys[i]);