/*****************************************************************************
 * Copyright (c) 2005  Daniel Lerch Hostalot <http://daniellerch.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a 
 * copy of this software and associated documentation files (the "Software"), 
 * to deal in the Software without restriction, including without limitation 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 * and/or sell copies of the Software, and to permit persons to whom the 
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 ****************************************************************************/


#ifndef __SET_H__
#define __SET_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "list.h"
#include <stdio.h>


/**
 * Tipo de representacion de una tabla de set.
 */
#define set_t list_t

/**
 * Crea un tipo set.  
 *
 * @return set_t*: tipo set.
 */
#define set_new list_new

/**
 * Libera la memoria utilizada por el set.
 * Si no se proporciona una funcion para liberar los elementos insertador, 
 * (NULL como argumento) no se liberaran.
 *
 * @param *obj: objeto con el que trabaja.
 * @param freefunc: funcion para liberar memoria reservada por el elemento.
 */
#define set_free list_free


/**
 * A~ade una elemento al set.
 *
 * @param *obj: objeto con el que trabaja.
 * @param *element: elemento nuevo.
 */
#define set_add list_add_last

/**
 * Borra un elemento del set.
 *
 * @param *obj: objeto con el que trabaja.
 * @param *element: elemento a borrar.
 * @return void*: apuntador al elemento borrado.
 */
void* set_remove (set_t* obj, void *element);

/**
 * Mira si existe un elemento en el set.
 *
 * @param *obj: objeto con el que trabaja.
 * @param *element: elemento.
 * @return int: 1 si existe algun elmento con clave key, 0 en caso contrario.
 */
#define set_contains list_contains

/**
 * Retorna el numero de elementos en el set.
 *
 * @param *obj: objeto con el que trabaja.
 * @return int: numero de elementos en la lista.
 */
#define set_size list_size

/**
 * Establece una funcion de comparacion personalizada.
 * 
 * @param *obj: objeto con el que trabaja.
 * @param *cmpfunc(...): funcion de comparacion que retorna 0 si param1=param2,
 *         un entero menor que 1 si param1<param2 y un entero mayor que cero 
 *         si param1>param2.
 */
#define set_set_cmpfunc list_set_cmpfunc


/**
 * Realiza la union entre dos sets.
 * Ejemplo: si set_a={A,B,C} y set_b={C,D,E}: set_u={A,B,C,D,E}
 *
 * @param set_u: set donde se guardara el resultado.
 *               Debe estar inicializado y vacio.
 * @param set_a: set con el que realizar la operacion.
 * @param set_b: set con el que realizar la operacion.
 */
void set_union (set_t *set_u, set_t* set_a, set_t* set_b); 

/**
 * Realiza la interseccion entre dos sets.
 * Ejemplo: si set_a={A,B,C} y set_b={C,D,E}: set_i={C}
 *
 * @param set_u: set donde se guardara el resultado. 
 *               Debe estar inicializado y vacio.
 * @param set_a: set con el que realizar la operacion.
 * @param set_b: set con el que realizar la operacion.
 */
void set_intersection (set_t *set_i, set_t* set_a, set_t* set_b); 

/**
 * Realiza la resta de dos sets.
 * Ejemplo: si set_a={A,B,C} y set_b={C,D,E}: set_d={A,B}
 *
 * @param set_u: set donde se guardara el resultado. 
 *               Debe estar inicializado y vacio.
 * @param set_a: set con el que realizar la operacion.
 * @param set_b: set con el que realizar la operacion.
 */
void set_difference (set_t *set_d, set_t* set_a, set_t* set_b); 





#ifdef __cplusplus
}
#endif

#endif







