X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firnodeset.h;h=330caa620ae3762bb2cbb6a834763e34e1f6b7a7;hb=af0115376ccdcc72e0643caf221407218f4504f0;hp=e20e99d4f6610b9e1d239805bb50a659dc34e305;hpb=3eced231d086db25ba65f7265950915671fe6467;p=libfirm diff --git a/ir/ir/irnodeset.h b/ir/ir/irnodeset.h index e20e99d4f..330caa620 100644 --- a/ir/ir/irnodeset.h +++ b/ir/ir/irnodeset.h @@ -1,3 +1,22 @@ +/* + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * + * This file is part of libFirm. + * + * This file may be distributed and/or modified under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation and appearing in the file LICENSE.GPL included in the + * packaging of this file. + * + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + /** * @file * @author Matthias Braun @@ -5,24 +24,42 @@ * @brief A nodeset. This should be prefered over a simple pset, because it * tries to guarantee deterministic behavior. (and is faster) * @version $Id$ + * @note Actually the bits to make the behaviour deterministic are not + * implemented yet... */ #ifndef _FIRM_IRNODESET_H_ #define _FIRM_IRNODESET_H_ -#include "irnode.h" +#include "firm_types.h" +#include "xmalloc.h" + +/* + * sebastian experimental: + * use ordered arrays as node sets. + * the guys here have made good experiences with that. + * Internally we use normal Firm arrays and binary + * search for locating the elements. Using arrays should + * give the sets a small footprint. + */ +#undef IR_NODESET_USE_ORDERED_SETS #define HashSet ir_nodeset_t #define HashSetIterator ir_nodeset_iterator_t #define ValueType ir_node* #define DO_REHASH + #include "hashset.h" + #undef DO_REHASH #undef ValueType #undef HashSetIterator #undef HashSet +typedef struct ir_nodeset_t ir_nodeset_t; +typedef struct ir_nodeset_iterator_t ir_nodeset_iterator_t; + /** - * Initializes a nodeset + * Initializes a nodeset with default size. * * @param nodeset Pointer to allocated space for the nodeset */ @@ -32,7 +69,7 @@ void ir_nodeset_init(ir_nodeset_t *nodeset); * Initializes a nodeset * * @param nodeset Pointer to allocated space for the nodeset - * @param expected_elements Number of elements expected in the nodeset (rougly) + * @param expected_elements Number of elements expected in the nodeset (roughly) */ void ir_nodeset_init_size(ir_nodeset_t *nodeset, size_t expected_elements); @@ -44,6 +81,26 @@ void ir_nodeset_init_size(ir_nodeset_t *nodeset, size_t expected_elements); */ void ir_nodeset_destroy(ir_nodeset_t *nodeset); +/** + * Allocates memory for a nodeset and initializes the set. + * + * @param expected_elements Number of elements expected in the nodeset (roughly) + * @return The initialized nodeset + */ +static inline ir_nodeset_t *ir_nodeset_new(size_t expected_elements) { + ir_nodeset_t *res = XMALLOC(ir_nodeset_t); + ir_nodeset_init_size(res, expected_elements); + return res; +} + +/** + * Destroys a nodeset and frees the memory of the nodeset itself. + */ +static inline void ir_nodeset_del(ir_nodeset_t *nodeset) { + ir_nodeset_destroy(nodeset); + xfree(nodeset); +} + /** * Inserts a node into a nodeset. * @@ -54,6 +111,7 @@ void ir_nodeset_destroy(ir_nodeset_t *nodeset); */ int ir_nodeset_insert(ir_nodeset_t *nodeset, ir_node *node); + /** * Removes a node from a nodeset. Does nothing if the nodeset doesn't contain * the node.