Commons Library  1.7.0
dictionary.h
Ir a la documentación de este archivo.
1 /*
2  * Copyright (C) 2012 Sistemas Operativos - UTN FRBA. All rights reserved.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef DICTIONARY_H_
18 #define DICTIONARY_H_
19 
20  #define DEFAULT_DICTIONARY_INITIAL_SIZE 20
21 
22  #include "node.h"
23  #include <stdbool.h>
24  #include "list.h"
25 
36  typedef struct {
37  t_hash_element **elements;
41  } t_dictionary;
42 
52 
63  void dictionary_put(t_dictionary *, char *key, void *element);
64 
70  void *dictionary_get(t_dictionary *, char *key);
71 
78  void *dictionary_remove(t_dictionary *, char *key);
79 
84  void dictionary_remove_and_destroy(t_dictionary *, char *, void(*element_destroyer)(void*));
85 
89  void dictionary_iterator(t_dictionary *, void(*closure)(char* key, void* element));
90 
96 
101  void dictionary_clean_and_destroy_elements(t_dictionary *, void(*element_destroyer)(void*));
102 
106  bool dictionary_has_key(t_dictionary *, char* key);
107 
112 
117 
122 
127 
132 
137  void dictionary_destroy_and_destroy_elements(t_dictionary *, void(*element_destroyer)(void*));
138 
139 #endif /* DICTIONARY_H_ */
void dictionary_destroy_and_destroy_elements(t_dictionary *, void(*element_destroyer)(void *))
Destruye el diccionario y destruye sus elementos.
void dictionary_clean_and_destroy_elements(t_dictionary *, void(*element_destroyer)(void *))
Quita todos los elementos del diccionario y los destruye, dejando el diccionario vacío.
void dictionary_iterator(t_dictionary *, void(*closure)(char *key, void *element))
Aplica closure a todos los elementos del diccionario.
void dictionary_destroy(t_dictionary *)
Destruye el diccionario.
void * dictionary_get(t_dictionary *, char *key)
Obtiene el elemento asociado a la key.
bool dictionary_is_empty(t_dictionary *)
Retorna true si el diccionario está vacío.
int dictionary_size(t_dictionary *)
Retorna la cantidad de elementos del diccionario.
t_list * dictionary_keys(t_dictionary *self)
Retorna todas las keys en una lista.
void dictionary_remove_and_destroy(t_dictionary *, char *, void(*element_destroyer)(void *))
Remueve un elemento del diccionario y lo destruye llamando a la función element_destroyer pasada por ...
void dictionary_put(t_dictionary *, char *key, void *element)
Inserta un nuevo par (key->element) al diccionario, en caso de ya existir la key actualiza el element...
void * dictionary_remove(t_dictionary *, char *key)
Remueve un elemento del diccionario y lo retorna.
t_list * dictionary_elements(t_dictionary *self)
Retorna todos los elementos en una lista.
bool dictionary_has_key(t_dictionary *, char *key)
Retorna true si key se encuentra en el diccionario.
t_dictionary * dictionary_create(void)
Crea el diccionario.
void dictionary_clean(t_dictionary *)
Quita todos los elementos del diccionario sin liberarlos, dejando el diccionario vacío.
#include <commons/collections/list.h>
Estructura de un diccionario que contiene pares string->puntero. Inicializar con dictionary_create().
Definition: dictionary.h:36
t_hash_element ** elements
Definition: dictionary.h:37
int elements_amount
Definition: dictionary.h:40
int table_current_size
Definition: dictionary.h:39
int table_max_size
Definition: dictionary.h:38
Estructura de una lista enlazada. Inicializar con list_create()
Definition: list.h:32