You are viewing a plain text version of this content. The canonical link for it is here.
Posted to triplesoup-commits@incubator.apache.org by le...@apache.org on 2007/02/21 21:56:45 UTC
svn commit: r510255 [1/3] - in
/incubator/triplesoup/donations/TRIPLES-2-libb: ./ redland-integration/
src/ tests/ utils/
Author: leosimons
Date: Wed Feb 21 13:56:43 2007
New Revision: 510255
URL: http://svn.apache.org/viewvc?view=rev&rev=510255
Log:
Initial import of libb-52393 as attached to jira issue TRIPLES-2 and provided
by Joost at
http://opensource.joost.com/libb/libb-52393.tar.gz
Added:
incubator/triplesoup/donations/TRIPLES-2-libb/Makefile.in
incubator/triplesoup/donations/TRIPLES-2-libb/export.sh (with props)
incubator/triplesoup/donations/TRIPLES-2-libb/redland-integration/
incubator/triplesoup/donations/TRIPLES-2-libb/redland-integration/README.txt
incubator/triplesoup/donations/TRIPLES-2-libb/redland-integration/rdf_storage_b.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/
incubator/triplesoup/donations/TRIPLES-2-libb/src/Makefile.in
incubator/triplesoup/donations/TRIPLES-2-libb/src/b.h
incubator/triplesoup/donations/TRIPLES-2-libb/src/b_internal.h
incubator/triplesoup/donations/TRIPLES-2-libb/src/badd.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/bcache.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/bcount.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/bdestroy.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/berror.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/bget.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/bhash.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/bio.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/biterator.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/bmd5.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/bnew.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/bremove.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/bstring.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/bsync.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/btcache.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/btempty.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/btimer.c
incubator/triplesoup/donations/TRIPLES-2-libb/src/btriple.c
incubator/triplesoup/donations/TRIPLES-2-libb/tests/
incubator/triplesoup/donations/TRIPLES-2-libb/tests/Makefile.in
incubator/triplesoup/donations/TRIPLES-2-libb/tests/test1.c
incubator/triplesoup/donations/TRIPLES-2-libb/tests/test2.c
incubator/triplesoup/donations/TRIPLES-2-libb/tests/test3.c
incubator/triplesoup/donations/TRIPLES-2-libb/tests/test4.c
incubator/triplesoup/donations/TRIPLES-2-libb/tests/test5.c
incubator/triplesoup/donations/TRIPLES-2-libb/tests/test6.c
incubator/triplesoup/donations/TRIPLES-2-libb/tests/test7.c
incubator/triplesoup/donations/TRIPLES-2-libb/utils/
incubator/triplesoup/donations/TRIPLES-2-libb/utils/Makefile.in
incubator/triplesoup/donations/TRIPLES-2-libb/utils/bproc.c
Added: incubator/triplesoup/donations/TRIPLES-2-libb/Makefile.in
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/Makefile.in?view=auto&rev=510255
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-2-libb/Makefile.in (added)
+++ incubator/triplesoup/donations/TRIPLES-2-libb/Makefile.in Wed Feb 21 13:56:43 2007
@@ -0,0 +1,21 @@
+# (c) 2006 Satis Superque Merce B.V. All rights reserved. This code
+# contains trade secrets of Satis Superque Merce B.V. and any
+# unauthorized use or disclosure is strictly prohibited.
+#
+# $Id: Makefile.in 29834 2006-10-19 16:22:05Z Andrea Marchesini <ba...@theveniceproject.com> $
+#
+
+DEPTH = ../../..
+topsrcdir = @top_srcdir@
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+include $(DEPTH)/config/autoconf.mk
+
+DIRS = src utils
+
+ifdef ENABLE_TESTS
+DIRS += tests
+endif
+
+include $(topsrcdir)/config/rules.mk
Added: incubator/triplesoup/donations/TRIPLES-2-libb/export.sh
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/export.sh?view=auto&rev=510255
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-2-libb/export.sh (added)
+++ incubator/triplesoup/donations/TRIPLES-2-libb/export.sh Wed Feb 21 13:56:43 2007
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# Simple script to create a B tarball
+
+revision=`svn export https://svn.theveniceproject.com/repos/venice/code/client/trunk/mozilla/tvp/tvprdf/b b-export | grep 'Exported revision' | sed 's/Exported revision //' | sed 's/\.//'`
+mv b-export libb-$revision
+mkdir libb-$revision/redland-integration
+svn cat https://svn.theveniceproject.com/repos/venice/code/client/trunk/mozilla/tvp/tvprdf/redland/librdf/rdf_storage_b.c > libb-$revision/redland-integration/rdf_storage_b.c
+cat > libb-$revision/redland-integration/README.txt <<END
+B store can be used as a backend for redland (http://librdf.org/).
+
+The file rdf_storage_b.c contains most of the code needed for this;
+in addition, there's some changes to make to the build system, for
+which a patch will be forthcoming.
+
+END
+tar czf libb-$revision.tar.gz libb-$revision
+rm -Rf libb-$revision
+echo libb-$revision.tar.gz
\ No newline at end of file
Propchange: incubator/triplesoup/donations/TRIPLES-2-libb/export.sh
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/triplesoup/donations/TRIPLES-2-libb/redland-integration/README.txt
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/redland-integration/README.txt?view=auto&rev=510255
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-2-libb/redland-integration/README.txt (added)
+++ incubator/triplesoup/donations/TRIPLES-2-libb/redland-integration/README.txt Wed Feb 21 13:56:43 2007
@@ -0,0 +1,6 @@
+B store can be used as a backend for redland (http://librdf.org/).
+
+The file rdf_storage_b.c contains most of the code needed for this;
+in addition, there's some changes to make to the build system, for
+which a patch will be forthcoming.
+
Added: incubator/triplesoup/donations/TRIPLES-2-libb/redland-integration/rdf_storage_b.c
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/redland-integration/rdf_storage_b.c?view=auto&rev=510255
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-2-libb/redland-integration/rdf_storage_b.c (added)
+++ incubator/triplesoup/donations/TRIPLES-2-libb/redland-integration/rdf_storage_b.c Wed Feb 21 13:56:43 2007
@@ -0,0 +1,816 @@
+/* -*- Mode: c; c-basic-offset: 2 -*-
+ *
+ * (c) 2007 Satis Superque Merce B.V. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * rdf_storage_b.c - RDF Storage using B implementation
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <rdf_config.h>
+#endif
+
+#ifdef WIN32
+#include <win32_rdf_config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h> /* for abort() as used in errors */
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <sys/types.h>
+
+#include <redland.h>
+#include <rdf_storage.h>
+#include <rdf_digest.h>
+#include <rdf_types.h>
+
+#include <b.h>
+
+typedef struct
+{
+ librdf_storage *storage;
+
+ b_t *db;
+ int db_cache;
+
+ unsigned char *path;
+
+} librdf_storage_b_context;
+
+typedef struct {
+ librdf_storage *storage;
+ librdf_storage_b_context* b_context;
+
+ int finished;
+
+ librdf_statement *statement;
+ librdf_node* context;
+
+ b_iterator_triple_t *iterator;
+} librdf_storage_b_stream_context;
+
+typedef struct {
+ librdf_storage *storage;
+ librdf_storage_b_context* b_context;
+
+ int finished;
+ b_iterator_type_t *iterator;
+ unsigned char *what;
+} librdf_storage_b_iterator_context;
+
+static b_triple_t * librdf_storage_b_triple(librdf_storage* storage,
+ librdf_node *subject_node,
+ librdf_node *property_node,
+ librdf_node *object_node,
+ librdf_node *context_node);
+static void librdf_storage_b_triple_free(unsigned char **values);
+
+static int librdf_storage_b_stream_end_of_stream(void* context);
+static int librdf_storage_b_stream_next_statement(void* context);
+static void librdf_storage_b_stream_finished(void* context);
+static void* librdf_storage_b_stream_get_statement(void* context, int flags);
+
+static int librdf_storage_b_iterator_is_end(void* iterator);
+static int librdf_storage_b_iterator_next_method(void* iterator);
+static void* librdf_storage_b_iterator_get_method(void* iterator, int);
+static void librdf_storage_b_iterator_finished(void* iterator);
+
+static int
+librdf_storage_b_init(librdf_storage* storage, char *name, librdf_hash* options)
+{
+ librdf_storage_b_context *context=(librdf_storage_b_context*)storage->context;
+ unsigned char *path;
+ int len;
+
+ if(!name)
+ return 1;
+
+ context->storage = storage;
+
+ if(options && (context->db_cache=(int)librdf_hash_get_as_long(options, "cache"))<0)
+ context->db_cache=0;
+
+ len=strlen(name);
+
+ if(!(path=(unsigned char*)LIBRDF_MALLOC(cstring, len+1)))
+ return 1;
+
+ strncpy((char *)path, name, len+1);
+ context->path=path;
+
+ if(options)
+ librdf_free_hash(options);
+
+ return 0;
+}
+
+static void
+librdf_storage_b_terminate(librdf_storage* storage)
+{
+ librdf_storage_b_context *context=(librdf_storage_b_context*)storage->context;
+
+ if(context->path)
+ LIBRDF_FREE(cstring, context->path);
+}
+
+static int
+librdf_storage_b_open(librdf_storage* storage, librdf_model* model)
+{
+ librdf_storage_b_context *context=(librdf_storage_b_context*)storage->context;
+ b_error_t error;
+
+ if((error=b_new(&context->db, context->path))!=B_OK) {
+ librdf_log(storage->world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_STORAGE, NULL,
+ "B database %s open failed - %s", context->path,
+ b_strerror(error));
+ return 1;
+ }
+
+ if(context->db_cache)
+ b_set_max_cache(context->db, context->db_cache);
+
+ return 0;
+}
+
+static int
+librdf_storage_b_close(librdf_storage* storage)
+{
+ librdf_storage_b_context* context=(librdf_storage_b_context*)storage->context;
+ b_error_t error;
+
+ if(context->db) {
+ if((error=b_destroy(context->db))!=B_OK) {
+ librdf_log(storage->world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_STORAGE,
+ NULL, "B database %s close failed - %s", context->path,
+ b_strerror(error));
+ }
+ context->db=NULL;
+ }
+
+ return 0;
+}
+
+static int
+librdf_storage_b_size(librdf_storage* storage)
+{
+ librdf_storage_b_context* context=(librdf_storage_b_context*)storage->context;
+ b_uint64 count=0;
+ b_error_t error;
+
+ if((error=b_count_triple(context->db, &count))!=B_OK) {
+ librdf_log(storage->world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_STORAGE,
+ NULL, "B database %s get size failed - %s", context->path,
+ b_strerror(error));
+ }
+
+ return (int)count;
+}
+
+static int
+librdf_storage_b_context_add_statement(librdf_storage* storage,
+ librdf_node* context_node,
+ librdf_statement* statement)
+{
+ librdf_storage_b_context* context=(librdf_storage_b_context*)storage->context;
+ b_triple_t *triple;
+ b_error_t error;
+
+ if(!(triple= librdf_storage_b_triple(storage,
+ librdf_statement_get_subject(statement),
+ librdf_statement_get_predicate(statement),
+ librdf_statement_get_object(statement),
+ context_node)))
+ return 1;
+
+ if((error=b_add_triple(context->db, triple))!=B_OK) {
+ librdf_log(storage->world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_STORAGE,
+ NULL, "B database %s add triple failed - %s", context->path,
+ b_strerror(error));
+
+ b_triple_destroy(triple);
+ return 1;
+ }
+
+ b_triple_destroy(triple);
+ return 0;
+}
+
+static int
+librdf_storage_b_add_statement(librdf_storage* storage,
+ librdf_statement* statement)
+{
+ return librdf_storage_b_context_add_statement(storage, NULL, statement);
+}
+
+static unsigned char **
+librdf_storage_b_triple_array(librdf_storage *storage,
+ librdf_node *subject_node,
+ librdf_node *property_node,
+ librdf_node *object_node,
+ librdf_node *context_node,
+ unsigned int *values_len)
+{
+ librdf_storage_b_context* context=(librdf_storage_b_context*)storage->context;
+ unsigned char **values;
+ librdf_uri *uri;
+
+ if(!(values=calloc(9, sizeof(unsigned char *))))
+ return NULL;
+
+ memset(values_len, 0, sizeof(unsigned int)*9);
+
+#define B_FIND_NODE( x , a , b , c , d , e) \
+ if(x) { \
+ switch(librdf_node_get_type(x)) { \
+ case LIBRDF_NODE_TYPE_RESOURCE: \
+ values[a]=librdf_uri_as_counted_string(librdf_node_get_uri(x), \
+ &values_len[a]); \
+ break; \
+ \
+ case LIBRDF_NODE_TYPE_BLANK: \
+ values[b]=librdf_node_get_blank_identifier(x); \
+ break; \
+ \
+ case LIBRDF_NODE_TYPE_LITERAL: \
+ values[c]=librdf_node_get_literal_value_as_counted_string(x, \
+ &values_len[c]); \
+ if ((uri=librdf_node_get_literal_value_datatype_uri(x))) \
+ values[d]=(unsigned char *)librdf_uri_as_counted_string(uri, \
+ &values_len[d]); \
+ values[e]=(unsigned char *)librdf_node_get_literal_value_language(x); \
+ break; \
+ \
+ case LIBRDF_NODE_TYPE_UNKNOWN: \
+ break; \
+ \
+ } \
+ }
+
+ B_FIND_NODE(subject_node, 0, 1, 1, 1, 1);
+ B_FIND_NODE(property_node, 2, 2, 2, 2, 2);
+ B_FIND_NODE(object_node, 3, 4, 5, 7, 8);
+ B_FIND_NODE(context_node, 6, 6, 6, 6, 6);
+
+ return values;
+}
+
+static b_triple_t *
+librdf_storage_b_triple(librdf_storage *storage,
+ librdf_node *subject_node, librdf_node *property_node,
+ librdf_node *object_node, librdf_node *context_node)
+{
+ librdf_storage_b_context* context=(librdf_storage_b_context*)storage->context;
+ unsigned char **values;
+ unsigned int values_len[9];
+ b_triple_t *triple;
+ b_error_t error;
+
+ if(!(values = librdf_storage_b_triple_array(storage, subject_node,
+ property_node,object_node,
+ context_node, values_len)))
+ return NULL;
+
+ if((error=b_triple_new_incomplete(&triple, values[0], values_len[0],
+ values[1], values_len[1],
+ values[2], values_len[2],
+ values[3], values_len[3],
+ values[4], values_len[4],
+ values[5], values_len[5],
+ values[6], values_len[6],
+ values[7], values_len[7],
+ values[8], values_len[8]))!=B_OK) {
+ librdf_log(storage->world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_STORAGE,
+ NULL, "B database %s create triple failed - %s", context->path,
+ b_strerror(error));
+ librdf_storage_b_triple_free(values);
+ return NULL;
+ }
+
+ librdf_storage_b_triple_free(values);
+ return triple;
+}
+
+static void librdf_storage_b_triple_free(unsigned char **values) {
+/*
+ int i;
+ for(i=0;i<9;i++)
+ if(values[i])
+ free(values[i]);
+*/
+
+ free(values);
+}
+
+static int
+librdf_storage_b_context_remove_statement(librdf_storage* storage,
+ librdf_node* context_node,
+ librdf_statement* statement)
+{
+ librdf_storage_b_context* context=(librdf_storage_b_context*)storage->context;
+ b_triple_t *triple;
+ b_error_t error;
+
+ if(!(triple= librdf_storage_b_triple(storage,
+ librdf_statement_get_subject(statement),
+ librdf_statement_get_predicate(statement),
+ librdf_statement_get_object(statement),
+ context_node)))
+ return 1;
+
+ if((error=b_remove_triple(context->db, triple))!=B_OK) {
+ librdf_log(storage->world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_STORAGE,
+ NULL, "B database %s remove triple failed - %s", context->path,
+ b_strerror(error));
+
+ b_triple_destroy(triple);
+ return 1;
+ }
+
+ b_triple_destroy(triple);
+ return 0;
+}
+
+static int
+librdf_storage_b_remove_statement(librdf_storage* storage,
+ librdf_statement* statement)
+{
+ return librdf_storage_b_context_remove_statement(storage, NULL,
+ statement);
+}
+
+static int
+librdf_storage_b_contains_statement(librdf_storage* storage,
+ librdf_statement* statement)
+{
+ librdf_storage_b_context* context=(librdf_storage_b_context*)storage->context;
+ b_triple_t *triple;
+ b_error_t error;
+ char status;
+
+ if(!(triple= librdf_storage_b_triple(storage,
+ librdf_statement_get_subject(statement),
+ librdf_statement_get_predicate(statement),
+ librdf_statement_get_object(statement),
+ NULL)))
+ return 1;
+
+ if((error=b_get_triple(context->db, triple, &status))!=B_OK) {
+ librdf_log(storage->world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_STORAGE,
+ NULL, "B database %s remove triple failed - %s", context->path,
+ b_strerror(error));
+
+ b_triple_destroy(triple);
+ return 1;
+ }
+
+ b_triple_destroy(triple);
+ return status ? 1 : 0;
+}
+
+static librdf_stream*
+librdf_storage_b_serialise(librdf_storage* storage)
+{
+ librdf_stream *stream;
+ librdf_storage_b_stream_context *scontext;
+ librdf_storage_b_context* context=(librdf_storage_b_context*)storage->context;
+ b_error_t error;
+
+ scontext=(librdf_storage_b_stream_context*)LIBRDF_CALLOC(librdf_storage_b_stream_context, 1, sizeof(librdf_storage_b_stream_context));
+ scontext->storage=storage;
+ scontext->b_context=context;
+
+ librdf_storage_add_reference(scontext->storage);
+
+ if((error=b_iterator_triple_new(context->db, &scontext->iterator, NULL))!=B_OK) {
+ librdf_log(storage->world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_STORAGE,
+ NULL, "B iterator create failed - %s", context->path,
+ b_strerror(error));
+ librdf_storage_b_stream_finished((void*)scontext);
+ return NULL;
+ }
+
+ if(!(stream=librdf_new_stream(storage->world,
+ (void*)scontext,
+ &librdf_storage_b_stream_end_of_stream,
+ &librdf_storage_b_stream_next_statement,
+ &librdf_storage_b_stream_get_statement,
+ &librdf_storage_b_stream_finished))) {
+ librdf_storage_b_stream_finished((void*)scontext);
+ return NULL;
+ }
+
+ return stream;
+}
+
+static int
+librdf_storage_b_get_next_stream_common(librdf_storage_b_stream_context* scontext,
+ b_iterator_triple_t *iterator,
+ librdf_statement **statement)
+{
+ librdf_node *node;
+ b_triple_t *next;
+ b_error_t error;
+
+ if((error=b_iterator_triple_step(iterator, &next))!=B_OK) {
+ librdf_log(scontext->storage->world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_STORAGE,
+ NULL, "B database %s iterator triple step failed - %s",
+ scontext->b_context->path, b_strerror(error));
+ return 1;
+ }
+
+ if(!next)
+ return 1;
+
+ if(!(*statement=librdf_new_statement(scontext->storage->world)))
+ return 1;
+
+ librdf_statement_clear(*statement);
+
+ if(next->subject_uri)
+ node=librdf_new_node_from_uri_string(scontext->storage->world,
+ next->subject_uri);
+ else
+ node=librdf_new_node_from_blank_identifier(scontext->storage->world,
+ next->subject_bnode);
+
+ librdf_statement_set_subject(*statement, node);
+
+ node=librdf_new_node_from_uri_string(scontext->storage->world,
+ next->property);
+
+ librdf_statement_set_predicate(*statement, node);
+
+ if(next->object_uri)
+ node=librdf_new_node_from_uri_string(scontext->storage->world,
+ next->object_uri);
+ else if(next->object_bnode)
+ node=librdf_new_node_from_blank_identifier(scontext->storage->world,
+ next->object_bnode);
+ else {
+ librdf_uri *datatype;
+
+ if(next->datatype)
+ datatype=librdf_new_uri(scontext->storage->world,
+ next->datatype);
+ else
+ datatype=NULL;
+
+ node=librdf_new_node_from_typed_literal(scontext->storage->world,
+ next->object_literal,
+ (char *)next->lang,
+ datatype);
+
+ if(datatype)
+ librdf_free_uri(datatype);
+ }
+
+ librdf_statement_set_object(*statement, node);
+
+ return 0;
+}
+
+static int
+librdf_storage_b_stream_end_of_stream(void* context)
+{
+ librdf_storage_b_stream_context* scontext=(librdf_storage_b_stream_context*)context;
+
+ if(scontext->finished)
+ return 1;
+
+ if(scontext->statement == NULL) {
+ if(librdf_storage_b_get_next_stream_common(scontext, scontext->iterator, &scontext->statement))
+ scontext->finished=1;
+ }
+
+ return scontext->finished;
+}
+
+static int
+librdf_storage_b_stream_next_statement(void* context)
+{
+ librdf_storage_b_stream_context* scontext=(librdf_storage_b_stream_context*)context;
+
+ if(scontext->finished)
+ return 1;
+
+ if(librdf_storage_b_get_next_stream_common(scontext, scontext->iterator, &scontext->statement))
+ scontext->finished=1;
+
+ return scontext->finished;
+}
+
+static void*
+librdf_storage_b_stream_get_statement(void* context, int flags)
+{
+ librdf_storage_b_stream_context* scontext=(librdf_storage_b_stream_context*)context;
+
+ switch(flags) {
+ case LIBRDF_ITERATOR_GET_METHOD_GET_OBJECT:
+ return scontext->statement;
+ case LIBRDF_ITERATOR_GET_METHOD_GET_CONTEXT:
+ return scontext->context;
+ default:
+ librdf_log(scontext->storage->world,
+ 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_STORAGE, NULL,
+ "Unknown iterator method flag %d", flags);
+ return NULL;
+ }
+}
+
+static void
+librdf_storage_b_stream_finished(void* context)
+{
+ librdf_storage_b_stream_context* scontext=(librdf_storage_b_stream_context*)context;
+
+ if(scontext->storage)
+ librdf_storage_remove_reference(scontext->storage);
+
+ if(scontext->statement)
+ librdf_free_statement(scontext->statement);
+
+ if(scontext->context)
+ librdf_free_node(scontext->context);
+
+ if(scontext->iterator)
+ b_iterator_triple_destroy(scontext->iterator);
+
+ LIBRDF_FREE(librdf_storage_b_stream_context, scontext);
+}
+
+static librdf_stream*
+librdf_storage_b_find_statements(librdf_storage* storage, librdf_statement* statement)
+{
+ librdf_stream *stream;
+ librdf_storage_b_stream_context *scontext;
+ librdf_storage_b_context* context=(librdf_storage_b_context*)storage->context;
+ b_triple_t *compare;
+ b_error_t error;
+
+ scontext=(librdf_storage_b_stream_context*)LIBRDF_CALLOC(librdf_storage_b_stream_context, 1, sizeof(librdf_storage_b_stream_context));
+ scontext->storage=storage;
+ scontext->b_context=context;
+
+ librdf_storage_add_reference(scontext->storage);
+
+ if(!(compare = librdf_storage_b_triple(storage,
+ librdf_statement_get_subject(statement),
+ librdf_statement_get_predicate(statement),
+ librdf_statement_get_object(statement),
+ NULL))) {
+ librdf_storage_b_stream_finished((void*)scontext);
+ return NULL;
+ }
+
+ if((error=b_iterator_triple_new(context->db, &scontext->iterator, compare))!=B_OK) {
+ librdf_log(storage->world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_STORAGE,
+ NULL, "B iterator create failed - %s", context->path,
+ b_strerror(error));
+
+ librdf_storage_b_stream_finished((void*)scontext);
+ b_triple_destroy(compare);
+ return NULL;
+ }
+
+ b_triple_destroy(compare);
+
+ if(!(stream=librdf_new_stream(storage->world,
+ (void*)scontext,
+ &librdf_storage_b_stream_end_of_stream,
+ &librdf_storage_b_stream_next_statement,
+ &librdf_storage_b_stream_get_statement,
+ &librdf_storage_b_stream_finished))) {
+ librdf_storage_b_stream_finished((void*)scontext);
+ return NULL;
+ }
+
+ return stream;
+}
+
+static librdf_stream*
+librdf_storage_b_context_serialise(librdf_storage* storage, librdf_node* context_node)
+{
+ librdf_stream *stream;
+ librdf_storage_b_stream_context *scontext;
+ librdf_storage_b_context* context=(librdf_storage_b_context*)storage->context;
+ b_triple_t *compare;
+ b_error_t error;
+
+ scontext=(librdf_storage_b_stream_context*)LIBRDF_CALLOC(librdf_storage_b_stream_context, 1, sizeof(librdf_storage_b_stream_context));
+ scontext->storage=storage;
+ scontext->b_context=context;
+
+ librdf_storage_add_reference(scontext->storage);
+
+ if(!(compare = librdf_storage_b_triple (storage, NULL, NULL, NULL, context_node))) {
+ librdf_storage_b_stream_finished((void*)scontext);
+ return NULL;
+ }
+
+ if((error=b_iterator_triple_new(context->db, &scontext->iterator, compare))!=B_OK) {
+ librdf_log(storage->world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_STORAGE,
+ NULL, "B iterator create failed - %s", context->path,
+ b_strerror(error));
+
+ librdf_storage_b_stream_finished((void*)scontext);
+ b_triple_destroy(compare);
+ return NULL;
+ }
+
+ b_triple_destroy(compare);
+
+ if(!(stream=librdf_new_stream(storage->world,
+ (void*)scontext,
+ &librdf_storage_b_stream_end_of_stream,
+ &librdf_storage_b_stream_next_statement,
+ &librdf_storage_b_stream_get_statement,
+ &librdf_storage_b_stream_finished))) {
+ librdf_storage_b_stream_finished((void*)scontext);
+ return NULL;
+ }
+
+ return stream;
+}
+
+static librdf_iterator*
+librdf_storage_b_get_contexts(librdf_storage* storage) {
+ librdf_storage_b_context* context=(librdf_storage_b_context*)storage->context;
+ librdf_storage_b_iterator_context* icontext;
+ librdf_iterator* iterator;
+ b_error_t error;
+
+ icontext=(librdf_storage_b_iterator_context*)LIBRDF_CALLOC(librdf_storage_b_iterator_context, 1, sizeof(librdf_storage_b_iterator_context));
+ if(!icontext)
+ return NULL;
+
+ icontext->b_context=context;
+ icontext->storage=storage;
+
+ librdf_storage_add_reference(icontext->storage);
+
+ if((error=b_iterator_type_new(context->db, B_TYPE_CONTEXT, &icontext->iterator))!=B_OK) {
+ librdf_storage_b_iterator_finished((void*)icontext);
+ return NULL;
+ }
+
+ if(!(iterator=librdf_new_iterator(storage->world,
+ (void*)icontext,
+ &librdf_storage_b_iterator_is_end,
+ &librdf_storage_b_iterator_next_method,
+ &librdf_storage_b_iterator_get_method,
+ &librdf_storage_b_iterator_finished))) {
+ librdf_storage_b_iterator_finished((void*)icontext);
+ return NULL;
+ }
+
+ return iterator;
+}
+
+static int
+librdf_storage_b_get_next_iterator_common(librdf_storage_b_iterator_context* icontext)
+{
+ b_error_t error;
+
+ if(icontext->what)
+ LIBRDF_FREE(cstring, icontext->what);
+
+ if((error=b_iterator_type_step(icontext->iterator, &icontext->what, NULL))!=B_OK) {
+ librdf_log(icontext->storage->world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_STORAGE,
+ NULL, "B database %s iterator type step failed - %s",
+ icontext->b_context->path, b_strerror(error));
+ icontext->what=NULL;
+ return 1;
+ }
+
+ if(!icontext->what)
+ return 1;
+
+ return 0;
+}
+
+static int librdf_storage_b_iterator_is_end(void* iterator)
+{
+ librdf_storage_b_iterator_context* icontext=(librdf_storage_b_iterator_context*)iterator;
+
+ if(icontext->finished)
+ return 1;
+
+ if(!icontext->what)
+ if(librdf_storage_b_get_next_iterator_common(icontext))
+ icontext->finished=1;
+
+ return icontext->finished;
+}
+
+static int librdf_storage_b_iterator_next_method(void* iterator)
+{
+ librdf_storage_b_iterator_context* icontext=(librdf_storage_b_iterator_context*)iterator;
+
+ if(icontext->finished)
+ return 1;
+
+ if(librdf_storage_b_get_next_iterator_common(icontext))
+ icontext->finished=1;
+
+ return icontext->finished;
+}
+
+static void* librdf_storage_b_iterator_get_method(void* iterator, int flags)
+{
+ librdf_storage_b_iterator_context* icontext=(librdf_storage_b_iterator_context*)iterator;
+
+ switch(flags) {
+ case LIBRDF_ITERATOR_GET_METHOD_GET_OBJECT:
+ if(icontext->what)
+ return librdf_new_node_from_uri_string(icontext->storage->world,
+ icontext->what);
+ else
+ return NULL;
+
+ case LIBRDF_ITERATOR_GET_METHOD_GET_KEY:
+ case LIBRDF_ITERATOR_GET_METHOD_GET_VALUE:
+ return NULL;
+
+ default:
+ librdf_log(icontext->storage->world,
+ 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_STORAGE, NULL,
+ "Unknown iterator method flag %d", flags);
+ return NULL;
+ }
+}
+
+static void librdf_storage_b_iterator_finished(void* iterator)
+{
+ librdf_storage_b_iterator_context* icontext=(librdf_storage_b_iterator_context*)iterator;
+
+ if(icontext->storage)
+ librdf_storage_remove_reference(icontext->storage);
+
+ if(icontext->what)
+ free(icontext->what);
+
+ LIBRDF_FREE(librdf_storage_b_iterator_context, icontext);
+}
+
+static librdf_node*
+librdf_storage_b_get_feature(librdf_storage* storage, librdf_uri* feature)
+{
+ /* librdf_storage_b_context* scontext=(librdf_storage_b_context*)storage->context; */
+ unsigned char *uri_string;
+
+ if(!feature)
+ return NULL;
+
+ if(!(uri_string=librdf_uri_as_string(feature)))
+ return NULL;
+
+ if(!strcmp((const char*)uri_string, LIBRDF_MODEL_FEATURE_CONTEXTS)) {
+ return librdf_new_node_from_typed_literal(storage->world,
+ (const unsigned char*)"1",
+ NULL, NULL);
+ }
+
+ return NULL;
+}
+
+/* local function to register B storage functions */
+static void
+librdf_storage_b_register_factory(librdf_storage_factory *factory)
+{
+ factory->context_length = sizeof(librdf_storage_b_context);
+
+ factory->init = librdf_storage_b_init;
+ factory->terminate = librdf_storage_b_terminate;
+ factory->open = librdf_storage_b_open;
+ factory->close = librdf_storage_b_close;
+ factory->size = librdf_storage_b_size;
+ factory->add_statement = librdf_storage_b_add_statement;
+ factory->remove_statement = librdf_storage_b_remove_statement;
+ factory->contains_statement = librdf_storage_b_contains_statement;
+ factory->serialise = librdf_storage_b_serialise;
+ factory->find_statements = librdf_storage_b_find_statements;
+ factory->context_add_statement = librdf_storage_b_context_add_statement;
+ factory->context_remove_statement = librdf_storage_b_context_remove_statement;
+ factory->context_serialise = librdf_storage_b_context_serialise;
+ factory->get_contexts = librdf_storage_b_get_contexts;
+ factory->get_feature = librdf_storage_b_get_feature;
+}
+
+void
+librdf_init_storage_b(librdf_world *world)
+{
+ librdf_storage_register_factory(world, "b", "B",
+ &librdf_storage_b_register_factory);
+}
+
Added: incubator/triplesoup/donations/TRIPLES-2-libb/src/Makefile.in
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/src/Makefile.in?view=auto&rev=510255
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-2-libb/src/Makefile.in (added)
+++ incubator/triplesoup/donations/TRIPLES-2-libb/src/Makefile.in Wed Feb 21 13:56:43 2007
@@ -0,0 +1,51 @@
+# (c) 2006 Satis Superque Merce B.V. All rights reserved. This code
+# contains trade secrets of Satis Superque Merce B.V. and any
+# unauthorized use or disclosure is strictly prohibited.
+#
+# $Id: Makefile.in 29834 2006-10-19 16:22:05Z Andrea Marchesini <ba...@theveniceproject.com> $
+#
+
+DEPTH = ../../../..
+topsrcdir = @top_srcdir@
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+include $(DEPTH)/config/autoconf.mk
+
+MODULE = b
+LIBRARY_NAME = mozb_s
+
+CSRCS = \
+ badd.c \
+ bcache.c \
+ bcount.c \
+ bdestroy.c \
+ berror.c \
+ bget.c \
+ bhash.c \
+ bio.c \
+ biterator.c \
+ bmd5.c \
+ bnew.c \
+ bremove.c \
+ bstring.c \
+ bsync.c \
+ btcache.c \
+ btempty.c \
+ btimer.c \
+ btriple.c \
+ $(NULL)
+
+EXPORTS = \
+ b.h
+
+# We want only the static lib, not the shared lib
+FORCE_STATIC_LIB = 1
+
+include $(topsrcdir)/config/rules.mk
+
+DEFINES += -DB_INTERNAL
+
+LOCAL_INCLUDES += \
+ -I$(srcdir) \
+ $(NULL)
Added: incubator/triplesoup/donations/TRIPLES-2-libb/src/b.h
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/src/b.h?view=auto&rev=510255
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-2-libb/src/b.h (added)
+++ incubator/triplesoup/donations/TRIPLES-2-libb/src/b.h Wed Feb 21 13:56:43 2007
@@ -0,0 +1,322 @@
+/* (c) 2007 Satis Superque Merce B.V. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ */
+
+#ifndef __B_H__
+#define __B_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef WIN32
+#include <sys/mman.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/time.h>
+#else
+#include <Windows.h>
+#include <Winbase.h>
+#include <Winsock2.h>
+#include <sys/timeb.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <time.h>
+
+#include <fcntl.h>
+
+/**
+ * b_t:
+ *
+ * The principal data struct. You must have 1 for any B storage.
+ **/
+typedef struct b_t b_t;
+
+/**
+ * b_iterator_type_t:
+ *
+ * The data struct for a Type Iterator. You should use this data struct
+ * only with b_iterator_type_*() functions.
+ **/
+typedef struct b_iterator_type_t b_iterator_type_t;
+
+/**
+ * b_iterator_triple_t:
+ *
+ * The data struct for a Triple Iterator. You should use this data struct
+ * only with b_iterator_triple_*() functions.
+ **/
+typedef struct b_iterator_triple_t b_iterator_triple_t;
+
+/**
+ * b_timer_t:
+ *
+ * The data struct for a Timer. You should use this data struct only with
+ * b_timer_*() functions.
+ **/
+typedef struct b_timer_t b_timer_t;
+
+/**
+ * b_int64:
+ *
+ * Variable 64bit signed.
+ **/
+
+/**
+ * b_uint64:
+ *
+ * Variable 64bit unsigned.
+ **/
+
+#ifdef B_INT64_TYPE
+typedef B_INT64_TYPE b_int64;
+typedef unsigned B_INT64_TYPE b_uint64;
+#elif defined(_MSC_VER) || defined(__BORLANDC__)
+typedef __int64 b_int64;
+typedef unsigned __int64 b_uint64;
+#else
+typedef long long int b_int64;
+typedef unsigned long long int b_uint64;
+#endif
+
+/**
+ * b_error_t:
+ * @B_OK: Success.
+ * @B_ERROR_MEMORY: Error in a alloc operation.
+ * @B_ERROR_POSIX: System error. If you are using a Posix system, read the
+ * errno variable.
+ * @B_ERROR_INTERNAL: Internal error. It shouldn't be.
+ * @B_ERROR_DATA: Pls, read the documentation.
+ *
+ * The list of errors for this library.
+ **/
+typedef enum {
+ B_OK = 0,
+
+ B_ERROR_MEMORY,
+ B_ERROR_POSIX,
+ B_ERROR_INTERNAL,
+
+ B_ERROR_DATA
+} b_error_t;
+
+/**
+ * b_type_t:
+ * @B_TYPE_URI: The URI elements.
+ * @B_TYPE_PROPERTY: The properties are in a separated B-Tree.
+ * @B_TYPE_LITERAL: The Literal elements.
+ * @B_TYPE_BNODE: The BNode elements.
+ * @B_TYPE_CONTEXT: The Contexts are URI but they are into a separated B-Tree.
+ * @B_TYPE_DATATYPE: Like the Contexts the Datatypes are into a separated
+ * B-Tree.
+ *
+ * The types of simple elements.
+ */
+typedef enum {
+ B_TYPE_URI,
+ B_TYPE_PROPERTY,
+ B_TYPE_LITERAL,
+ B_TYPE_BNODE,
+ B_TYPE_CONTEXT,
+ B_TYPE_DATATYPE
+} b_type_t;
+
+/**
+ * b_triple_t:
+ * @subject_uri: subject of this triple if the subject is a URI.
+ * @subject_uri_len: The length of the subject_uri.
+ * @subject_bnode: subject of this triple if the subject is a BNODE.
+ * @subject_bnode_len: The length of the subject_bnode.
+ * @property: property of this triple.
+ * @property_len: The length of the property.
+ * @object_uri: object of this triple if the object is a URI.
+ * @object_uri_len: The length of the object_uri.
+ * @object_bnode: object of this triple if the object is a BNODE.
+ * @object_bnode_len: The length of the object_bnode.
+ * @object_literal: object of this triple if the object is a LITERAL.
+ * @object_literal_len: The length of the object_literal.
+ * @context: context of this triple. It can be NULL.
+ * @context_len: The length of the context.
+ * @datatype: datatype of this triple. It can be NULL.
+ * @datatype_len: The length of the datatype.
+ * @lang: lang of this triple. It can be NULL.
+ * @lang_len: The length of the lang.
+ *
+ * This struct describes a RDF triple.
+ */
+typedef struct {
+ unsigned char * subject_uri;
+ b_uint64 subject_uri_len;
+
+ unsigned char * subject_bnode;
+ b_uint64 subject_bnode_len;
+
+ unsigned char * property;
+ b_uint64 property_len;
+
+ unsigned char * object_uri;
+ b_uint64 object_uri_len;
+
+ unsigned char * object_bnode;
+ b_uint64 object_bnode_len;
+
+ unsigned char * object_literal;
+ b_uint64 object_literal_len;
+
+ unsigned char * context;
+ b_uint64 context_len;
+
+ unsigned char * datatype;
+ b_uint64 datatype_len;
+
+ unsigned char * lang;
+ b_uint64 lang_len;
+} b_triple_t;
+
+b_error_t b_new (b_t ** data,
+ unsigned char * path);
+
+b_error_t b_set_max_cache (b_t * data,
+ b_uint64 max_cache);
+
+b_error_t b_get_max_cache (b_t * data,
+ b_uint64 * max_cache);
+
+b_error_t b_destroy (b_t * data);
+
+b_error_t b_sync (b_t * data);
+
+b_error_t b_add_type (b_t * data,
+ b_type_t type,
+ unsigned char * what,
+ b_uint64 len);
+
+b_error_t b_add_triple (b_t * data,
+ b_triple_t * triple);
+
+b_error_t b_get_type (b_t * data,
+ b_type_t type,
+ unsigned char * what,
+ b_uint64 len,
+ char * exist);
+
+b_error_t b_get_triple (b_t * data,
+ b_triple_t * triple,
+ char * exist);
+
+b_error_t b_iterator_type_new
+ (b_t * data,
+ b_type_t type,
+ b_iterator_type_t ** iterator);
+
+b_error_t b_iterator_type_step
+ (b_iterator_type_t * iterator,
+ unsigned char ** ret,
+ b_uint64 * ret_size);
+
+b_error_t b_iterator_type_destroy
+ (b_iterator_type_t * iterator);
+
+b_error_t b_iterator_triple_new
+ (b_t * data,
+ b_iterator_triple_t ** iterator,
+ b_triple_t * compare);
+
+b_error_t b_iterator_triple_step
+ (b_iterator_triple_t * iterator,
+ b_triple_t ** triple);
+
+b_error_t b_iterator_triple_destroy
+ (b_iterator_triple_t * iterator);
+
+b_error_t b_remove_triple (b_t * data,
+ b_triple_t * triple);
+
+b_error_t b_remove_type (b_t * data,
+ b_type_t type,
+ unsigned char * what,
+ b_uint64 len);
+
+b_error_t b_count_type (b_t * data,
+ b_type_t type,
+ b_uint64 * count);
+
+b_error_t b_count_triple (b_t * data,
+ b_uint64 * count);
+
+char * b_strerror (b_error_t error);
+
+b_error_t b_triple_new (b_triple_t ** triple,
+ unsigned char * subject_uri,
+ b_uint64 subject_uri_len,
+ unsigned char * subject_bnode,
+ b_uint64 subject_bnode_len,
+ unsigned char * property,
+ b_uint64 property_len,
+ unsigned char * object_uri,
+ b_uint64 object_uri_len,
+ unsigned char * object_bnode,
+ b_uint64 object_bnode_len,
+ unsigned char * object_literal,
+ b_uint64 object_literal_len,
+ unsigned char * context,
+ b_uint64 context_len,
+ unsigned char * datatype,
+ b_uint64 datatype_len,
+ unsigned char * lang,
+ b_uint64 lang_len);
+
+b_error_t b_triple_new_incomplete
+ (b_triple_t ** triple,
+ unsigned char * subject_uri,
+ b_uint64 subject_uri_len,
+ unsigned char * subject_bnode,
+ b_uint64 subject_bnode_len,
+ unsigned char * property,
+ b_uint64 property_len,
+ unsigned char * object_uri,
+ b_uint64 object_uri_len,
+ unsigned char * object_bnode,
+ b_uint64 object_bnode_len,
+ unsigned char * object_literal,
+ b_uint64 object_literal_len,
+ unsigned char * context,
+ b_uint64 context_len,
+ unsigned char * datatype,
+ b_uint64 datatype_len,
+ unsigned char * lang,
+ b_uint64 lang_len);
+
+b_error_t b_triple_destroy
+ (b_triple_t * triple);
+
+b_error_t b_triple_print (FILE * file,
+ b_triple_t * triple);
+
+b_error_t b_timer_new (b_timer_t ** timer);
+
+b_error_t b_timer_destroy (b_timer_t * timer,
+ b_uint64 * nanosec);
+
+b_error_t b_timer_start (b_timer_t * timer);
+
+b_error_t b_timer_stop (b_timer_t * timer);
+
+b_error_t b_timer_diff (b_timer_t * timer,
+ b_uint64 * nanosec);
+
+#ifdef B_INTERNAL
+# include <b_internal.h>
+#endif
+
+#endif
+
+/* EOF */
Added: incubator/triplesoup/donations/TRIPLES-2-libb/src/b_internal.h
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/src/b_internal.h?view=auto&rev=510255
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-2-libb/src/b_internal.h (added)
+++ incubator/triplesoup/donations/TRIPLES-2-libb/src/b_internal.h Wed Feb 21 13:56:43 2007
@@ -0,0 +1,495 @@
+/* (c) 2007 Satis Superque Merce B.V. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ */
+
+#ifndef __B_INTERNAL_H__
+#define __B_INTERNAL_H__
+
+#define B_PATH_URIS_DATA "_uris.data"
+#define B_PATH_PROPERTIES_DATA "_properties.data"
+#define B_PATH_LITERALS_DATA "_literals.data"
+#define B_PATH_BNODES_DATA "_bnodes.data"
+#define B_PATH_CONTEXTS_DATA "_contexts.data"
+#define B_PATH_DATATYPES_DATA "_datatypes.data"
+#define B_PATH_TRIPLES_DATA "_triples.data"
+
+#define B_HASH_SIZE 16
+#define B_TRIPLE_SIZE (sizeof(b_tmap_item_t) * 9)
+
+#define B_MAX_CACHE_ITEMS 512
+#define B_MIN_CACHE_ITEMS 32
+
+#define B_TMAP_NUMB 128 /* <= 127 = 0xFE >> 0x1 -> 01111111 */
+
+#define B_TMAP_VALUE( x ) (x & 0x01)
+#define B_TMAP_DATA( x ) ((x & 0xFE) >> 0x1)
+#define B_TMAP_SET( x , y ) ((x << 0x1 ) | y)
+
+#define B_TMAP_VALUE_EMPTY 0x0
+#define B_TMAP_VALUE_FULL 0x1
+
+#ifdef WIN32
+# define snprintf sprintf_s
+#endif
+
+#ifdef B_DEBUG
+# define B_LOG( x ) \
+ fprintf (stderr, "%s (%d) - ", __FILE__, __LINE__); \
+ fprintf (stderr, x); \
+ fprintf (stderr, "\n");
+
+# define B_LOG1( x , a ) \
+ fprintf (stderr, "%s (%d) - ", __FILE__, __LINE__); \
+ fprintf (stderr, x, a); \
+ fprintf (stderr, "\n");
+
+# define B_LOG2( x , a , b ) \
+ fprintf (stderr, "%s (%d) - ", __FILE__, __LINE__); \
+ fprintf (stderr, x, a, b); \
+ fprintf (stderr, "\n");
+
+# define B_LOG3( x , a , b , c ) \
+ fprintf (stderr, "%s (%d) - ", __FILE__, __LINE__); \
+ fprintf (stderr, x, a, b, c); \
+ fprintf (stderr, "\n");
+
+# define B_LOG4( x , a , b , c , d ) \
+ fprintf (stderr, "%s (%d) - ", __FILE__, __LINE__); \
+ fprintf (stderr, x, a, b, c, d); \
+ fprintf (stderr, "\n");
+
+# define B_LOG5( x , a , b , c , d , e ) \
+ fprintf (stderr, "%s (%d) - ", __FILE__, __LINE__); \
+ fprintf (stderr, x, a, b, c, d, e); \
+ fprintf (stderr, "\n");
+
+# define B_LOG6( x , a , b , c , d , e , f) \
+ fprintf (stderr, "%s (%d) - ", __FILE__, __LINE__); \
+ fprintf (stderr, x, a, b, c, d, e, f); \
+ fprintf (stderr, "\n");
+
+# define B_LOG7( x , a , b , c , d , e , f , g ) \
+ fprintf (stderr, "%s (%d) - ", __FILE__, __LINE__); \
+ fprintf (stderr, x, a, b, c, d, e, f, g); \
+ fprintf (stderr, "\n");
+
+# define B_LOG8( x , a , b , c , d , e , f , g , h ) \
+ fprintf (stderr, "%s (%d) - ", __FILE__, __LINE__); \
+ fprintf (stderr, x, a, b, c, d, e, f, g, h); \
+ fprintf (stderr, "\n");
+
+# define B_LOG9( x , a , b , c , d , e , f , g , h , i ) \
+ fprintf (stderr, "%s (%d) - ", __FILE__, __LINE__); \
+ fprintf (stderr, x, a, b, c, d, e, f, g, h, i); \
+ fprintf (stderr, "\n");
+
+# define B_LOG19( x , a , b , c , d , e , f , g , h , i , l , m , n , o , \
+ p , q , r , s , t , u ) \
+ fprintf (stderr, "%s (%d) - ", __FILE__, __LINE__); \
+ fprintf (stderr, x, a, b, c, d, e, f, g, h, i , l , m , n , o , p , q , \
+ r , s , t , u ); \
+ fprintf (stderr, "\n");
+#else
+# define B_LOG( x )
+# define B_LOG1( x , a )
+# define B_LOG2( x , a , b )
+# define B_LOG3( x , a , b , c )
+# define B_LOG4( x , a , b , c , d )
+# define B_LOG5( x , a , b , c , d , e )
+# define B_LOG6( x , a , b , c , d , e , f )
+# define B_LOG7( x , a , b , c , d , e , f , g )
+# define B_LOG8( x , a , b , c , d , e , f , g , h )
+# define B_LOG9( x , a , b , c , d , e , f , g , h , i )
+# define B_LOG19( x , a , b , c , d , e , f , g , h , i , l , m , n , o , \
+ p , q , r , s , t , u )
+#endif
+
+typedef struct b_io_t b_io_t;
+typedef struct b_el_t b_el_t;
+typedef struct b_hash_t b_hash_t;
+typedef struct b_cache_t b_cache_t;
+typedef struct b_tcache_t b_tcache_t;
+typedef struct b_string_t b_string_t;
+
+typedef struct b_tmap_t b_tmap_t;
+typedef struct b_tmap_item_t b_tmap_item_t;
+
+typedef struct b_map_t b_map_t;
+
+typedef struct b_tempty_t b_tempty_t;
+
+typedef struct b_iterator_compare_t
+ b_iterator_compare_t;
+
+typedef b_int64 (*b_write_func) (unsigned char * what,
+ b_uint64 size,
+ void * data);
+
+struct b_cache_t {
+ unsigned char hash[B_HASH_SIZE];
+
+ unsigned char * what;
+ b_uint64 len;
+
+ b_uint64 pointer;
+};
+
+struct b_tcache_t {
+ b_uint64 tmap_pointer;
+ unsigned char tmap_index;
+
+ b_cache_t * subject_uri;
+ b_cache_t * subject_bnode;
+
+ b_cache_t * property;
+
+ b_cache_t * object_uri;
+ b_cache_t * object_bnode;
+ b_cache_t * object_literal;
+
+ b_cache_t * context;
+
+ b_cache_t * datatype;
+ b_cache_t * lang;
+
+ b_tcache_t * prev;
+ b_tcache_t * next;
+};
+
+struct b_t {
+ b_uint64 max_cache;
+
+ b_hash_t * hashes_cache;
+ b_uint64 hashes_cache_items;
+
+ b_io_t * uris_io;
+ b_io_t * properties_io;
+ b_io_t * literals_io;
+ b_io_t * bnodes_io;
+ b_io_t * contexts_io;
+ b_io_t * datatypes_io;
+
+ b_io_t * triples_io;
+ b_tcache_t * triples_cache;
+ b_uint64 triples_cache_items;
+ b_uint64 triples_total;
+
+ b_tempty_t * triples_empty;
+ b_uint64 triples_empty_size;
+};
+
+struct b_hash_t {
+ unsigned char hash[B_HASH_SIZE];
+ unsigned char * what;
+ b_uint64 len;
+
+ b_hash_t * next;
+ b_hash_t * prev;
+};
+
+struct b_string_t {
+ unsigned char * string;
+ b_uint64 size;
+
+ b_write_func callback;
+ b_uint64 callback_size;
+ void * callback_data;
+ b_int64 callback_ret;
+};
+
+struct b_io_t {
+ void * fd;
+
+ b_uint64 size;
+ b_uint64 pointer;
+ b_uint64 end_pointer;
+
+ unsigned char *data;
+};
+
+struct b_el_t {
+ b_tcache_t * cache;
+ b_el_t * next;
+};
+
+struct b_iterator_type_t {
+ b_t * data;
+ b_type_t type;
+
+ b_io_t * io;
+
+ char right;
+ b_uint64 pointer;
+};
+
+struct b_iterator_compare_t {
+ char subject_uri_exists;
+ unsigned char subject_uri[B_HASH_SIZE];
+ char subject_bnode_exists;
+ unsigned char subject_bnode[B_HASH_SIZE];
+
+ char property_exists;
+ unsigned char property[B_HASH_SIZE];
+
+ char object_uri_exists;
+ unsigned char object_uri[B_HASH_SIZE];
+ char object_bnode_exists;
+ unsigned char object_bnode[B_HASH_SIZE];
+ char object_literal_exists;
+ unsigned char object_literal[B_HASH_SIZE];
+
+ char context_exists;
+ unsigned char context[B_HASH_SIZE];
+
+ char datatype_exists;
+ unsigned char datatype[B_HASH_SIZE];
+ char lang_exists;
+ unsigned char lang[B_HASH_SIZE];
+};
+
+struct b_iterator_triple_t {
+ b_t * data;
+ char status;
+ b_iterator_compare_t *compare;
+
+ b_tcache_t * file;
+ b_el_t * results;
+};
+
+struct b_map_t {
+ /* This 2 elements must be in the top: */
+ unsigned char hash[16];
+ b_uint64 len;
+
+ /* how many triples linked with this item? */
+ b_uint64 instances;
+
+ b_uint64 left;
+ b_uint64 right;
+ b_uint64 parent;
+};
+
+struct b_timer_t {
+ struct timeval start;
+ struct timeval stop;
+ char stopped;
+};
+
+struct b_tempty_t {
+ b_uint64 pointer;
+ b_tempty_t * next;
+};
+
+struct b_tmap_t {
+ /* Maybe tomorrow a single bit: */
+ unsigned char map[B_TMAP_NUMB];
+
+ unsigned char subjects_uri[B_TMAP_NUMB];
+ unsigned char subjects_bnode[B_TMAP_NUMB];
+
+ unsigned char properties[B_TMAP_NUMB];
+
+ unsigned char objects_uri[B_TMAP_NUMB];
+ unsigned char objects_bnode[B_TMAP_NUMB];
+ unsigned char objects_literal[B_TMAP_NUMB];
+
+ unsigned char contexts[B_TMAP_NUMB];
+
+ unsigned char datatypes[B_TMAP_NUMB];
+ unsigned char langs[B_TMAP_NUMB];
+};
+
+struct b_tmap_item_t {
+ unsigned char hash[B_HASH_SIZE];
+ b_uint64 pointer;
+};
+
+/* b_string: */
+b_error_t b_string_new (b_string_t ** string);
+
+b_error_t b_string_new_callback (b_string_t ** string,
+ b_write_func callback,
+ b_uint64 size,
+ void * data);
+
+b_error_t b_string_destroy (b_string_t * string,
+ b_int64 * ret);
+
+b_error_t b_string_add (b_string_t * string,
+ unsigned char * what,
+ b_uint64 size);
+
+b_error_t b_string_callback (b_string_t * string,
+ b_int64 * ret);
+
+unsigned char * b_string_alloc (unsigned char * what,
+ b_uint64 len);
+
+/* io: */
+b_error_t b_io_new (b_io_t ** ret,
+ unsigned char * file,
+ b_uint64 size);
+
+b_error_t b_io_destroy (b_io_t * io);
+
+b_error_t b_io_sync (b_io_t * io);
+
+b_int64 b_io_read (b_io_t * io,
+ void * what,
+ b_uint64 size);
+
+b_int64 b_io_write (b_io_t * io,
+ void * what,
+ b_uint64 size,
+ b_uint64 buffer_max);
+
+b_int64 b_io_seek (b_io_t * io,
+ b_uint64 size,
+ int whence);
+
+/* count: */
+b_error_t b_count_triple_cache (b_t * data,
+ b_uint64 * count);
+
+/* sync: */
+b_error_t b_sync_cache (b_t * data,
+ b_io_t * io,
+ unsigned char * hash,
+ unsigned char * what,
+ b_uint64 len);
+
+b_error_t b_sync_tcache (b_t * data);
+
+b_error_t b_sync_instances (b_t * data,
+ b_tcache_t * cache,
+ char add);
+
+/* add: */
+b_error_t b_add_triple_cache (b_t * data,
+ b_triple_t * triple,
+ b_uint64 tmap_pointer,
+ unsigned char tmap_index);
+
+/* get: */
+b_error_t b_get_type_cache (b_t * data,
+ b_type_t type,
+ unsigned char * what,
+ b_uint64 len,
+ b_cache_t ** exist);
+
+b_error_t b_get_type_pointer (b_t * data,
+ b_type_t type,
+ b_uint64 pointer,
+ b_cache_t ** exist);
+
+b_error_t b_get_type_cache_hash (b_t * data,
+ b_type_t type,
+ unsigned char * hash,
+ unsigned char * what,
+ b_uint64 len,
+ b_cache_t ** exist);
+
+b_error_t b_get_type_internal (b_t * data,
+ b_type_t type,
+ b_io_t ** io);
+
+b_error_t b_get_triple_cache (b_t * data,
+ b_triple_t * triple,
+ b_tcache_t ** exist);
+
+/* tcache: */
+b_error_t b_tcache_destroy (b_tcache_t ** cache,
+ b_uint64 * numb);
+
+b_error_t b_tcache_destroy_single (b_tcache_t ** cache_root,
+ b_uint64 * numb,
+ b_tcache_t * cache);
+
+b_error_t b_tcache_copy (b_tcache_t * src,
+ b_tcache_t ** dest);
+
+b_error_t b_tcache_copy_easy (b_tcache_t * src,
+ b_tcache_t ** dest);
+
+/* copy: */
+/* triple: */
+b_error_t b_triple_check (b_triple_t * triple);
+
+b_error_t b_triple_new_cache (b_tcache_t * cache,
+ b_triple_t ** ret);
+
+b_error_t b_triple_copy (b_triple_t * src,
+ b_triple_t ** dest);
+
+/* hash: */
+b_error_t b_hash_new (b_t * data,
+ unsigned char * what,
+ b_uint64 len,
+ unsigned char * where);
+
+b_error_t b_hash_copy (unsigned char * dst,
+ unsigned char * src);
+
+int b_hash_compare (unsigned char * a,
+ unsigned char * b);
+
+int b_hash_empty (unsigned char * a);
+
+b_error_t b_hash_zero (unsigned char * a);
+
+b_error_t b_hash_print (FILE * file,
+ unsigned char * hash);
+
+b_error_t b_hash_destroy (b_hash_t ** cache,
+ b_uint64 * numb);
+
+/* md5: */
+b_error_t b_MD5 (unsigned char * what,
+ b_uint64 len,
+ unsigned char * where);
+
+/* graph: */
+b_error_t b_graph (b_t * data,
+ b_type_t type,
+ FILE * file);
+
+/* tempty: */
+b_error_t b_tempty_check (b_t * data,
+ b_tmap_t * tmap,
+ b_uint64 pointer,
+ char remove);
+
+char b_tempty_get (b_t * data,
+ b_tmap_t * tmap,
+ b_uint64 * pointer);
+
+void b_tempty_destroy (b_tempty_t ** list);
+
+/* cache: */
+b_error_t b_cache_new (unsigned char * hash,
+ unsigned char * what,
+ b_uint64 len,
+ b_uint64 pointer,
+ b_cache_t ** ret);
+
+b_error_t b_cache_destroy (b_cache_t * cache);
+
+b_error_t b_cache_copy (b_cache_t * src,
+ b_cache_t ** dest);
+
+b_error_t b_cache_copy_easy (b_cache_t * src,
+ b_cache_t ** dest);
+
+/* remove: */
+b_error_t b_remove_type_cache (b_t * data,
+ b_io_t * io,
+ b_cache_t * cache);
+
+#endif
+
+/* EOF */
Added: incubator/triplesoup/donations/TRIPLES-2-libb/src/badd.c
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/src/badd.c?view=auto&rev=510255
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-2-libb/src/badd.c (added)
+++ incubator/triplesoup/donations/TRIPLES-2-libb/src/badd.c Wed Feb 21 13:56:43 2007
@@ -0,0 +1,226 @@
+/* (c) 2007 Satis Superque Merce B.V. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ */
+
+#include <b.h>
+
+/**
+ * b_add_type:
+ * @data: The pointer to the b_t struct.
+ * @type: The type of the item.
+ * @what: The data as string.
+ * @len: The len of what. If it is 0, this function uses strlen on what.
+ * @returns: the error code.
+ *
+ * Adds a item into the storage. No dublicate items will be inserted.
+ **/
+b_error_t
+b_add_type (b_t * data, b_type_t type, unsigned char *what, b_uint64 len)
+{
+ b_io_t *io;
+ b_error_t error;
+ b_cache_t *exist = NULL;
+ unsigned char hash[B_HASH_SIZE];
+
+ B_LOG4 ("b_add_type: %p %d %p %d", data, type, what, (int) len);
+
+ if (!data || !what)
+ return B_ERROR_DATA;
+
+ len = len > 0 ? len : strlen ((char *) what);
+ b_hash_new (data, what, len, hash);
+
+ /* does it already exist? */
+ if ((error =
+ b_get_type_cache_hash (data, type, hash, what, len, &exist)) != B_OK)
+ return error;
+
+ if (exist)
+ {
+ b_cache_destroy (exist);
+ return B_OK;
+ }
+
+ b_cache_destroy (exist);
+
+ if ((error = b_get_type_internal (data, type, &io)) != B_OK)
+ return error;
+
+ return b_sync_cache (data, io, hash, what, len);
+}
+
+/**
+ * b_add_triple:
+ * @data: The pointer to the b_t struct.
+ * @triple: The triple. You should use b_triple_new() to create it.
+ * @returns: the error code.
+ *
+ * Adds a triple and the internal elements into the storage. This function
+ * doesn't insert a triple if it exists already in the storage.
+ **/
+b_error_t
+b_add_triple (b_t * data, b_triple_t * triple)
+{
+ b_tcache_t *status;
+ b_error_t error;
+
+ B_LOG2 ("b_add_triple: %p %p", data, triple);
+
+ if (!data || !triple)
+ return B_ERROR_DATA;
+
+ if (b_triple_check (triple) != B_OK)
+ return B_ERROR_DATA;
+
+ /* does it already exist? */
+ if ((error = b_get_triple_cache (data, triple, &status)) != B_OK)
+ return error;
+
+ if (status)
+ return B_OK;
+
+ /* Add to the cache list: */
+ return b_add_triple_cache (data, triple, 0, 0);
+}
+
+/* This function adds a triple to cache: */
+b_error_t
+b_add_triple_cache (b_t * data, b_triple_t * triple, b_uint64 tmap_pointer,
+ unsigned char tmap_index)
+{
+ b_tcache_t *cache;
+ b_error_t error;
+
+ B_LOG4 ("b_add_triple_cache: %p %p %d %d", data, triple, (int) tmap_pointer,
+ (int) tmap_index);
+
+ /* Allocation: */
+ if (!(cache = (b_tcache_t *) calloc (1, sizeof (b_tcache_t))))
+ return B_ERROR_MEMORY;
+
+#define B_ADD_TRIPLES_CACHE( str, len , type , where ) \
+ if ((error = b_add_type (data, type, str, len)) != B_OK) \
+ { \
+ b_tcache_destroy_single (NULL, NULL, cache); \
+ return error; \
+ } \
+ \
+ if ((error = b_get_type_cache (data, type, str, len, &cache->where)) \
+ != B_OK) \
+ { \
+ b_tcache_destroy_single (NULL, NULL, cache); \
+ return error; \
+ } \
+ \
+ if (!cache->where) \
+ { \
+ b_tcache_destroy_single (NULL, NULL, cache); \
+ return B_ERROR_INTERNAL; \
+ }
+
+ if (triple->subject_uri)
+ {
+ B_ADD_TRIPLES_CACHE (triple->subject_uri, triple->subject_uri_len,
+ B_TYPE_URI, subject_uri);
+ }
+ else if (triple->subject_bnode)
+ {
+ B_ADD_TRIPLES_CACHE (triple->subject_bnode, triple->subject_bnode_len,
+ B_TYPE_BNODE, subject_bnode);
+ }
+
+ B_ADD_TRIPLES_CACHE (triple->property, triple->property_len,
+ B_TYPE_PROPERTY, property);
+
+ if (triple->object_uri)
+ {
+ B_ADD_TRIPLES_CACHE (triple->object_uri, triple->object_uri_len,
+ B_TYPE_URI, object_uri);
+ }
+
+ else if (triple->object_bnode)
+ {
+ B_ADD_TRIPLES_CACHE (triple->object_bnode, triple->object_bnode_len,
+ B_TYPE_BNODE, object_bnode);
+ }
+
+ else if (triple->object_literal)
+ {
+ B_ADD_TRIPLES_CACHE (triple->object_literal, triple->object_literal_len,
+ B_TYPE_LITERAL, object_literal);
+ }
+
+ if (triple->context)
+ {
+ B_ADD_TRIPLES_CACHE (triple->context, triple->context_len,
+ B_TYPE_CONTEXT, context);
+ }
+
+ if (triple->datatype)
+ {
+ B_ADD_TRIPLES_CACHE (triple->datatype, triple->datatype_len,
+ B_TYPE_DATATYPE, datatype);
+ }
+
+ if (triple->lang)
+ {
+ B_ADD_TRIPLES_CACHE (triple->lang, triple->lang_len, B_TYPE_LITERAL,
+ lang);
+ }
+
+ cache->tmap_index = tmap_index;
+ cache->tmap_pointer = tmap_pointer;
+
+ if (data->triples_cache_items)
+ {
+ cache->next = data->triples_cache;
+ data->triples_cache->prev = cache;
+ }
+
+ data->triples_cache = cache;
+ data->triples_cache_items++;
+
+ if (!tmap_pointer)
+ {
+ /* Incrementing the instances for the elements: */
+ if (b_sync_instances (data, cache, 1))
+ return B_ERROR_INTERNAL;
+
+ data->triples_total++;
+ }
+
+ if (data->triples_cache_items > data->max_cache)
+ {
+ b_error_t error;
+ b_uint64 half = data->triples_cache_items / 2;
+ b_tcache_t *next;
+
+ /* Sync all the list because any item will active
+ * this routine so, 1 write is better then 1024. */
+ if ((error = b_sync_tcache (data)) != B_OK)
+ return error;
+
+ for (cache = data->triples_cache; cache && half;
+ cache = cache->next, half--);
+
+ /* I destroy half cache (totaly random - the random is always the better
+ * solution: */
+ while (cache)
+ {
+ next = cache->next;
+
+ b_tcache_destroy_single (&data->triples_cache,
+ &data->triples_cache_items, cache);
+ cache = next;
+ }
+ }
+
+ return B_OK;
+}
+
+/* EOF */
Added: incubator/triplesoup/donations/TRIPLES-2-libb/src/bcache.c
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/src/bcache.c?view=auto&rev=510255
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-2-libb/src/bcache.c (added)
+++ incubator/triplesoup/donations/TRIPLES-2-libb/src/bcache.c Wed Feb 21 13:56:43 2007
@@ -0,0 +1,157 @@
+/* (c) 2007 Satis Superque Merce B.V. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ */
+
+#include <b.h>
+
+/**
+ * b_set_max_cache:
+ * @data: The pointer to the b_t struct
+ * @max_cache: The new max_cache.
+ * @returns: the error code.
+ *
+ * Changes the MaxCache.
+ *
+ * If you want change the max cache value in any moment you must use this
+ * function.
+ */
+b_error_t
+b_set_max_cache (b_t * data, b_uint64 max_cache)
+{
+ b_error_t error;
+
+ B_LOG2 ("b_set_max_cache: %p %d", data, (int) max_cache);
+
+ if (!data)
+ return B_ERROR_DATA;
+
+ if (max_cache < B_MIN_CACHE_ITEMS)
+ max_cache = B_MIN_CACHE_ITEMS;
+
+ data->max_cache = max_cache;
+
+ if ((error = b_sync_tcache (data)) != B_OK)
+ return error;
+
+ while (data->triples_cache_items > data->max_cache)
+ b_tcache_destroy_single (&data->triples_cache, &data->triples_cache_items,
+ data->triples_cache);
+
+ return B_OK;
+}
+
+/**
+ * b_get_max_cache:
+ * @data: The pointer to the b_t struct
+ * @max_cache: A pointer to a b_uint64 variable.
+ * @returns: The error code;
+ *
+ * Returns the value of the MaXCache.
+ */
+b_error_t
+b_get_max_cache (b_t * data, b_uint64 * max_cache)
+{
+ B_LOG2 ("b_get_max_cache: %p %p", data, max_cache);
+
+ if (!data || !max_cache)
+ return B_ERROR_DATA;
+
+ *max_cache = data->max_cache;
+ return B_OK;
+}
+
+b_error_t
+b_cache_new (unsigned char *hash, unsigned char *what, b_uint64 len,
+ b_uint64 pointer, b_cache_t ** ret)
+{
+ b_cache_t *new;
+
+ if (!(new = calloc (1, sizeof (b_cache_t))))
+ return B_ERROR_MEMORY;
+
+ b_hash_copy (new->hash, hash);
+ new->what = b_string_alloc (what, len);
+ new->len = len;
+ new->pointer = pointer;
+
+ *ret = new;
+ return B_OK;
+}
+
+/* Destroy a cache list: */
+b_error_t
+b_cache_destroy (b_cache_t * cache)
+{
+ B_LOG1 ("b_cache_destroy: %p", cache);
+
+ if (!cache)
+ return B_ERROR_DATA;
+
+ if (cache->what)
+ free (cache->what);
+
+ free (cache);
+
+ return B_OK;
+}
+
+b_error_t
+b_cache_copy (b_cache_t * src, b_cache_t ** dst)
+{
+ b_cache_t *new;
+
+ B_LOG2 ("b_cache_copy: %p %p", src, dst);
+
+ if (!src)
+ return B_ERROR_DATA;
+
+ if (!(new = (b_cache_t *) calloc (1, sizeof (b_cache_t))))
+ return B_ERROR_MEMORY;
+
+ b_hash_copy (new->hash, src->hash);
+
+ if (src->what)
+ {
+ new->len = src->len;
+
+ if (!(new->what = b_string_alloc (src->what, src->len)))
+ {
+ free (new);
+ return B_ERROR_MEMORY;
+ }
+ }
+
+ new->pointer = src->pointer;
+
+ *dst = new;
+ return B_OK;
+}
+
+b_error_t
+b_cache_copy_easy (b_cache_t * src, b_cache_t ** dst)
+{
+ b_cache_t *new;
+
+ B_LOG2 ("b_cache_copy_easy: %p %p", src, dst);
+
+ if (!src)
+ return B_ERROR_DATA;
+
+ if (!(new = (b_cache_t *) calloc (1, sizeof (b_cache_t))))
+ return B_ERROR_MEMORY;
+
+ b_hash_copy (new->hash, src->hash);
+
+ new->len = src->len;
+ new->pointer = src->pointer;
+
+ *dst = new;
+ return B_OK;
+}
+
+/* EOF */
Added: incubator/triplesoup/donations/TRIPLES-2-libb/src/bcount.c
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/src/bcount.c?view=auto&rev=510255
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-2-libb/src/bcount.c (added)
+++ incubator/triplesoup/donations/TRIPLES-2-libb/src/bcount.c Wed Feb 21 13:56:43 2007
@@ -0,0 +1,128 @@
+/* (c) 2007 Satis Superque Merce B.V. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ */
+
+#include <b.h>
+
+/**
+ * b_count_type:
+ * @data: The pointer to a b_t struct
+ * @type: The type of elements you want count.
+ * @count: The pointer to a b_uint64. It'll contain the number of elements.
+ * @returns: The error code.
+ *
+ * counts the elements of a b_type_t into the storage.
+ **/
+b_error_t
+b_count_type (b_t * data, b_type_t type, b_uint64 * count)
+{
+ b_map_t map;
+ b_error_t error;
+ b_io_t *io;
+ b_uint64 pointer;
+
+ B_LOG3 ("b_count_type_cache: %p %d %p", data, type, count);
+
+ if (!data || !count)
+ return B_ERROR_DATA;
+
+ if ((error = b_get_type_internal (data, type, &io)) != B_OK)
+ return error;
+
+ *count = 0;
+ pointer = b_io_seek (io, sizeof (b_uint64), SEEK_SET);
+
+ while (1)
+ {
+ /* Hash and len is the second variable of the b_map_t struct: */
+ if (b_io_read (io, map.hash, sizeof (map.hash)) <= 0 ||
+ b_io_read (io, &map.len, sizeof (map.len)) <= 0)
+ break;
+
+ if (pointer != sizeof (b_uint64) && b_hash_empty (map.hash))
+ (*count)++;
+
+ pointer =
+ b_io_seek (io,
+ sizeof (map) - sizeof (map.hash) - sizeof (map.len) +
+ map.len, SEEK_CUR);
+
+ }
+
+ return B_OK;
+}
+
+/**
+ * b_count_triple:
+ * @data: The pointer to a b_t struct
+ * @count: The pointer to a b_uint64. It'll contain the number of triples.
+ * @returns: The error code.
+ *
+ * counts the triples into the Storage.
+ **/
+b_error_t
+b_count_triple (b_t * data, b_uint64 * count)
+{
+ B_LOG2 ("b_count_triple: %p %p", data, count);
+
+ if (!data || !count)
+ return B_ERROR_DATA;
+
+ if (data->triples_total == data->triples_cache_items)
+ {
+ *count = data->triples_cache_items;
+ return B_OK;
+ }
+
+ return b_count_triple_cache (data, count);
+}
+
+b_error_t
+b_count_triple_cache (b_t * data, b_uint64 * count)
+{
+ b_tcache_t *c;
+ b_tmap_t tmap;
+ b_error_t error;
+ b_uint64 pointer;
+ int i;
+
+ B_LOG2 ("b_count_triple_cache: %p %p", data, count);
+
+ if (!data || !count)
+ return B_ERROR_DATA;
+
+ (*count) = 0;
+ pointer = b_io_seek (data->triples_io, sizeof (b_uint64), SEEK_SET);
+
+ while (1)
+ {
+ if (b_io_read (data->triples_io, &tmap.map, sizeof (tmap.map)) <= 0)
+ break;
+
+ if ((error = b_tempty_check (data, &tmap, pointer, 0)) != B_OK)
+ return error;
+
+ for (i = 0; i < B_TMAP_NUMB; i++)
+ if (tmap.map[i])
+ (*count)++;
+
+ pointer =
+ b_io_seek (data->triples_io,
+ sizeof (tmap) - sizeof (tmap.map) +
+ B_TRIPLE_SIZE * B_TMAP_NUMB, SEEK_CUR);
+ }
+
+ /* No sync items: */
+ for (c = data->triples_cache; c; c = c->next)
+ if (!c->tmap_pointer)
+ (*count)++;
+
+ return B_OK;
+}
+
+/* EOF */
Added: incubator/triplesoup/donations/TRIPLES-2-libb/src/bdestroy.c
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/src/bdestroy.c?view=auto&rev=510255
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-2-libb/src/bdestroy.c (added)
+++ incubator/triplesoup/donations/TRIPLES-2-libb/src/bdestroy.c Wed Feb 21 13:56:43 2007
@@ -0,0 +1,68 @@
+/* (c) 2007 Satis Superque Merce B.V. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ */
+
+#include <b.h>
+
+/**
+ * b_destroy:
+ * @data: The pointer to the b_t you want destroy.
+ * @returns: The error code.
+ *
+ * Destroies a b_t data struct and closes the storage. This must be the
+ * last operation with that data.
+ **/
+b_error_t
+b_destroy (b_t * data)
+{
+ B_LOG1 ("b_destroy: %p", data);
+
+ if (!data)
+ return B_ERROR_DATA;
+
+ /* Sync datas: */
+ b_sync (data);
+
+ /* Remove the cache: */
+ if (data->triples_cache)
+ b_tcache_destroy (&data->triples_cache, &data->triples_cache_items);
+
+ if (data->hashes_cache)
+ b_hash_destroy (&data->hashes_cache, &data->hashes_cache_items);
+
+ if (data->triples_empty)
+ b_tempty_destroy (&data->triples_empty);
+
+ /* Close the IO: */
+ if (data->uris_io)
+ b_io_destroy (data->uris_io);
+
+ if (data->properties_io)
+ b_io_destroy (data->properties_io);
+
+ if (data->literals_io)
+ b_io_destroy (data->literals_io);
+
+ if (data->bnodes_io)
+ b_io_destroy (data->bnodes_io);
+
+ if (data->contexts_io)
+ b_io_destroy (data->contexts_io);
+
+ if (data->datatypes_io)
+ b_io_destroy (data->datatypes_io);
+
+ if (data->triples_io)
+ b_io_destroy (data->triples_io);
+
+ /* Free memory: */
+ free (data);
+ return B_OK;
+}
+
+/* EOF */
Added: incubator/triplesoup/donations/TRIPLES-2-libb/src/berror.c
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/src/berror.c?view=auto&rev=510255
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-2-libb/src/berror.c (added)
+++ incubator/triplesoup/donations/TRIPLES-2-libb/src/berror.c Wed Feb 21 13:56:43 2007
@@ -0,0 +1,51 @@
+/* (c) 2007 Satis Superque Merce B.V. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ */
+
+#include <b.h>
+
+/**
+ * b_strerror:
+ * @error: The error code
+ * @returns: a string with the error code in human readble format.
+ *
+ * Returns the error code in a human readble format. This return string
+ * doesn't not freed!!
+ **/
+char *
+b_strerror (b_error_t error)
+{
+ B_LOG1 ("b_strerror: %d", error);
+
+ switch (error)
+ {
+ case B_OK:
+ return "Success";
+
+ case B_ERROR_MEMORY:
+ return "Allocation error";
+
+ case B_ERROR_POSIX:
+#ifndef WIN32
+ return strerror (errno);
+#else
+ return "System error";
+#endif
+
+ case B_ERROR_DATA:
+ return "Read the manual";
+
+ case B_ERROR_INTERNAL:
+ return "Internal error";
+
+ default:
+ return "?!?";
+ }
+}
+
+/* EOF */
Added: incubator/triplesoup/donations/TRIPLES-2-libb/src/bget.c
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/src/bget.c?view=auto&rev=510255
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-2-libb/src/bget.c (added)
+++ incubator/triplesoup/donations/TRIPLES-2-libb/src/bget.c Wed Feb 21 13:56:43 2007
@@ -0,0 +1,570 @@
+/* (c) 2007 Satis Superque Merce B.V. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ */
+
+#include <b.h>
+
+static int b_triple_compare (b_tcache_t * a, b_tcache_t * b);
+
+/**
+ * b_get_type:
+ * @data: The pointer to a b_t data struct.
+ * @type: The type of the element you are looking for.
+ * @what: The data of this element as string.
+ * @len: The len of the string (if 0, this function uses strlen on what).
+ * @exist: A pointer to a char. It will be 1 if the data exists or 0.
+ * @returns: The error code.
+ *
+ * Searchs a data into the storage.
+ */
+b_error_t
+b_get_type (b_t * data, b_type_t type, unsigned char *what, b_uint64 len,
+ char *exist)
+{
+ b_cache_t *cache;
+ b_error_t error;
+
+ B_LOG5 ("b_get_type: %p %d %p %d %p", data, type, what, (int) len, exit);
+
+ if ((error = b_get_type_cache (data, type, what, len, &cache)) != B_OK)
+ {
+ b_cache_destroy (cache);
+ return error;
+ }
+
+ *exist = cache ? 1 : 0;
+ b_cache_destroy (cache);
+ return B_OK;
+}
+
+/* This function gets a item from the list: */
+b_error_t
+b_get_type_cache (b_t * data, b_type_t type, unsigned char *what,
+ b_uint64 len, b_cache_t ** exist)
+{
+ unsigned char hash[B_HASH_SIZE];
+
+ B_LOG5 ("b_get_type_cache: %p %d %p %d %p", data, type, what, (int) len,
+ exit);
+
+ if (!data || !what || !exist)
+ return B_ERROR_DATA;
+
+ len = len > 0 ? len : strlen ((char *) what);
+ b_hash_new (data, what, len, hash);
+
+ return b_get_type_cache_hash (data, type, hash, what, len, exist);
+}
+
+/* This function gets a item from the list: */
+b_error_t
+b_get_type_cache_hash (b_t * data, b_type_t type, unsigned char *hash,
+ unsigned char *what, b_uint64 len, b_cache_t ** exist)
+{
+ b_uint64 pointer;
+ b_error_t error;
+ b_io_t *io;
+ b_map_t map;
+ unsigned char *iwhat = NULL;
+ int cmp;
+
+ B_LOG6 ("b_get_type_cache_hash: %p %d %p %p %d %p", data, type, hash, what,
+ (int) len, exit);
+
+ if (!data || !hash || !exist)
+ return B_ERROR_DATA;
+
+ if ((error = b_get_type_internal (data, type, &io)) != B_OK)
+ return error;
+
+ *exist = NULL;
+
+ pointer = b_io_seek (io, sizeof (b_uint64), SEEK_SET);
+
+ /* Check in the file: */
+ while (1)
+ {
+ /* hash: */
+ if (b_io_read (io, &map, sizeof (map)) <= 0)
+ return B_OK;
+
+ cmp = b_hash_compare (hash, map.hash);
+
+ /* Too small? On the left */
+ if (cmp < 0 || (cmp == 0 && pointer == sizeof (b_uint64)))
+ {
+ if (map.left)
+ {
+ pointer = b_io_seek (io, map.left, SEEK_SET);
+ continue;
+ }
+ else
+ break;
+ }
+
+ /* Too big? On the right */
+ else if (cmp > 0)
+ {
+ if (map.right)
+ {
+ pointer = b_io_seek (io, map.right, SEEK_SET);
+ continue;
+ }
+ else
+ break;
+ }
+
+ /* Found! */
+ else
+ {
+ if (!what)
+ {
+ if (!
+ (iwhat =
+ malloc (sizeof (unsigned char) * (size_t) (map.len + 1))))
+ return B_ERROR_MEMORY;
+
+ if (map.len && b_io_read (io, iwhat, map.len) <= 0)
+ return B_ERROR_INTERNAL;
+
+ iwhat[map.len] = 0;
+ }
+
+ if ((error =
+ b_cache_new (hash, what ? what : iwhat, map.len, pointer,
+ exist)) != B_OK)
+ {
+ if (!what)
+ free (iwhat);
+ return error;
+ }
+
+ if (!iwhat)
+ free (iwhat);
+ return B_OK;
+ }
+ }
+
+ return B_OK;
+}
+
+/* This function gets a item from the list: */
+b_error_t
+b_get_type_pointer (b_t * data, b_type_t type, b_uint64 pointer,
+ b_cache_t ** exist)
+{
+ b_error_t error;
+ b_io_t *io;
+ b_map_t map;
+ unsigned char *iwhat;
+
+ B_LOG4 ("b_get_type_pointer: %p %d %d %p", data, type, (int) pointer, exit);
+
+ if (!data || !pointer || !exist)
+ return B_ERROR_DATA;
+
+ if ((error = b_get_type_internal (data, type, &io)) != B_OK)
+ return error;
+
+ *exist = NULL;
+
+ pointer = b_io_seek (io, pointer, SEEK_SET);
+
+ /* hash: */
+ if (b_io_read (io, &map, sizeof (map)) <= 0)
+ return B_OK;
+
+ if (!(iwhat = malloc (sizeof (unsigned char) * (size_t) (map.len + 1))))
+ return B_ERROR_MEMORY;
+
+ if (map.len && b_io_read (io, iwhat, map.len) <= 0)
+ return B_ERROR_INTERNAL;
+
+ iwhat[map.len] = 0;
+
+ if ((error =
+ b_cache_new (map.hash, iwhat, map.len, pointer, exist)) != B_OK)
+ {
+ free (iwhat);
+ return error;
+ }
+
+ free (iwhat);
+ return B_OK;
+}
+
+b_error_t
+b_get_type_internal (b_t * data, b_type_t type, b_io_t ** io)
+{
+ B_LOG3 ("b_get_type_internal: %p %d %p", data, type, io);
+
+ if (!data || !io)
+ return B_ERROR_DATA;
+
+ switch (type)
+ {
+ case B_TYPE_URI:
+ *io = data->uris_io;
+ break;
+
+ case B_TYPE_PROPERTY:
+ *io = data->properties_io;
+ break;
+
+ case B_TYPE_LITERAL:
+ *io = data->literals_io;
+ break;
+
+ case B_TYPE_BNODE:
+ *io = data->bnodes_io;
+ break;
+
+ case B_TYPE_CONTEXT:
+ *io = data->contexts_io;
+ break;
+
+ case B_TYPE_DATATYPE:
+ *io = data->datatypes_io;
+ break;
+
+ default:
+ return B_ERROR_DATA;
+ }
+
+ return B_OK;
+}
+
+/**
+ * b_get_triple:
+ * @data: The pointer to a b_t data struct.
+ * @triple: The triple you are looking for.
+ * @exist: A pointer to a char. It will be 1 if the data exists or 0.
+ * @returns: The error code.
+ *
+ * Searchs a triple into the storage.
+ */
+b_error_t
+b_get_triple (b_t * data, b_triple_t * triple, char *exist)
+{
+ b_tcache_t *cache;
+ b_error_t error;
+
+ B_LOG3 ("b_get_triple: %p %p %p", data, triple, exist);
+
+ if ((error = b_get_triple_cache (data, triple, &cache)) != B_OK)
+ return error;
+
+ *exist = cache ? 1 : 0;
+ return B_OK;
+}
+
+b_error_t
+b_get_triple_cache (b_t * data, b_triple_t * triple, b_tcache_t ** exist)
+{
+ b_tcache_t *list;
+ b_tcache_t *cache;
+ b_error_t error;
+
+ b_uint64 pointer;
+ b_tmap_t tmap;
+ b_tmap_item_t tmap_item;
+
+ int i, j;
+ char tmap_results[B_TMAP_NUMB];
+
+ B_LOG3 ("b_get_triple_cache: %p %p %p", data, triple, exist);
+
+ if (!data)
+ return B_ERROR_DATA;
+
+ if (b_triple_check (triple) != B_OK)
+ return B_ERROR_DATA;
+
+ if (!(cache = (b_tcache_t *) calloc (1, sizeof (b_tcache_t))))
+ return B_ERROR_MEMORY;
+
+#define B_GET_FIND( str , len , type , where ) \
+ if (where) \
+ { \
+ b_cache_destroy (where); \
+ where = NULL; \
+ } \
+ \
+ if ((error = b_get_type_cache (data, type, str, len, &where)) != B_OK) \
+ { \
+ b_tcache_destroy_single (NULL, NULL, cache); \
+ return error; \
+ } \
+ \
+ if (!where) \
+ { \
+ b_tcache_destroy_single (NULL, NULL, cache); \
+ *exist=0; \
+ return B_OK; \
+ }
+
+ if (triple->subject_uri)
+ {
+ B_GET_FIND (triple->subject_uri, triple->subject_uri_len, B_TYPE_URI,
+ cache->subject_uri);
+ }
+ else
+ {
+ B_GET_FIND (triple->subject_bnode, triple->subject_bnode_len,
+ B_TYPE_BNODE, cache->subject_bnode);
+ }
+
+ B_GET_FIND (triple->property, triple->property_len, B_TYPE_PROPERTY,
+ cache->property);
+
+ if (triple->object_uri)
+ {
+ B_GET_FIND (triple->object_uri, triple->object_uri_len, B_TYPE_URI,
+ cache->object_uri);
+ }
+
+ else if (triple->object_bnode)
+ {
+ B_GET_FIND (triple->object_bnode, triple->object_bnode_len,
+ B_TYPE_BNODE, cache->object_bnode);
+ }
+
+ else if (triple->object_literal)
+ {
+ B_GET_FIND (triple->object_literal, triple->object_literal_len,
+ B_TYPE_LITERAL, cache->object_literal);
+ }
+
+ if (triple->context)
+ {
+ B_GET_FIND (triple->context, triple->context_len, B_TYPE_CONTEXT,
+ cache->context);
+ }
+
+ if (triple->datatype)
+ {
+ B_GET_FIND (triple->datatype, triple->datatype_len, B_TYPE_DATATYPE,
+ cache->datatype);
+ }
+
+ if (triple->lang)
+ {
+ B_GET_FIND (triple->lang, triple->lang_len, B_TYPE_LITERAL,
+ cache->lang);
+ }
+
+ /* Check from the cache list: */
+ for (list = data->triples_cache; list; list = list->next)
+ {
+ if (!b_triple_compare (list, cache))
+ {
+ *exist = list;
+ b_tcache_destroy_single (NULL, NULL, cache);
+ return B_OK;
+ }
+ }
+
+ *exist = NULL;
+
+ if (data->triples_total == data->triples_cache_items)
+ {
+ b_tcache_destroy_single (NULL, NULL, cache);
+ return B_OK;
+ }
+
+ pointer = b_io_seek (data->triples_io, sizeof (b_uint64), SEEK_SET);
+
+ /* Check in the file: */
+ while (1)
+ {
+ if (b_io_read (data->triples_io, &tmap, sizeof (tmap)) <= 0)
+ {
+ b_tcache_destroy_single (NULL, NULL, cache);
+ return B_OK;
+ }
+
+ if ((error = b_tempty_check (data, &tmap, pointer, 0)) != B_OK)
+ {
+ b_tcache_destroy_single (NULL, NULL, cache);
+ return error;
+ }
+
+ memset (&tmap_results, 0, sizeof (tmap_results));
+
+ /* Disactive no compatible results: */
+ for (i = 0; i < B_TMAP_NUMB; i++)
+ {
+ if (!tmap.map[i])
+ tmap_results[i] = 1;
+ else
+ {
+ if (cache->subject_uri
+ && B_TMAP_VALUE (tmap.subjects_uri[i]) ==
+ B_TMAP_VALUE_EMPTY)
+ tmap_results[B_TMAP_DATA (tmap.subjects_uri[i])] = 1;
+
+ if (cache->subject_bnode
+ && B_TMAP_VALUE (tmap.subjects_bnode[i]) ==
+ B_TMAP_VALUE_EMPTY)
+ tmap_results[B_TMAP_DATA (tmap.subjects_bnode[i])] = 1;
+
+ if (cache->object_uri
+ && B_TMAP_VALUE (tmap.objects_uri[i]) == B_TMAP_VALUE_EMPTY)
+ tmap_results[B_TMAP_DATA (tmap.objects_uri[i])] = 1;
+
+ if (cache->object_bnode
+ && B_TMAP_VALUE (tmap.objects_bnode[i]) ==
+ B_TMAP_VALUE_EMPTY)
+ tmap_results[B_TMAP_DATA (tmap.objects_bnode[i])] = 1;
+
+ if (cache->object_literal
+ && B_TMAP_VALUE (tmap.objects_literal[i]) ==
+ B_TMAP_VALUE_EMPTY)
+ tmap_results[B_TMAP_DATA (tmap.objects_literal[i])] = 1;
+
+ if (cache->context
+ && B_TMAP_VALUE (tmap.contexts[i]) == B_TMAP_VALUE_EMPTY)
+ tmap_results[B_TMAP_DATA (tmap.contexts[i])] = 1;
+
+ if (cache->datatype
+ && B_TMAP_VALUE (tmap.datatypes[i]) == B_TMAP_VALUE_EMPTY)
+ tmap_results[B_TMAP_DATA (tmap.datatypes[i])] = 1;
+
+ if (cache->lang
+ && B_TMAP_VALUE (tmap.langs[i]) == B_TMAP_VALUE_EMPTY)
+ tmap_results[B_TMAP_DATA (tmap.langs[i])] = 1;
+ }
+ }
+
+#define B_GET_FILE( x , y , n ) \
+ if (tmap_results[i]) \
+ continue; \
+ \
+ if (cache->x) \
+ { \
+ b_io_seek (data->triples_io, pointer + sizeof (b_tmap_t) + i * \
+ B_TRIPLE_SIZE + sizeof(b_tmap_item_t) * n, SEEK_SET); \
+ \
+ if (b_io_read (data->triples_io, &tmap_item, sizeof (b_tmap_item_t)) \
+ <= 0) \
+ { \
+ b_tcache_destroy_single(NULL, NULL, cache); \
+ return B_ERROR_INTERNAL; \
+ } \
+ \
+ switch (b_hash_compare (tmap_item.hash, cache->x->hash)) \
+ { \
+ case -1: \
+ for (j = 0; j < B_TMAP_NUMB; j++) \
+ { \
+ if (B_TMAP_VALUE (tmap.y[j]) != B_TMAP_VALUE_EMPTY) \
+ { \
+ tmap_results[B_TMAP_DATA(tmap.y[j])] = 1; \
+ if (B_TMAP_DATA(tmap.y[j]) == i) \
+ break; \
+ } \
+ } \
+ break; \
+ \
+ case 1: \
+ for (j = B_TMAP_NUMB-1; j >= 0; j--) \
+ { \
+ if (B_TMAP_VALUE (tmap.y[j]) != B_TMAP_VALUE_EMPTY) \
+ { \
+ tmap_results[B_TMAP_DATA(tmap.y[j])] = 1; \
+ if (B_TMAP_DATA(tmap.y[j]) == i) \
+ break; \
+ } \
+ } \
+ break; \
+ \
+ case 0: \
+ default: \
+ break; \
+ } \
+ }
+
+ for (i = 0; i < B_TMAP_NUMB; i++)
+ {
+ B_GET_FILE (subject_uri, subjects_uri, 0);
+ B_GET_FILE (subject_bnode, subjects_bnode, 1);
+ B_GET_FILE (property, properties, 2);
+ B_GET_FILE (object_uri, objects_uri, 3);
+ B_GET_FILE (object_bnode, objects_bnode, 4);
+ B_GET_FILE (object_literal, objects_literal, 5);
+ B_GET_FILE (context, contexts, 6);
+ B_GET_FILE (datatype, datatypes, 7);
+ B_GET_FILE (lang, langs, 8);
+
+ if (tmap_results[i])
+ continue;
+
+ if ((error = b_add_triple_cache (data, triple, pointer, i)) != B_OK)
+ {
+ b_tcache_destroy_single (NULL, NULL, cache);
+ return error;
+ }
+
+ /* Re-exec because the previous function inserts in the cache
+ * list the element founded */
+ b_tcache_destroy_single (NULL, NULL, cache);
+ return b_get_triple_cache (data, triple, exist);
+ }
+
+ pointer =
+ b_io_seek (data->triples_io,
+ pointer + sizeof (b_tmap_t) + B_TRIPLE_SIZE * B_TMAP_NUMB,
+ SEEK_SET);
+ }
+
+ b_tcache_destroy_single (NULL, NULL, cache);
+ return B_OK;
+}
+
+static int
+b_triple_compare (b_tcache_t * a, b_tcache_t * b)
+{
+ int c;
+
+ B_LOG2 ("b_triple_compare: %p %p", a, b);
+
+#define B_COMPARE_SINGLE( x ) \
+ c = 0; \
+ if (a->x) \
+ c++; \
+ if (b->x) \
+ c++; \
+ \
+ switch (c) \
+ { \
+ case 0: \
+ break; \
+ \
+ case 1: \
+ return 1; \
+ \
+ default: \
+ if (b_hash_compare(a->x->hash, b->x->hash)) \
+ return 1; \
+ break; \
+ }
+
+ B_COMPARE_SINGLE (subject_uri);
+ B_COMPARE_SINGLE (subject_bnode);
+ B_COMPARE_SINGLE (property);
+ B_COMPARE_SINGLE (object_uri);
+ B_COMPARE_SINGLE (object_bnode);
+ B_COMPARE_SINGLE (object_literal);
+ B_COMPARE_SINGLE (context);
+ B_COMPARE_SINGLE (datatype);
+ B_COMPARE_SINGLE (lang);
+
+ return 0;
+}
+
+/* EOF */