Commit ee85e2c9 authored by Matthias Braun's avatar Matthias Braun
Browse files

use bool as return value in XXX_insert and ID_HASH

also flip true/false in the implementation to match the documentation in
irnodeset.h
parent 3c2c8da0
......@@ -99,21 +99,26 @@
#endif /* Alloc */
#ifdef ID_HASH
#define InsertReturnValue int
#define GetInsertReturnValue(entry,found) (found)
#define NullReturnValue 0
#define FindReturnValue bool
#define GetFindReturnValue(entry,found) (found)
#define NullReturnValue false
#define InsertReturnValue(findreturn) !(findreturn)
#else /* ! ID_HASH */
#ifdef SCALAR_RETURN
#define InsertReturnValue ValueType
#define GetInsertReturnValue(entry,found) EntryGetValue(entry)
#define NullReturnValue NullValue
#define FindReturnValue ValueType
#define GetFindReturnValue(entry,found) EntryGetValue(entry)
#define NullReturnValue NullValue
#else
#define InsertReturnValue ValueType*
#define GetInsertReturnValue(entry,found) & EntryGetValue(entry)
#define NullReturnValue & NullValue
#define FindReturnValue ValueType*
#define GetFindReturnValue(entry,found) & EntryGetValue(entry)
#define NullReturnValue & NullValue
#endif
#endif /* ID_HASH */
#ifndef InsertReturnValue
#define InsertReturnValue(findreturn) findreturn
#endif
#ifndef KeyType
#define KeyType ValueType
#define GetKey(value) (value)
......@@ -215,10 +220,11 @@ size_t hashset_size(const HashSet *self)
/**
* Inserts an element into a hashset without growing the set (you have to make
* sure there's enough room for that.
* @returns previous value if found, NullValue otherwise
* @note also see comments for hashset_insert()
* @internal
*/
static inline InsertReturnValue insert_nogrow(HashSet *self, KeyType key)
static inline FindReturnValue insert_nogrow(HashSet *self, KeyType key)
{
size_t num_probes = 0;
size_t num_buckets = self->num_buckets;
......@@ -246,7 +252,7 @@ static inline InsertReturnValue insert_nogrow(HashSet *self, KeyType key)
InitData(self, EntryGetValue(*nentry), key);
EntrySetHash(*nentry, hash);
self->num_elements++;
return GetInsertReturnValue(*nentry, 0);
return GetFindReturnValue(*nentry, false);
}
if (EntryIsDeleted(*entry)) {
if (insert_pos == ILLEGAL_POS)
......@@ -254,7 +260,7 @@ static inline InsertReturnValue insert_nogrow(HashSet *self, KeyType key)
} else if (EntryGetHash(self, *entry) == hash) {
if (KeysEqual(self, GetKey(EntryGetValue(*entry)), key)) {
// Value already in the set, return it
return GetInsertReturnValue(*entry, 1);
return GetFindReturnValue(*entry, true);
}
}
......@@ -416,7 +422,7 @@ static inline void maybe_shrink(HashSet *self)
* @param key the key that identifies the data
* @returns the existing or newly created data element (or nothing in case of hashs where keys are the while value)
*/
InsertReturnValue hashset_insert(HashSet *self, KeyType key)
FindReturnValue hashset_insert(HashSet *self, KeyType key)
{
#ifndef NDEBUG
self->entries_version++;
......@@ -424,7 +430,7 @@ InsertReturnValue hashset_insert(HashSet *self, KeyType key)
maybe_shrink(self);
maybe_grow(self);
return insert_nogrow(self, key);
return InsertReturnValue(insert_nogrow(self, key));
}
/**
......@@ -434,7 +440,7 @@ InsertReturnValue hashset_insert(HashSet *self, KeyType key)
* @param key the key to search for
* @returns the found value or NullValue if nothing was found
*/
InsertReturnValue hashset_find(const HashSet *self, ConstKeyType key)
FindReturnValue hashset_find(const HashSet *self, ConstKeyType key)
{
size_t num_probes = 0;
size_t num_buckets = self->num_buckets;
......@@ -453,7 +459,7 @@ InsertReturnValue hashset_find(const HashSet *self, ConstKeyType key)
} else if (EntryGetHash(self, *entry) == hash) {
if (KeysEqual(self, GetKey(EntryGetValue(*entry)), key)) {
// found the value
return GetInsertReturnValue(*entry, 1);
return GetFindReturnValue(*entry, true);
}
}
......
......@@ -28,6 +28,7 @@
/** probing method: quadratic probing */
#define DO_REHASH
#define ID_HASH
#define HashSet pset_new_t
#define HashSetIterator pset_new_iterator_t
#define ValueType void*
......
......@@ -31,6 +31,8 @@
#ifndef FIRM_ADT_PSET_NEW_H
#define FIRM_ADT_PSET_NEW_H
#include <stdbool.h>
/** @cond PRIVATE */
#define HashSet pset_new_t
......@@ -79,9 +81,9 @@ void pset_new_destroy(pset_new_t *pset_new);
*
* @param pset_new Pointer to the pset_new
* @param ptr Pointer to insert into the pset_new
* @returns 1 if the pointer was inserted, 0 if it was already there
* @returns true if the pointer was inserted, false if it was already there
*/
int pset_new_insert(pset_new_t *pset_new, void *ptr);
bool pset_new_insert(pset_new_t *pset_new, void *ptr);
/**
* Removes an element from a pset_new. Does nothing if the pset_new doesn't contain the
......@@ -97,9 +99,8 @@ void pset_new_remove(pset_new_t *pset_new, const void *ptr);
*
* @param pset_new Pointer to the pset_new
* @param ptr The pointer to test
* @returns 1 @p pset_new contains the @p ptr, 0 otherwise
*/
int pset_new_contains(const pset_new_t *pset_new, const void *ptr);
bool pset_new_contains(const pset_new_t *pset_new, const void *ptr);
/**
* Returns the number of pointers contained in the pset_new
......
......@@ -810,7 +810,7 @@ static void emit_subroutine_type(const ir_type *type)
static void emit_type(ir_type *type)
{
if (pset_new_insert(&env.emitted_types, type))
if (!pset_new_insert(&env.emitted_types, type))
return;
switch (get_type_tpop_code(type)) {
......
......@@ -29,6 +29,7 @@
#ifndef _FIRM_IRNODESET_H_
#define _FIRM_IRNODESET_H_
#include <stdbool.h>
#include "firm_types.h"
#include "xmalloc.h"
......@@ -95,10 +96,10 @@ static inline void ir_nodeset_del(ir_nodeset_t *nodeset) {
*
* @param nodeset Pointer to the nodeset
* @param node node to insert into the nodeset
* @returns 1 if the element has been inserted,
* 0 if it was already there
* @returns true if the element has been inserted,
* false if it was already there
*/
int ir_nodeset_insert(ir_nodeset_t *nodeset, ir_node *node);
bool ir_nodeset_insert(ir_nodeset_t *nodeset, ir_node *node);
/**
......@@ -115,9 +116,8 @@ void ir_nodeset_remove(ir_nodeset_t *nodeset, const ir_node *node);
*
* @param nodeset Pointer to the nodeset
* @param node The pointer to find
* @returns 1 if nodeset contains the node, 0 else
*/
int ir_nodeset_contains(const ir_nodeset_t *nodeset, const ir_node *node);
bool ir_nodeset_contains(const ir_nodeset_t *nodeset, const ir_node *node);
/**
* Returns the number of pointers contained in the nodeset
......
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