Changeset: 3d22f6b30aee for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3d22f6b30aee
Added Files:
        monetdb5/extras/rdf/50_rdf.mal
        monetdb5/extras/rdf/hashmap/Makefile.ag
        monetdb5/extras/rdf/hashmap/hashmap.c
        monetdb5/extras/rdf/hashmap/hashmap.h
        monetdb5/extras/rdf/rdfschema.c
        monetdb5/extras/rdf/rdfschema.mal
Removed Files:
        monetdb5/extras/rdf/30_rdf.mal
Modified Files:
        monetdb5/extras/rdf/Makefile.ag
        sql/backends/monet5/Makefile.ag
Branch: rdf
Log Message:

Add rdfschema for extracting schema from RDF triples and modify make file.

- Change 30_rdf.mal to 50_rdf.mal so that it will be loaded after sql.
- Add hashmap for handling hashmap of CSs (characteristic sets)


diffs (truncated from 649 to 300 lines):

diff --git a/monetdb5/extras/rdf/30_rdf.mal b/monetdb5/extras/rdf/50_rdf.mal
rename from monetdb5/extras/rdf/30_rdf.mal
rename to monetdb5/extras/rdf/50_rdf.mal
--- a/monetdb5/extras/rdf/30_rdf.mal
+++ b/monetdb5/extras/rdf/50_rdf.mal
@@ -16,7 +16,7 @@
 # All Rights Reserved.
 
 # This loads the MonetDB/RDF module
-library rdf;
+#library rdf;
 
 include tokenizer;
 include rdfalgebra;
diff --git a/monetdb5/extras/rdf/Makefile.ag b/monetdb5/extras/rdf/Makefile.ag
--- a/monetdb5/extras/rdf/Makefile.ag
+++ b/monetdb5/extras/rdf/Makefile.ag
@@ -28,14 +28,15 @@ MTSAFE
 SUBDIRS = hashmap
 
 lib__rdf = {
-       MODULE
-       DIR = libdir/monetdb5
+       #MODULE
+       NOINST
+       #DIR = libdir/monetdb5
        SOURCES = rdf.h rdf_shredder.mx rdfalgebra.c rdfschema.c 
        #SEP = _
-       LIBS =  ./hashmap/librdfhash
-               ../../tools/libmonetdb5 \
-                  ../../../gdk/libbat \
-                  $(MALLOC_LIBS) $(raptor_LIBS)
+       # LIBS =  ./hashmap/librdfhash  
+       #       ../../tools/libmonetdb5 \
+       #          ../../../gdk/libbat \
+       #          $(MALLOC_LIBS) $(raptor_LIBS)
 }
 
 headers_rdf_mal = {
@@ -47,8 +48,8 @@ headers_rdf_mal = {
 headers_autoload = {
        HEADERS = mal
        DIR = libdir/monetdb5/autoload
-       SOURCES = 30_rdf.mal
+       SOURCES = 50_rdf.mal
 }
 
 EXTRA_DIST_DIR = hashmap
-EXTRA_DIST = 30_rdf.mal rdfalgebra.mal rdfschema.mal
+EXTRA_DIST = 50_rdf.mal rdfalgebra.mal rdfschema.mal
diff --git a/monetdb5/extras/rdf/hashmap/Makefile.ag 
b/monetdb5/extras/rdf/hashmap/Makefile.ag
new file mode 100644
--- /dev/null
+++ b/monetdb5/extras/rdf/hashmap/Makefile.ag
@@ -0,0 +1,36 @@
+# The contents of this file are subject to the MonetDB Public License
+# Version 1.1 (the "License"); you may not use this file except in
+# compliance with the License. You may obtain a copy of the License at
+# http://www.monetdb.org/Legal/MonetDBLicense
+#
+# Software distributed under the License is distributed on an "AS IS"
+# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+# License for the specific language governing rights and limitations
+# under the License.
+#
+# The Original Code is the MonetDB Database System.
+#
+# The Initial Developer of the Original Code is CWI.
+# Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+# Copyright August 2008-2012 MonetDB B.V.
+# All Rights Reserved.
+
+INCLUDES = ../../../modules/atoms ../../../modules/mal ../../../mal \
+                  ../../../modules/kernel \
+                  ../../../../clients/mapilib \
+                  ../../../../common/options \
+                  ../../../../common/stream \
+                  ../../../../gdk \
+                  $(raptor_CFLAGS)
+
+MTSAFE
+
+lib_rdfhash = {
+       #DIR = libdir/monetdb5
+       NOINST
+       SOURCES = hashmap.h hashmap.c                   
+       #SEP = _
+}
+
+#EXTRA_DIST_DIR = Tests
+#EXTRA_DIST
diff --git a/monetdb5/extras/rdf/hashmap/hashmap.c 
b/monetdb5/extras/rdf/hashmap/hashmap.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/extras/rdf/hashmap/hashmap.c
@@ -0,0 +1,299 @@
+/*
+ * Generic map implementation.
+ */
+#include <hashmap.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define INITIAL_SIZE (256)
+#define MAX_CHAIN_LENGTH (8)
+
+/* We need to keep keys and values */
+typedef struct _hashmap_element{
+       int* key;
+       int num;        
+       int in_use;
+       any_t data;
+} hashmap_element;
+
+/* A hashmap has some maximum size and current size,
+ * as well as the data to hold. */
+typedef struct _hashmap_map{
+       int table_size;
+       int size;
+       hashmap_element *data;
+} hashmap_map;
+
+/*
+ * Return an empty hashmap, or NULL on failure.
+ */
+map_t hashmap_new(void) {
+       hashmap_map* m = (hashmap_map*) malloc(sizeof(hashmap_map));
+       if(!m) goto err;
+
+       m->data = (hashmap_element*) calloc(INITIAL_SIZE, 
sizeof(hashmap_element));
+       if(!m->data) goto err;
+
+       m->table_size = INITIAL_SIZE;
+       m->size = 0;
+
+       return m;
+       err:
+               if (m)
+                       hashmap_free(m);
+               return NULL;
+}
+
+/*
+ * Hashing function for a set of values
+ * Rely on djb2 http://www.cse.yorku.ca/~oz/hash.html
+ *
+ */
+static unsigned int hashmap_hash_int(hashmap_map * m, int* key, int num){
+       unsigned int hashCode = 5381u; 
+       int i; 
+
+       for (i = 0; i < num; i++){
+               hashCode = ((hashCode << 5) + hashCode) + key[i];
+       }
+       
+       // return 0x7fffffff & hashCode 
+       return hashCode % m->table_size;
+}
+
+/* Compare two list of integers 
+ * Return 0 if they are same
+ * Return 1 if they are different
+ * */
+static char intsetcmp(int* key1, int* key2, int num){
+       int i; 
+        
+       for (i = 0; i < num; i++){
+               if (key1[i] != key2[i]) return 1;       
+       }
+       return 0; 
+}
+
+/*
+ * Return the integer of the location in data
+ * to store the point to the item, or MAP_FULL.
+ */
+static int hashmap_hash(map_t in, int* key, int num){
+       int curr;
+       int i;
+
+       /* Cast the hashmap */
+       hashmap_map* m = (hashmap_map *) in;
+
+       /* If full, return immediately */
+       if(m->size >= (m->table_size/2)) return MAP_FULL;
+
+       /* Find the best index */
+       curr = hashmap_hash_int(m, key, num);
+
+       /* Linear probing */
+       for(i = 0; i< MAX_CHAIN_LENGTH; i++){
+               if(m->data[curr].in_use == 0)
+                       return curr;
+
+               if(m->data[curr].in_use == 1 && (m->data[curr].num == num) && 
(intsetcmp (m->data[curr].key,key, num)==0))
+                       return curr;
+
+               curr = (curr + 1) % m->table_size;
+       }
+
+       return MAP_FULL;
+}
+
+/*
+ * Doubles the size of the hashmap, and rehashes all the elements
+ */
+static int hashmap_rehash(map_t in){
+       int i;
+       int old_size;
+       hashmap_element* curr;
+
+       /* Setup the new elements */
+       hashmap_map *m = (hashmap_map *) in;
+       hashmap_element* temp = (hashmap_element *)
+               calloc(2 * m->table_size, sizeof(hashmap_element));
+       if(!temp) return MAP_OMEM;
+
+       /* Update the array */
+       curr = m->data;
+       m->data = temp;
+
+       /* Update the size */
+       old_size = m->table_size;
+       m->table_size = 2 * m->table_size;
+       m->size = 0;
+
+       /* Rehash the elements */
+       for(i = 0; i < old_size; i++){
+               int status;
+
+               if (curr[i].in_use == 0)
+                       continue;
+            
+               status = hashmap_put(m, curr[i].key, curr[i].num, curr[i].data);
+               if (status != MAP_OK)
+                       return status;
+       }
+
+       free(curr);
+
+       return MAP_OK;
+}
+
+/*
+ * Add a pointer to the hashmap with some key
+ */
+int hashmap_put(map_t in, int* key, int num,  any_t value){
+       int index;
+       hashmap_map* m;
+
+       /* Cast the hashmap */
+       m = (hashmap_map *) in;
+
+       /* Find a place to put our value */
+       index = hashmap_hash(in, key, num);
+       while(index == MAP_FULL){
+               if (hashmap_rehash(in) == MAP_OMEM) {
+                       return MAP_OMEM;
+               }
+               index = hashmap_hash(in, key, num);
+       }
+
+       /* Set the data */
+       m->data[index].data = value;
+       m->data[index].key = key;
+       m->data[index].num = num; 
+       m->data[index].in_use = 1;
+       m->size++; 
+
+       return MAP_OK;
+}
+
+/*
+ * Get your pointer out of the hashmap with a key
+ */
+int hashmap_get(map_t in, int* key, int num,  any_t *arg){
+       int curr;
+       int i;
+       hashmap_map* m;
+
+       /* Cast the hashmap */
+       m = (hashmap_map *) in;
+
+       /* Find data location */
+       curr = hashmap_hash_int(m, key, num);
+
+       /* Linear probing, if necessary */
+       for(i = 0; i<MAX_CHAIN_LENGTH; i++){
+
+        int in_use = m->data[curr].in_use;
+        if (in_use == 1){
+            if ((m->data[curr].num == num) && 
(intsetcmp(m->data[curr].key,key,num)==0)){
+                *arg = (m->data[curr].data);
+                return MAP_OK;
+            }
+               }
+
+               curr = (curr + 1) % m->table_size;
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to