Commit d9216f73 authored by Chris Müller's avatar Chris Müller

lib: add simple map interface in structures/map.h

lib: add a ordering funptr definition and some concret comparators in structures.h
parent 77a9509f
/*
* Copyright (c) 2012 Christoph Mueller <ruunhb@googlemail.com>
*
* Crystal is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Crystal is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
*
* You should have received a copy of the Lesser GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef CRYSTAL_STRUCTURES_MAP_H
#define CRYSTAL_STRUCTURES_MAP_H
#include "structures.h"
struct CryMap;
struct CryMap* cry_map_new(cry_ordering_funptr compare);
void cry_map_free(struct CryMap* map, cry_free_funptr key_free, cry_free_funptr value_free);
size_t cry_map_size(struct CryMap* map);
pointer cry_map_lookup(struct CryMap* map, const_pointer key);
return_code cry_map_insert(struct CryMap* map, const_pointer key, pointer value);
return_code cry_map_remove(struct CryMap* map, const_pointer key, cry_free_funptr key_free, cry_free_funptr value_free);
void cry_map_dump_debug(struct CryMap* map);
#endif // CRYSTAL_STRUCTURES_MAP_H
......@@ -22,10 +22,16 @@
#include "../standard.h"
#define CRY_OUT_OF_INDEX_RANGE -1
#define CRY_ENTRY_NOT_FOUND -2
#define CRY_ENTRY_FULL -3
typedef int (*cry_ordering_funptr)(const_pointer a, const_pointer b);
typedef void (*cry_free_funptr)(pointer data);
typedef int (*cry_predicate_funptr)(pointer element, pointer context);
int cry_int_compare(const_pointer a, const_pointer b);
int cry_double_compare(const_pointer a, const_pointer b);
#endif // CRYSTAL_STRUCTURES_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment