add *_list_get_ctx
[platform/upstream/isl.git] / isl_name.c
index 2ef6cbe..a9a6382 100644 (file)
@@ -1,4 +1,14 @@
+/*
+ * Copyright 2008-2009 Katholieke Universiteit Leuven
+ *
+ * Use of this software is governed by the GNU LGPLv2.1 license
+ *
+ * Written by Sven Verdoolaege, K.U.Leuven, Departement
+ * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
+ */
+
 #include <string.h>
+#include <isl_ctx_private.h>
 #include "isl_name.h"
 
 struct isl_name *isl_name_alloc(struct isl_ctx *ctx, const char *s)
@@ -10,12 +20,18 @@ struct isl_name *isl_name_alloc(struct isl_ctx *ctx, const char *s)
                return NULL;
        name = isl_alloc_type(ctx, struct isl_name);
        if (!name)
-               return NULL;
+               goto error;
 
        name->ref = 1;
        name->name = copy;
 
+       name->hash = isl_hash_init();
+       name->hash = isl_hash_string(name->hash, s);
+
        return name;
+error:
+       free((char *)copy);
+       return NULL;
 }
 
 static int isl_name_has_name(const void *entry, const void *val)
@@ -58,6 +74,14 @@ static int isl_name_eq(const void *entry, const void *name)
        return entry == name;
 }
 
+uint32_t isl_hash_name(uint32_t hash, struct isl_name *name)
+{
+       if (name)
+               isl_hash_hash(hash, name->hash);
+
+       return hash;
+}
+
 void isl_name_free(struct isl_ctx *ctx, struct isl_name *name)
 {
        uint32_t name_hash;