RDFStore

 view release on metacpan or  search on metacpan

rdfstore_kernel.c  view on Meta::CPAN

#endif
		return -1;
		};

	/* index special literal stuff */
	if (statement->object->type == 1) {
		if (	(me->freetext) &&
		    	(statement->object->value.literal.string != NULL) &&
			(statement->object->value.literal.string_len > 0) ) {
			utf8_casefolded_buff = (unsigned char *)RDFSTORE_MALLOC(statement->object->value.literal.string_len * sizeof(unsigned char) * (RDFSTORE_UTF8_MAXLEN_FOLD + 1));	/* what about the ending '\0' here ?? */
			if (utf8_casefolded_buff == NULL) {
				perror("rdfstore_insert");
				fprintf(stderr,"Cannot compute case-folded string out of input literal for store '%s'\n", (me->name != NULL) ? me->name : "(in-memory)");
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			if (rdfstore_utf8_string_to_utf8_foldedcase(statement->object->value.literal.string_len, statement->object->value.literal.string, &utf8_size, utf8_casefolded_buff)) {
				perror("rdfstore_insert");
				fprintf(stderr,"Cannot compute case-folded string out of input literal for store '%s'\n", (me->name != NULL) ? me->name : "(in-memory)");
				RDFSTORE_FREE(utf8_casefolded_buff);
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};

			/* we do not even try to avoid duplicates for the moment */
			for (	word = strtok(utf8_casefolded_buff, sep);
			     	word;
			     	word = strtok(NULL, sep) ) {
				int jj=0;
				int kk=0;

				key.data = word;
				key.size = strlen(word);

				/*
				 * 
				 * bzero(me->bits_encode,sizeof(me->bits_encode
				 * ));
				 * bzero(me->bits_decode,sizeof(me->bits_decod
				 * e));
				 */
				err = rdfstore_flat_store_fetch_compressed(me->windex, me->func_decode, key, &outsize, me->bits_decode);
				if (err != 0) {
					if (err != FLAT_STORE_E_NOTFOUND) {
						RDFSTORE_FREE(utf8_casefolded_buff);
						perror("rdfstore_insert");
						fprintf(stderr,"Could not fetch windex of word '%s' for store '%s': %s\n", word, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->windex));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
						rdfstore_iterator_close(reindex);
#endif
						return -1;
					} else {
						outsize = 0;
						};
					};

				rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 1, sizeof(me->bits_decode));

				if (outsize) {
					err = rdfstore_flat_store_store_compressed(me->windex, me->func_encode, key, outsize, me->bits_decode,me->bits_encode );
					if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
						fprintf(stderr,"Stored %d bytes for '%s' in windex for store '%s'\n", outsize, (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)");
#endif
					} else {
						if (err != FLAT_STORE_E_KEYEXIST) {
							RDFSTORE_FREE(utf8_casefolded_buff);
							perror("rdfstore_insert");
							fprintf(stderr,"Could not store '%d' bytes for word '%s' in windex for store '%s': %s\n", (int)data.size, word, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->windex));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
							rdfstore_iterator_close(reindex);
#endif
							return -1;
							};
						};

#ifdef RDFSTORE_DEBUG
					{
						int             i;
						if ((rdfstore_flat_store_fetch(me->windex, key, &data)) == 0) {
							me->func_decode(data.size, data.data, &outsize, me->bits_decode);
							RDFSTORE_FREE(data.data);
						};
						printf("ADDED (%d) windex for case-folded word '%s' -->'", st_id, word);
						for(i=0;i<8*outsize;i++) {
							printf("Rec %d %c\n", i, (me->bits_decode[i>>3] & (1<<(i&7))) ? '1':'0');
							};
						printf("'\n");
					}
#endif

					};
		
				/* 
				stemming code for ISO-Latin languiages (left-to-right) and shouild be UTF-8 aware
				ie. word = "stemming" -- do index --> "s", "st", "ste", ....
				*/
#if RDFSTORE_WORD_STEMMING > 0

				if(	( rdfstore_xsd_deserialize_integer( word, &thelval ) ) ||
					( rdfstore_xsd_deserialize_double( word, &thedval )  ) ||
					( rdfstore_xsd_deserialize_dateTime(	word,
										&thedateval_tm ) ) ||
					( rdfstore_xsd_deserialize_date(	word,
										&thedateval_tm ) ) || /* dates are skipped, even if rdf:datatype is not set */
					(strlen(word)<=1) )
					continue;

				/* for efficency we should check if the given partial stem has been already indexed for the same word!!! */
				jj=1;
				while (	( jj < strlen(word) ) &&
					( kk < RDFSTORE_WORD_STEMMING ) ) {
					char stem[MIN((RDFSTORE_WORD_STEMMING*RDFSTORE_UTF8_MAXLEN_FOLD),strlen(word))+1];

					bzero(stem,MIN((RDFSTORE_WORD_STEMMING*RDFSTORE_UTF8_MAXLEN_FOLD),strlen(word))+1);

					/* look for next utf8 char to add to stemming string */
					utf8_size=0;
					while (	( jj < strlen(word) ) &&
                                        	(!( rdfstore_utf8_is_utf8( word+jj, &utf8_size ) )) ) {
						jj++;
						};

					if (jj>strlen(word)) {
						strncpy(stem, word, jj-1);
					} else {
						strncpy(stem, word, jj);
						};

					key.data = stem;
					key.size = strlen(stem);

					err = rdfstore_flat_store_fetch(me->windex, key, &data);
					if (err != 0) {
						if (err != FLAT_STORE_E_NOTFOUND) {
							RDFSTORE_FREE(utf8_casefolded_buff);
							perror("rdfstore_insert");
							fprintf(stderr,"Could not fetch windex of stemming '%s' of word '%s' for store '%s': %s\n", stem, word, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->windex));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
							rdfstore_iterator_close(reindex);
#endif
							return -1;
						} else {
							outsize = 0;
							};
					} else {
						me->func_decode(data.size, data.data, &outsize, me->bits_decode);	/* perhaps the
															 * compression for
															 * single bits could be
															 * different */
						RDFSTORE_FREE(data.data);
						};
					rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 1, sizeof(me->bits_decode));

					me->func_encode(outsize, me->bits_decode, &outsize, me->bits_encode);
					if (outsize) {
						data.data = me->bits_encode;
						data.size = outsize;
						err = rdfstore_flat_store_store(me->windex, key, data);
						if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
							fprintf(stderr,"Stored %d bytes for '%s' in windex for store '%s'\n", outsize, (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)");
#endif
						} else {
							if (err != FLAT_STORE_E_KEYEXIST) {
								RDFSTORE_FREE(utf8_casefolded_buff);
								perror("rdfstore_insert");
								fprintf(stderr,"Could not store '%d' bytes for stemming '%s' in windex for store '%s': %s\n", (int)data.size, stem, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->windex));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
								rdfstore_iterator_close(reindex);
#endif
								return -1;
								};
							};

#ifdef RDFSTORE_DEBUG
					{
						int             i;
						if ((rdfstore_flat_store_fetch(me->windex, key, &data)) == 0) {
							me->func_decode(data.size, data.data, &outsize, me->bits_decode);
							RDFSTORE_FREE(data.data);
						};
						printf("ADDED (%d) windex for case-folded stemming '%s' of word '%s' -->'", st_id, stem, word);
						for (i = 0; i < outsize; i++) {
							printf("%02X", me->bits_decode[i]);
						};
						printf("'\n");
					}
#endif

						};
					jj++;
					kk++;
					};
#endif
				};
			RDFSTORE_FREE(utf8_casefolded_buff);
			};

		/* languages table */
		if (	(statement->object->value.literal.lang != NULL) &&
			(strlen(statement->object->value.literal.lang) > 0) ) {
			utf8_casefolded_buff = (unsigned char *)RDFSTORE_MALLOC(strlen(statement->object->value.literal.lang) * sizeof(unsigned char) * (RDFSTORE_UTF8_MAXLEN_FOLD + 1));
			if (utf8_casefolded_buff == NULL) {
				perror("rdfstore_insert");
				fprintf(stderr,"Cannot compute case-folded string for literal language code '%s' for store '%s'\n", statement->object->value.literal.lang, (me->name != NULL) ? me->name : "(in-memory)");
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			if (rdfstore_utf8_string_to_utf8_foldedcase(strlen(statement->object->value.literal.lang), statement->object->value.literal.lang, &utf8_size, utf8_casefolded_buff)) {
				perror("rdfstore_insert");
				fprintf(stderr,"Cannot compute case-folded string for literal language code '%s' for store '%s'\n", statement->object->value.literal.lang, (me->name != NULL) ? me->name : "(in-memory)");
				RDFSTORE_FREE(utf8_casefolded_buff);
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};

			key.data = utf8_casefolded_buff;
			key.size = utf8_size;

			err = rdfstore_flat_store_fetch(me->languages, key, &data);
			if (err != 0) {
				if (err != FLAT_STORE_E_NOTFOUND) {
					RDFSTORE_FREE(utf8_casefolded_buff);
					perror("rdfstore_insert");
					fprintf(stderr,"Could not fetch language '%s' of literal '%s' for store '%s': %s\n", statement->object->value.literal.lang, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me-...
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
					rdfstore_iterator_close(reindex);
#endif
					return -1;
				} else {
					outsize = 0;
					};
			} else {
				me->func_decode(data.size, data.data, &outsize, me->bits_decode);
				RDFSTORE_FREE(data.data);
				};
			rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 1, sizeof(me->bits_decode));

			me->func_encode(outsize, me->bits_decode, &outsize, me->bits_encode);
			if (outsize) {
				data.data = me->bits_encode;
				data.size = outsize;
				err = rdfstore_flat_store_store(me->languages, key, data);
				if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
					fprintf(stderr,"Stored %d bytes for '%s' in languages for store '%s'\n", outsize, (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)");
#endif
				} else {
					if (err != FLAT_STORE_E_KEYEXIST) {
						RDFSTORE_FREE(utf8_casefolded_buff);
						perror("rdfstore_insert");
						fprintf(stderr,"Could not store '%d' bytes for language '%s' in languages for store '%s': %s\n", (int)data.size, statement->object->value.literal.lang, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->languages))...
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
						rdfstore_iterator_close(reindex);
#endif
						return -1;
						};
					};

#ifdef RDFSTORE_DEBUG
				{
				int             i;
				if ((rdfstore_flat_store_fetch(me->languages, key, &data)) == 0) {
					me->func_decode(data.size, data.data, &outsize, me->bits_decode);
					RDFSTORE_FREE(data.data);
				};
				printf("ADDED (%d) language '%s' of literal '%s' -->'", st_id, statement->object->value.literal.lang, statement->object->value.literal.string);
				for (i = 0; i < outsize; i++) {
					printf("%02X", me->bits_decode[i]);
					};
				printf("'\n");
				}
#endif

				};

			RDFSTORE_FREE(utf8_casefolded_buff);
			};

		/* datatypes table */
		if (	(statement->object->value.literal.dataType != NULL) &&
			(strlen(statement->object->value.literal.dataType) > 0) ) {
			key.data = statement->object->value.literal.dataType;
			key.size = strlen(statement->object->value.literal.dataType);

			err = rdfstore_flat_store_fetch(me->datatypes, key, &data);
			if (err != 0) {
				if (err != FLAT_STORE_E_NOTFOUND) {
					perror("rdfstore_insert");
					fprintf(stderr,"Could not fetch datatype '%s' of literal '%s' for store '%s': %s\n", statement->object->value.literal.dataType, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error...
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
					rdfstore_iterator_close(reindex);
#endif
					return -1;
				} else {
					outsize = 0;
					};
			} else {
				me->func_decode(data.size, data.data, &outsize, me->bits_decode);
				RDFSTORE_FREE(data.data);
				};
			rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 1, sizeof(me->bits_decode));

			me->func_encode(outsize, me->bits_decode, &outsize, me->bits_encode);
			if (outsize) {
				data.data = me->bits_encode;
				data.size = outsize;
				err = rdfstore_flat_store_store(me->datatypes, key, data);
				if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
					fprintf(stderr,"Stored %d bytes for '%s' in datatypes for store '%s'\n", outsize, (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)");
#endif
				} else {
					if (err != FLAT_STORE_E_KEYEXIST) {
						perror("rdfstore_insert");
						fprintf(stderr,"Could not store '%d' bytes for datatype '%s' in datatypes for store '%s': %s\n", (int)data.size, statement->object->value.literal.dataType, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->datatyp...
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
						rdfstore_iterator_close(reindex);
#endif
						return -1;
						};
					};

#ifdef RDFSTORE_DEBUG
				{
				int             i;
				if ((rdfstore_flat_store_fetch(me->datatypes, key, &data)) == 0) {
					me->func_decode(data.size, data.data, &outsize, me->bits_decode);
					RDFSTORE_FREE(data.data);
				};
				printf("ADDED (%d) datatype '%s' of literal '%s' -->'", st_id, statement->object->value.literal.dataType, statement->object->value.literal.string);
				for (i = 0; i < outsize; i++) {
					printf("%02X", me->bits_decode[i]);
					};
				printf("'\n");
				}
#endif

				};

			/* date type indexing only if rdf:datatype is set accordingly to xsd:date or xsd:dateTime */
			if(	(strcmp(statement->object->value.literal.dataType,RDFSTORE_MS_XSD_DATE)==0) ||
				(strcmp(statement->object->value.literal.dataType,RDFSTORE_MS_XSD_DATETIME)==0) ) {
				if (	( rdfstore_xsd_deserialize_dateTime(	statement->object->value.literal.string,
										&thedateval_tm ) ) ||
					( rdfstore_xsd_deserialize_date(	statement->object->value.literal.string,
										&thedateval_tm ) ) ) {

					rdfstore_xsd_serialize_dateTime( thedateval_tm, thedateval ); /* we index xsd:dataTime version anyway */

					key.data = thedateval;
					key.size = strlen(thedateval)+1;

#ifdef RDFSTORE_DEBUG
fprintf(stderr, "INDEX DATE '%s' for LITERAL '%s' \n",thedateval, statement->object->value.literal.string);
#endif

					err = rdfstore_flat_store_fetch(me->xsd_date, key, &data);
					if (err != 0) {
						if (err != FLAT_STORE_E_NOTFOUND) {
							perror("rdfstore_insert");
							fprintf(stderr,"Could not fetch from date table value '%s' for store '%s': %s\n", statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->xsd_date));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
							rdfstore_iterator_close(reindex);
#endif
							return -1;
						} else {
							outsize = 0;
							};
					} else {
						me->func_decode(data.size, data.data, &outsize, me->bits_decode);
						RDFSTORE_FREE(data.data);
						};
					rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 1, sizeof(me->bits_decode));

					me->func_encode(outsize, me->bits_decode, &outsize, me->bits_encode);
					if (outsize) {
						data.data = me->bits_encode;
						data.size = outsize;
						err = rdfstore_flat_store_store(me->xsd_date, key, data);
						if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
							fprintf(stderr,"Stored %d bytes for date '%s' in literal '%s' in integer table for store '%s'\n", outsize, thedateval, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)");
#endif
						} else {
							if (err != FLAT_STORE_E_KEYEXIST) {
								perror("rdfstore_insert");
								fprintf(stderr,"Could not store '%d' bytes for date '%s' in literal '%s' in date table for store '%s': %s\n", (int)data.size, thedateval, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_st...
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
								rdfstore_iterator_close(reindex);
#endif
								return -1;
								};
							};

#ifdef RDFSTORE_DEBUG
						{
						int             i;
						if ((rdfstore_flat_store_fetch(me->xsd_date, key, &data)) == 0) {
							me->func_decode(data.size, data.data, &outsize, me->bits_decode);
							RDFSTORE_FREE(data.data);
							};
						printf("ADDED (%d) date '%s' of literal '%s' -->'", st_id, thedateval, statement->object->value.literal.string);
						for (i = 0; i < outsize; i++) {
							printf("%02X", me->bits_decode[i]);
							};
						printf("'\n");
						}
#endif

						};
					};
				}; /* end of date indexing */
			};

		/* for xsd:integer alike literals use special b-tree sorted index if strtol() works.... */
		if( ( islval = rdfstore_xsd_deserialize_integer( statement->object->value.literal.string, &thelval ) ) != 0 ) {
			key.data = (long*) &thelval; /* should pack int perhaps... */
			key.size = sizeof(long);

#ifdef RDFSTORE_DEBUG
fprintf(stderr, "INDEX INTEGER '%ld' for LITERAL '%s' \n",(long)thelval, statement->object->value.literal.string);
#endif

			err = rdfstore_flat_store_fetch(me->xsd_integer, key, &data);
			if (err != 0) {
				if (err != FLAT_STORE_E_NOTFOUND) {
					perror("rdfstore_insert");
					fprintf(stderr,"Could not fetch from integer table value '%s' for store '%s': %s\n", statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->xsd_integer));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
					rdfstore_iterator_close(reindex);
#endif
					return -1;
				} else {
					outsize = 0;
					};
			} else {
				me->func_decode(data.size, data.data, &outsize, me->bits_decode);
				RDFSTORE_FREE(data.data);
				};
			rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 1, sizeof(me->bits_decode));

			me->func_encode(outsize, me->bits_decode, &outsize, me->bits_encode);
			if (outsize) {
				data.data = me->bits_encode;
				data.size = outsize;
				err = rdfstore_flat_store_store(me->xsd_integer, key, data);
				if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
					fprintf(stderr,"Stored %d bytes for integer '%ld' in literal '%s' in integer table for store '%s'\n", outsize, (long)thelval, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)");
#endif
				} else {
					if (err != FLAT_STORE_E_KEYEXIST) {
						perror("rdfstore_insert");
						fprintf(stderr,"Could not store '%d' bytes for integer '%ld' in literal '%s' in integer table for store '%s': %s\n", (int)data.size, (long)thelval, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)", rdfstore...
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
						rdfstore_iterator_close(reindex);
#endif
						return -1;
						};
					};

#ifdef RDFSTORE_DEBUG
				{
				int             i;
				if ((rdfstore_flat_store_fetch(me->xsd_integer, key, &data)) == 0) {
					me->func_decode(data.size, data.data, &outsize, me->bits_decode);
					RDFSTORE_FREE(data.data);
				};
				printf("ADDED (%d) integer '%ld' of literal '%s' -->'", st_id, (long)thelval, statement->object->value.literal.string);
				for (i = 0; i < outsize; i++) {
					printf("%02X", me->bits_decode[i]);
					};
				printf("'\n");
				}
#endif

				};

			};

		/* for xsd:double or xsd:float alike literals use special b-tree sorted index if strtod() works.... */
		if(	( islval == 0 ) && /* do not index xsd:integer(s) twice also as xsd:double */
			( ( isdval = rdfstore_xsd_deserialize_double( statement->object->value.literal.string, &thedval ) ) != 0 ) ) {
			key.data = (double*) &thedval; /* should pack int perhaps... */
			key.size = sizeof(double);

#ifdef RDFSTORE_DEBUG
fprintf(stderr, "INDEX DOUBLE '%f' for LITERAL '%s' \n",thedval, statement->object->value.literal.string);
#endif

			err = rdfstore_flat_store_fetch(me->xsd_double, key, &data);
			if (err != 0) {
				if (err != FLAT_STORE_E_NOTFOUND) {
					perror("rdfstore_insert");
					fprintf(stderr,"Could not fetch from double table value '%s' for store '%s': %s\n", statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->xsd_double));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
					rdfstore_iterator_close(reindex);
#endif
					return -1;
				} else {
					outsize = 0;
					};
			} else {
				me->func_decode(data.size, data.data, &outsize, me->bits_decode);
				RDFSTORE_FREE(data.data);
				};
			rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 1, sizeof(me->bits_decode));

			me->func_encode(outsize, me->bits_decode, &outsize, me->bits_encode);
			if (outsize) {
				data.data = me->bits_encode;
				data.size = outsize;
				err = rdfstore_flat_store_store(me->xsd_double, key, data);
				if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
					fprintf(stderr,"Stored %d bytes for double '%f' in literal '%s' in double table for store '%s'\n", outsize, thedval, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)");
#endif
				} else {
					if (err != FLAT_STORE_E_KEYEXIST) {
						perror("rdfstore_insert");
						fprintf(stderr,"Could not store '%d' bytes for double '%f' in literal '%s' in double table for store '%s': %s\n", (int)data.size, thedval, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_sto...
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
						rdfstore_iterator_close(reindex);
#endif
						return -1;
						};
					};

#ifdef RDFSTORE_DEBUG
				{
				int             i;
				if ((rdfstore_flat_store_fetch(me->xsd_double, key, &data)) == 0) {
					me->func_decode(data.size, data.data, &outsize, me->bits_decode);
					RDFSTORE_FREE(data.data);
				};
				printf("ADDED (%d) double '%f' of literal '%s' -->'", st_id, thedval, statement->object->value.literal.string);
				for (i = 0; i < outsize; i++) {
					printf("%02X", me->bits_decode[i]);
					};
				printf("'\n");
				}
#endif

				};

			};
		}; /* end index special literal stuff */

	/*
	 * gettimeofday(&tnow,NULL); ttime = ( tnow.tv_sec - tstart.tv_sec ) *
	 * 1000000 + ( tnow.tv_usec - tstart.tv_usec ) * 1;
	 * printf("rdfstore_insert DONE [%d micro sec]\n",ttime);
	 */

	/* adjacency matrixes (tables) i.e. subjects, predicates, objects, contexts and connections */

	/*
	 * compute other hashcodes (the should be cached because the
	 * underlying digest is carried out also for the statement->hashcode
	 * above)
	 */
	statement->subject->hashcode = rdfstore_digest_get_node_hashCode(statement->subject, 0);
	statement->predicate->hashcode = rdfstore_digest_get_node_hashCode(statement->predicate, 0);
	statement->object->hashcode = rdfstore_digest_get_node_hashCode(statement->object, 0);
	if (context != NULL)
		context->hashcode = rdfstore_digest_get_node_hashCode(context, 0);

rdfstore_kernel.c  view on Meta::CPAN

		};

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
	/*
		We need to re-index quite a lot for each new statement component now - hope caching will 
		help here!! i.e. the swiss army nife problem (see SWAD-E paper and preso)

		1.1) add this new statement (st_id) to p_connections(neighbour->predicate) and o_connections(neighbour->object)
		   tables of each other statement (neighbour) connected to this one via subjects(SUBJECT) node
		1.2) add this new statement (st_id) to s_connections(neighbour->subject) and o_connections(neighbour->object)
		   tables of each other statement (neighbour) connected to this one via predicates(SUBJECT) node
		1.3) add this new statement (st_id) to s_connections(neighbour->subject) and p_connections(neighbour->predicate)
		   tables of each other statement (neighbour) connected to this one via objects(SUBJECT) node
	*/

	/* 1.1) reindex st_id for connections to subjects(SUBJECT) node */

	/* copy the subjects(SUBJECT) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING predicate '%s' for connections to subjects('%s') node in st_id=%d\n",neighbour->predicate->value.resource.identifier,statement->subject->value.resource.identifier,st_id);
#endif
		neighbour->predicate->hashcode = rdfstore_digest_get_node_hashCode(neighbour->predicate, 0);

		/* fetch p_connections(neighbour->predicate) */
		packInt(neighbour->predicate->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->p_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for predicate in p_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->p_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for predicate in p_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING object '%s' for connections to subjects('%s') node in st_id=%d\n",(neighbour->object->type==1) ? neighbour->object->value.literal.string : neighbour->object->value.resource.identifier,statement->subject->value.resource.id...
#endif
		neighbour->object->hashcode = rdfstore_digest_get_node_hashCode(neighbour->object, 0);

		/* fetch o_connections(neighbour->object) */
		packInt(neighbour->object->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->o_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for object in o_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->o_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for object in o_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

	rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 1, sizeof(me->bits_decode));

#ifdef RDFSTORE_CONNECTIONS
	/* COPY subjects(SUBJECT) to s_connections(SUBJECT) */
        bcopy(me->bits_decode, s_connections, outsize);   /* slow? */
	s_outsize = outsize;

	/* COPY subjects(SUBJECT) to p_connections(PREDICATE) */
        bcopy(me->bits_decode, p_connections, outsize);   /* slow? */
	p_outsize = outsize;

	/* COPY subjects(SUBJECT) to o_connections(OBJECT) */
        bcopy(me->bits_decode, o_connections, outsize);   /* slow? */
	o_outsize = outsize;
#endif

	me->func_encode(outsize, me->bits_decode, &outsize, me->bits_encode);
	if (outsize) {

		/* regenerate it due to the re-indexing above which uses key already */
		packInt(statement->subject->hashcode, outbuf);
		key.data = outbuf;
		key.size = sizeof(int);

		data.data = me->bits_encode;
		data.size = outsize;
		err = rdfstore_flat_store_store(me->subjects, key, data);
		if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
			fprintf(stderr,"Stored %d bytes for '%s' in subjects table for store '%s'\n", outsize, (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)");
#endif
		} else {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for subject in subjects table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->subjects));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			};
		};

#ifdef RDFSTORE_DEBUG
		{
			int             i=0;
			if ((rdfstore_flat_store_fetch(me->subjects, key, &data)) == 0) {
				me->func_decode(data.size, data.data, &outsize, me->bits_decode);
				RDFSTORE_FREE(data.data);
			};
			printf("ADDED st_num=%d bitno=%d subjects for S '%s' -->'", st_id, st_id, statement->subject->value.resource.identifier);
			for(i=0;i<8*outsize;i++) {
				printf("Rec %d %c\n", i, (me->bits_decode[i>>3] & (1<<(i&7))) ? '1':'0');
                                };
			printf("'\n");
		}
#endif

	};

MX;
	/* predicates */

rdfstore_kernel.c  view on Meta::CPAN

			rdfstore_iterator_close(reindex);
#endif
			return -1;
		} else {
			outsize = 0;
		};
MX;
	} else {
MX;
		me->func_decode(data.size, data.data, &outsize, me->bits_decode);
MX;
		RDFSTORE_FREE(data.data);
	};

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
        /* 2.2) reindex st_id for connections to predicates(PREDICATE) node */

	/* copy the predicates(PREDICATE) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING subject '%s' for connections to predicates('%s') node in st_id=%d\n",neighbour->subject->value.resource.identifier,statement->predicate->value.resource.identifier,st_id);
#endif
		neighbour->subject->hashcode = rdfstore_digest_get_node_hashCode(neighbour->subject, 0);

		/* fetch s_connections(neighbour->subject) */
		packInt(neighbour->subject->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->s_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for subject in s_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->s_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for subject in s_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING object '%s' for connections to predicates('%s') node in st_id=%d\n",(neighbour->object->type==1) ? neighbour->object->value.literal.string : neighbour->object->value.resource.identifier,statement->predicate->value.resourc...
#endif
		neighbour->object->hashcode = rdfstore_digest_get_node_hashCode(neighbour->object, 0);

		/* fetch o_connections(neighbour->object) */
		packInt(neighbour->object->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->o_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for object in o_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->o_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for object in o_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

MX;
	rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 1, sizeof(me->bits_decode));
MX;

#ifdef RDFSTORE_CONNECTIONS
	/* OR predicates(PREDICATE) to s_connections(SUBJECT) */
        s_outsize = rdfstore_bits_or(outsize, me->bits_decode, s_outsize, s_connections, me->bits_encode); /* use me->bits_encode for easyness 
													     no problem due is rest with encode 
													     operation below here */
        bcopy(me->bits_encode, s_connections, s_outsize);   /* slow? */


	/* OR predicates(PREDICATE) to p_connections(PREDICATE) */
        p_outsize = rdfstore_bits_or(outsize, me->bits_decode, p_outsize, p_connections, me->bits_encode);
        bcopy(me->bits_encode, p_connections, p_outsize);   /* slow? */

	/* OR predicates(PREDICATE) to o_connections(OBJECT) */
        o_outsize = rdfstore_bits_or(outsize, me->bits_decode, o_outsize, o_connections, me->bits_encode);
        bcopy(me->bits_encode, o_connections, o_outsize);   /* slow? */
#endif

	me->func_encode(outsize, me->bits_decode, &outsize, me->bits_encode);
	if (outsize) {

		/* regenerate it due to the re-indexing above which uses key already */
		packInt(statement->predicate->hashcode, outbuf);
		key.data = outbuf;
		key.size = sizeof(int);

		data.data = me->bits_encode;
		data.size = outsize;
		err = rdfstore_flat_store_store(me->predicates, key, data);
		if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
			fprintf(stderr,"Stored %d bytes for '%s' in predicates table for store '%s'\n", outsize, (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)");
#endif
		} else {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for predicate in predicates table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->predicates));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			};
		};

#ifdef RDFSTORE_DEBUG
		{
			int             i=0;
			if ((rdfstore_flat_store_fetch(me->predicates, key, &data)) == 0) {
				me->func_decode(data.size, data.data, &outsize, me->bits_decode);
				RDFSTORE_FREE(data.data);
			};
			printf("ADDED st_num=%d bitno=%d predicates for P '%s' -->'", st_id, st_id, statement->predicate->value.resource.identifier);
			for(i=0;i<8*outsize;i++) {
				printf("Rec %d %c\n", i, (me->bits_decode[i>>3] & (1<<(i&7))) ? '1':'0');
                                };
			printf("'\n");
		}
#endif

rdfstore_kernel.c  view on Meta::CPAN

			rdfstore_iterator_close(reindex);
#endif
			return -1;
		} else {
			outsize = 0;
		};
	} else {
		me->func_decode(data.size, data.data, &outsize, me->bits_decode);	/* perhaps the
												 * compression for
												 * single bits could be
												 * different */
		RDFSTORE_FREE(data.data);
	};

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
        /* 3.3) reindex st_id for connections to objects(OBJECT) node */

	/* copy the objects(OBJECT) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING subject '%s' for connections to objects('%s') node in st_id=%d\n",neighbour->subject->value.resource.identifier,(statement->object->type==1) ? statement->object->value.literal.string : statement->object->value.resource.id...
#endif
		neighbour->subject->hashcode = rdfstore_digest_get_node_hashCode(neighbour->subject, 0);

		/* fetch s_connections(neighbour->subject) */
		packInt(neighbour->subject->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->s_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for subject in s_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->s_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for subject in s_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING predicate '%s' for connections to objects('%s') node in st_id=%d\n",neighbour->predicate->value.resource.identifier,(statement->object->type==1) ? statement->object->value.literal.string : statement->object->value.resourc...
#endif
		neighbour->predicate->hashcode = rdfstore_digest_get_node_hashCode(neighbour->predicate, 0);

		/* fetch p_connections(neighbour->predicate) */
		packInt(neighbour->predicate->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->p_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for predicate in p_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->p_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for predicate in p_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

	rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 1, sizeof(me->bits_decode));

#ifdef RDFSTORE_CONNECTIONS
        /* OR objects(OBJECT) to s_connections(SUBJECT) */
        s_outsize = rdfstore_bits_or(outsize, me->bits_decode, s_outsize, s_connections, me->bits_encode);
        bcopy(me->bits_encode, s_connections, s_outsize);   /* slow? */

	/* OR objects(OBJECT) to p_connections(PREDICATE) */
        p_outsize = rdfstore_bits_or(outsize, me->bits_decode, p_outsize, p_connections, me->bits_encode);
        bcopy(me->bits_encode, p_connections, p_outsize);   /* slow? */

	/* OR objects(OBJECT) to o_connections(OBJECT) */
        o_outsize = rdfstore_bits_or(outsize, me->bits_decode, o_outsize, o_connections, me->bits_encode);
        bcopy(me->bits_encode, o_connections, o_outsize);   /* slow? */
#endif

	me->func_encode(outsize, me->bits_decode, &outsize, me->bits_encode);
	if (outsize) {

		/* regenerate it due to the re-indexing above which uses key already */
		packInt(statement->object->hashcode, outbuf);
		key.data = outbuf;
		key.size = sizeof(int);

		data.data = me->bits_encode;
		data.size = outsize;
		err = rdfstore_flat_store_store(me->objects, key, data);
		if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
			fprintf(stderr,"Stored %d bytes for '%s' in objects table for store '%s'\n", outsize, (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)");
#endif
		} else {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for object in objects table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->objects));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			};
		};

#ifdef RDFSTORE_DEBUG
		{
			int             i=0;
			if ((rdfstore_flat_store_fetch(me->objects, key, &data)) == 0) {
				me->func_decode(data.size, data.data, &outsize, me->bits_decode);
				RDFSTORE_FREE(data.data);
			};
			printf("ADDED st_num=%d bitno=%d objects for O '%s' -->'", st_id, st_id, (statement->object->type != 1) ? statement->object->value.resource.identifier : statement->object->value.literal.string);
			for(i=0;i<8*outsize;i++) {
				printf("Rec %d %c\n", i, (me->bits_decode[i>>3] & (1<<(i&7))) ? '1':'0');
                                };
			printf("'\n");
		}
#endif

	};

#ifdef RDFSTORE_CONNECTIONS
	/* fill up all the rest of s_connections, p_connections and o_connections i.e. carry out remaining permutations of each component */

rdfstore_kernel.c  view on Meta::CPAN

		};

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
	/*
                We need to re-index quite a lot for each new statement component now - hope caching will
                help here!! i.e. the swiss army nife problem (see SWAD-E paper and preso)

                2.1) add this new statement (st_id) to p_connections(neighbour->predicate) and o_connections(neighbour->object)
                   tables of each other statement (neighbour) connected to this one via subjects(PREDICATE) node
                2.2) add this new statement (st_id) to s_connections(neighbour->subject) and o_connections(neighbour->object)
                   tables of each other statement (neighbour) connected to this one via predicates(PREDICATE) node
                2.3) add this new statement (st_id) to s_connections(neighbour->subject) and p_connections(neighbour->predicate)
                   tables of each other statement (neighbour) connected to this one via objects(PREDICATE) node
        */

        /* 2.1) reindex st_id for connections to subjects(PREDICATE) node */

	/* copy the subjects(PREDICATE) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING predicate '%s' for connections to subjects('%s') node in st_id=%d\n",neighbour->predicate->value.resource.identifier,statement->predicate->value.resource.identifier,st_id);
#endif
		neighbour->predicate->hashcode = rdfstore_digest_get_node_hashCode(neighbour->predicate, 0);

		/* fetch p_connections(neighbour->predicate) */
		packInt(neighbour->predicate->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->p_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for predicate in p_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->p_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for predicate in p_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING object '%s' for connections to subjects('%s') node in st_id=%d\n",(neighbour->object->type==1) ? neighbour->object->value.literal.string : neighbour->object->value.resource.identifier,statement->predicate->value.resource....
#endif
		neighbour->object->hashcode = rdfstore_digest_get_node_hashCode(neighbour->object, 0);

		/* fetch o_connections(neighbour->object) */
		packInt(neighbour->object->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->o_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for object in o_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->o_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for object in o_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

	/* OR subjects(PREDICATE) to s_connections(SUBJECT) */
        s_outsize = rdfstore_bits_or(outsize, me->bits_decode, s_outsize, s_connections, me->bits_encode); 
        bcopy(me->bits_encode, s_connections, s_outsize);   /* slow? */

	/* OR subjects(PREDICATE) to p_connections(PREDICATE) */
        p_outsize = rdfstore_bits_or(outsize, me->bits_decode, p_outsize, p_connections, me->bits_encode); 
        bcopy(me->bits_encode, p_connections, p_outsize);   /* slow? */

	/* OR subjects(PREDICATE) to o_connections(OBJECT) */
        o_outsize = rdfstore_bits_or(outsize, me->bits_decode, o_outsize, o_connections, me->bits_encode); 
        bcopy(me->bits_encode, o_connections, o_outsize);   /* slow? */

	/* fetch subjects(OBJECT) */
	packInt(statement->object->hashcode, outbuf);
	key.data = outbuf;
	key.size = sizeof(int);

rdfstore_kernel.c  view on Meta::CPAN

		};

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
	/*
                We need to re-index quite a lot for each new statement component now - hope caching will
                help here!! i.e. the swiss army nife problem (see SWAD-E paper and preso)

                3.1) add this new statement (st_id) to p_connections(neighbour->predicate) and o_connections(neighbour->object)
                   tables of each other statement (neighbour) connected to this one via subjects(OBJECT) node
                3.2) add this new statement (st_id) to s_connections(neighbour->subject) and o_connections(neighbour->object)
                   tables of each other statement (neighbour) connected to this one via predicates(OBJECT) node
                3.3) add this new statement (st_id) to s_connections(neighbour->subject) and p_connections(neighbour->predicate)
                   tables of each other statement (neighbour) connected to this one via objects(OBJECT) node
        */

        /* 3.1) reindex st_id for connections to subjects(OBJECT) node */

	/* copy the subjects(OBJECT) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING predicate '%s' for connections to subjects('%s') node in st_id=%d\n",neighbour->predicate->value.resource.identifier,(statement->object->type==1) ? statement->object->value.literal.string : statement->object->value.resour...
#endif
		neighbour->predicate->hashcode = rdfstore_digest_get_node_hashCode(neighbour->predicate, 0);

		/* fetch p_connections(neighbour->predicate) */
		packInt(neighbour->predicate->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->p_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for predicate in p_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->p_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for predicate in p_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING object '%s' for connections to subjects('%s') node in st_id=%d\n",(neighbour->object->type==1) ? neighbour->object->value.literal.string : neighbour->object->value.resource.identifier,(statement->object->type==1) ? statem...
#endif
		neighbour->object->hashcode = rdfstore_digest_get_node_hashCode(neighbour->object, 0);

		/* fetch o_connections(neighbour->object) */
		packInt(neighbour->object->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->o_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for object in o_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->o_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for object in o_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

	/* OR subjects(OBJECT) to s_connections(SUBJECT) */
        s_outsize = rdfstore_bits_or(outsize, me->bits_decode, s_outsize, s_connections, me->bits_encode); 
        bcopy(me->bits_encode, s_connections, s_outsize);   /* slow? */

	/* OR subjects(OBJECT) to p_connections(PREDICATE) */
        p_outsize = rdfstore_bits_or(outsize, me->bits_decode, p_outsize, p_connections, me->bits_encode); 
        bcopy(me->bits_encode, p_connections, p_outsize);   /* slow? */

	/* OR subjects(OBJECT) to o_connections(OBJECT) */
        o_outsize = rdfstore_bits_or(outsize, me->bits_decode, o_outsize, o_connections, me->bits_encode); 
        bcopy(me->bits_encode, o_connections, o_outsize);   /* slow? */

	/* fetch predicates(SUBJECT) */
	packInt(statement->subject->hashcode, outbuf);
	key.data = outbuf;
	key.size = sizeof(int);

rdfstore_kernel.c  view on Meta::CPAN

			perror("rdfstore_insert");
			fprintf(stderr,"Could not fetch key '%s' for subject in predicates table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->predicates));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
			rdfstore_iterator_close(reindex);
#endif
			return -1;
		} else {
			outsize = 0;
		};
	} else {
		me->func_decode(data.size, data.data, &outsize, me->bits_decode);
		RDFSTORE_FREE(data.data);
		};

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
	/* 1.2) reindex st_id for connections to predicates(SUBJECT) node */

	/* copy the predicates(SUBJECT) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING subject '%s' for connections to predicates('%s') node in st_id=%d\n",neighbour->subject->value.resource.identifier,statement->subject->value.resource.identifier,st_id);
#endif
		neighbour->subject->hashcode = rdfstore_digest_get_node_hashCode(neighbour->subject, 0);

		/* fetch s_connections(neighbour->subject) */
		packInt(neighbour->subject->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->s_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for subject in s_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->s_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for subject in s_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING object '%s' for connections to predicates('%s') node in st_id=%d\n",(neighbour->object->type==1) ? neighbour->object->value.literal.string : neighbour->object->value.resource.identifier,statement->subject->value.resource....
#endif
		neighbour->object->hashcode = rdfstore_digest_get_node_hashCode(neighbour->object, 0);

		/* fetch o_connections(neighbour->object) */
		packInt(neighbour->object->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->o_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for object in o_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->o_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for object in o_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

	/* OR predicates(SUBJECT) to s_connections(SUBJECT) */
        s_outsize = rdfstore_bits_or(outsize, me->bits_decode, s_outsize, s_connections, me->bits_encode); 
        bcopy(me->bits_encode, s_connections, s_outsize);   /* slow? */

	/* OR predicates(SUBJECT) to p_connections(PREDICATE) */
        p_outsize = rdfstore_bits_or(outsize, me->bits_decode, p_outsize, p_connections, me->bits_encode); 
        bcopy(me->bits_encode, p_connections, p_outsize);   /* slow? */

	/* OR predicates(SUBJECT) to o_connections(OBJECT) */
        o_outsize = rdfstore_bits_or(outsize, me->bits_decode, o_outsize, o_connections, me->bits_encode); 
        bcopy(me->bits_encode, o_connections, o_outsize);   /* slow? */

	/* fetch predicates(OBJECT) */
	packInt(statement->object->hashcode, outbuf);
	key.data = outbuf;
	key.size = sizeof(int);

rdfstore_kernel.c  view on Meta::CPAN

			perror("rdfstore_insert");
			fprintf(stderr,"Could not fetch key '%s' for object in predicates table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->predicates));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
			rdfstore_iterator_close(reindex);
#endif
			return -1;
		} else {
			outsize = 0;
		};
	} else {
		me->func_decode(data.size, data.data, &outsize, me->bits_decode);
		RDFSTORE_FREE(data.data);
		};

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
        /* 3.2) reindex st_id for connections to predicates(OBJECT) node */

	/* copy the predicates(OBJECT) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING subject '%s' for connections to predicates('%s') node in st_id=%d\n",neighbour->subject->value.resource.identifier,(statement->object->type==1) ? statement->object->value.literal.string : statement->object->value.resource...
#endif
		neighbour->subject->hashcode = rdfstore_digest_get_node_hashCode(neighbour->subject, 0);

		/* fetch s_connections(neighbour->subject) */
		packInt(neighbour->subject->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->s_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for subject in s_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->s_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for subject in s_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING object '%s' for connections to predicates('%s') node in st_id=%d\n",(neighbour->object->type==1) ? neighbour->object->value.literal.string : neighbour->object->value.resource.identifier,(statement->object->type==1) ? stat...
#endif
		neighbour->object->hashcode = rdfstore_digest_get_node_hashCode(neighbour->object, 0);

		/* fetch o_connections(neighbour->object) */
		packInt(neighbour->object->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->o_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for object in o_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->o_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for object in o_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

	/* OR predicates(OBJECT) to s_connections(SUBJECT) */
        s_outsize = rdfstore_bits_or(outsize, me->bits_decode, s_outsize, s_connections, me->bits_encode); 
        bcopy(me->bits_encode, s_connections, s_outsize);   /* slow? */

	/* OR predicates(OBJECT) to p_connections(PREDICATE) */
        p_outsize = rdfstore_bits_or(outsize, me->bits_decode, p_outsize, p_connections, me->bits_encode); 
        bcopy(me->bits_encode, p_connections, p_outsize);   /* slow? */

	/* OR predicates(OBJECT) to o_connections(OBJECT) */
        o_outsize = rdfstore_bits_or(outsize, me->bits_decode, o_outsize, o_connections, me->bits_encode); 
        bcopy(me->bits_encode, o_connections, o_outsize);   /* slow? */

	/* fetch objects(SUBJECT) */
	packInt(statement->subject->hashcode, outbuf);
	key.data = outbuf;
	key.size = sizeof(int);

rdfstore_kernel.c  view on Meta::CPAN

			perror("rdfstore_insert");
			fprintf(stderr,"Could not fetch key '%s' for subject in objects table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->objects));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
			rdfstore_iterator_close(reindex);
#endif
			return -1;
		} else {
			outsize = 0;
		};
	} else {
		me->func_decode(data.size, data.data, &outsize, me->bits_decode);
		RDFSTORE_FREE(data.data);
		};

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
	/* 1.3) reindex st_id for connections to objects(SUBJECT) node */

	/* copy the objects(SUBJECT) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING subject '%s' for connections to objects('%s') node in st_id=%d\n",neighbour->subject->value.resource.identifier,statement->subject->value.resource.identifier,st_id);
#endif
		neighbour->subject->hashcode = rdfstore_digest_get_node_hashCode(neighbour->subject, 0);

		/* fetch s_connections(neighbour->subject) */
		packInt(neighbour->subject->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->s_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for subject in s_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->s_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for subject in s_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING predicate '%s' for connections to objects('%s') node in st_id=%d\n",neighbour->predicate->value.resource.identifier,statement->subject->value.resource.identifier,st_id);
#endif
		neighbour->predicate->hashcode = rdfstore_digest_get_node_hashCode(neighbour->predicate, 0);

		/* fetch p_connections(neighbour->predicate) */
		packInt(neighbour->predicate->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->p_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for predicate in p_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->p_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for predicate in p_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

	/* OR objects(SUBJECT) to s_connections(SUBJECT) */
        s_outsize = rdfstore_bits_or(outsize, me->bits_decode, s_outsize, s_connections, me->bits_encode); 
        bcopy(me->bits_encode, s_connections, s_outsize);   /* slow? */

	/* OR objects(SUBJECT) to p_connections(PREDICATE) */
        p_outsize = rdfstore_bits_or(outsize, me->bits_decode, p_outsize, p_connections, me->bits_encode); 
        bcopy(me->bits_encode, p_connections, p_outsize);   /* slow? */

	/* OR objects(SUBJECT) to o_connections(OBJECT) */
        o_outsize = rdfstore_bits_or(outsize, me->bits_decode, o_outsize, o_connections, me->bits_encode); 
        bcopy(me->bits_encode, o_connections, o_outsize);   /* slow? */

	/* fetch objects(PREDICATE) */
	packInt(statement->predicate->hashcode, outbuf);
	key.data = outbuf;
	key.size = sizeof(int);

rdfstore_kernel.c  view on Meta::CPAN

			perror("rdfstore_insert");
			fprintf(stderr,"Could not fetch key '%s' for predicate in objects table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->objects));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
			rdfstore_iterator_close(reindex);
#endif
			return -1;
		} else {
			outsize = 0;
		};
	} else {
		me->func_decode(data.size, data.data, &outsize, me->bits_decode);
		RDFSTORE_FREE(data.data);
		};

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
        /* 2.3) reindex st_id for connections to objects(PREDICATE) node */

	/* copy the objects(PREDICATE) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING subject '%s' for connections to objects('%s') node in st_id=%d\n",neighbour->subject->value.resource.identifier,statement->predicate->value.resource.identifier,st_id);
#endif
		neighbour->subject->hashcode = rdfstore_digest_get_node_hashCode(neighbour->subject, 0);

		/* fetch s_connections(neighbour->subject) */
		packInt(neighbour->subject->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->s_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for subject in s_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->s_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for subject in s_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(insert)REINDEXING predicate '%s' for connections to objects('%s') node in st_id=%d\n",neighbour->predicate->value.resource.identifier,statement->predicate->value.resource.identifier,st_id);
#endif
		neighbour->predicate->hashcode = rdfstore_digest_get_node_hashCode(neighbour->predicate, 0);

		/* fetch p_connections(neighbour->predicate) */
		packInt(neighbour->predicate->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->p_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' for predicate in p_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* set the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 1, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->p_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for predicate in p_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

	/* OR objects(PREDICATE) to s_connections(SUBJECT) */
        s_outsize = rdfstore_bits_or(outsize, me->bits_decode, s_outsize, s_connections, me->bits_encode); 
        bcopy(me->bits_encode, s_connections, s_outsize);   /* slow? */

	/* OR objects(PREDICATE) to p_connections(PREDICATE) */
        p_outsize = rdfstore_bits_or(outsize, me->bits_decode, p_outsize, p_connections, me->bits_encode); 
        bcopy(me->bits_encode, p_connections, p_outsize);   /* slow? */

	/* OR objects(PREDICATE) to o_connections(OBJECT) */
        o_outsize = rdfstore_bits_or(outsize, me->bits_decode, o_outsize, o_connections, me->bits_encode); 
        bcopy(me->bits_encode, o_connections, o_outsize);   /* slow? */

	/* SUBJECT - we need to OR s_connections(SUBJECT) with generated s_connections and store */

	/* fetch s_connections(SUBJECT) */
	packInt(statement->subject->hashcode, outbuf);
	key.data = outbuf;

rdfstore_kernel.c  view on Meta::CPAN

				perror("rdfstore_insert");
				fprintf(stderr,"Could not store '%d' bytes for object in o_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			};
		};

#ifdef RDFSTORE_DEBUG
		{
			int             i=0;
			if ((rdfstore_flat_store_fetch(me->o_connections, key, &data)) == 0) {
				me->func_decode_connections(data.size, data.data, &outsize, me->bits_decode);
				RDFSTORE_FREE(data.data);
			};
			printf("ADDED st_num=%d bitno=%d o_connections for object '%s' -->'", st_id, st_id, (statement->object->type != 1) ? statement->object->value.resource.identifier : statement->object->value.literal.string );
			for(i=0;i<8*outsize;i++) {
				printf("Rec %d %c\n", i, (me->bits_decode[i>>3] & (1<<(i&7))) ? '1':'0');
                                };
			printf("'\n");
		}
#endif

	};

#endif /* RDFSTORE_CONNECTIONS */

	/* contexts table */

	if (context != NULL) {
		/* context */
		packInt(context->hashcode, outbuf);
		key.data = outbuf;
		key.size = sizeof(int);

		/*
		 * bzero(me->bits_encode,sizeof(me->bits_encode));
		 * bzero(me->bits_decode,sizeof(me->bits_decode));
		 */

		err = rdfstore_flat_store_fetch(me->contexts, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_insert");
				fprintf(stderr,"Could not fetch key '%s' in contexts table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->contexts));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize = 0;
			};
		} else {
			me->func_decode(data.size, data.data, &outsize, me->bits_decode);	/* perhaps the
													 * compression for
													 * single bits could be
													 * different */
			RDFSTORE_FREE(data.data);
		};
		rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 1, sizeof(me->bits_decode));

		me->func_encode(outsize, me->bits_decode, &outsize, me->bits_encode);
		if (outsize) {
			data.data = me->bits_encode;
			data.size = outsize;
			err = rdfstore_flat_store_store(me->contexts, key, data);
			if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
				fprintf(stderr,"Stored %d bytes for '%s' in contexts table for store '%s'\n", outsize, (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)");
#endif
			} else {
				if (err != FLAT_STORE_E_KEYEXIST) {
					perror("rdfstore_insert");
					fprintf(stderr,"Could not store '%d' bytes in contexts table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->contexts));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
					rdfstore_iterator_close(reindex);
#endif
					return -1;
				};
			};

#ifdef RDFSTORE_DEBUG
			{
				int             i;
				if ((rdfstore_flat_store_fetch(me->contexts, key, &data)) == 0) {
					me->func_decode(data.size, data.data, &outsize, me->bits_decode);
					RDFSTORE_FREE(data.data);
				};
				printf("ADDED st_num=%d bitno=%d contexts for C '%s' -->'", st_id, st_id, context->value.resource.identifier);
				for(i=0;i<8*outsize;i++) {
					printf("Rec %d %c\n", i, (me->bits_decode[i>>3] & (1<<(i&7))) ? '1':'0');
                                        };
				printf("'\n");
			}
#endif
		};
	};

	/* store the statement internal identifier */
	packInt(hc, outbuf);
	key.data = outbuf;
	key.size = sizeof(int);

	packInt(st_id, outbuf1);
	data.data = outbuf1;
	data.size = sizeof(int);

	err = rdfstore_flat_store_store(me->statements, key, data);
	if (err != 0) {
		perror("rdfstore_insert");
		fprintf(stderr,"Could not store statement internal identifier in statements for store '%s': %s\n", (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->statements));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
		rdfstore_iterator_close(reindex);
#endif
		return -1;
	} else {
		/* touch DB last modified date */
        	bzero(&thedateval_tm, sizeof( struct tm ) );

        	time(&now);

rdfstore_kernel.c  view on Meta::CPAN

	 *
         * here are all the possible connections an existing statement might get into (i.e. "swiss army knife problem"):
         *
         *              a4                     a6               a8
         *               \                      \                \
         *                \            * *       \       * *      \
         *                 \---> A =====*=======> B ======*======> C------>b9----->c9
         *                     / ^\    * *       /^\     * *       ^\
         *                    /  | \            / | \              | \
         *             b5<---/   |  \--->c4    /  |  \--->c6       |  \--->c8
         *            /          b1           /   b2               b3
         *           /           ^     b7<---/    ^                ^
         *    c5<---/            |     \          |                |
         *                       |      \         |                |
	 *                       a1      \--->c7  a2               a3
         *
         *
         * where  A======>B======>C is the statement to remove and '*' flags edges/arcs to zap
         *
	 * when a statement is removed e.g. (A,B,C) the corresponding connections tables need to be updated; together with the
         * ones of its neighbours. First, the two graph edges connecting the statement components (see '*' signs in the above pic)
         * need to be pruned; then each other connection to neighbours need to be reset accordingly for the statement (st_id) being
         * removed. By removing the connection arcs for the statements the corresponding connections to the connected components
         * need to be removed from each node connection too; this means if a specific node is being a component of more than one
         * statement e.g. C in the above pic - we need for example to reset each connection due to each other component of the statement
         * being removed. For example, by removing the above statement the C nods needs to reset its connections to other statemnts
         * due to A and B nodes (which WERE its subject and object before the statement was removed) - clear enough???!
	 * In practice, when carrying out the connections tables for the statement components being removed we just keep the connections
	 * due to each node self (e.g. for C its subjects(C), predicates(C) and object(C) - of course if not empty - clear?) and do not 
         * consider (reset) all the other set during insertion/updation - which now are not more used.
	 *
	 */

	/* subjects */
	packInt(statement->subject->hashcode, outbuf);
	key.data = outbuf;
	key.size = sizeof(int);

	/*
	 * bzero(me->bits_encode,sizeof(me->bits_encode));
	 * bzero(me->bits_decode,sizeof(me->bits_decode));
	 */
	err = rdfstore_flat_store_fetch(me->subjects, key, &data);
	if (err != 0) {
		if (err != FLAT_STORE_E_NOTFOUND) {
			perror("rdfstore_remove");
			fprintf(stderr,"Could not fetch key '%s' for subject in subjects for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->subjects));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
			rdfstore_iterator_close(reindex);
#endif
			return -1;
		} else {
			outsize = 0;
		};
	} else {
		me->func_decode(data.size, data.data, &outsize, me->bits_decode);
		RDFSTORE_FREE(data.data);
	};

	/* reset the right bit to zero */
	rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 0, sizeof(me->bits_decode));

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
	/*
                We need to re-index quite a lot for each new statement component now - hope caching will
                help here!! i.e. the swiss army nife problem (see SWAD-E paper and preso)

                1.1) remove this new statement (st_id) from p_connections(neighbour->predicate) and o_connections(neighbour->object)
                   tables of each other statement (neighbour) connected to this one via subjects(SUBJECT) node
                1.2) remove this new statement (st_id) from s_connections(neighbour->subject) and o_connections(neighbour->object)
                   tables of each other statement (neighbour) connected to this one via predicates(SUBJECT) node
                1.3) remove this new statement (st_id) from s_connections(neighbour->subject) and p_connections(neighbour->predicate)
                   tables of each other statement (neighbour) connected to this one via objects(SUBJECT) node
        */

        /* 1.1) reindex st_id for connections to subjects(SUBJECT) node */

	/* copy the subjects(SUBJECT) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING predicate '%s' for connections to subjects('%s') node in st_id=%d\n",neighbour->predicate->value.resource.identifier,statement->subject->value.resource.identifier,st_id);
#endif
		neighbour->predicate->hashcode = rdfstore_digest_get_node_hashCode(neighbour->predicate, 0);

		/* fetch p_connections(neighbour->predicate) */
		packInt(neighbour->predicate->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->p_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for predicate in p_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->p_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for predicate in p_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING object '%s' for connections to subjects('%s') node in st_id=%d\n",(neighbour->object->type==1) ? neighbour->object->value.literal.string : neighbour->object->value.resource.identifier,statement->subject->value.resource.id...
#endif
		neighbour->object->hashcode = rdfstore_digest_get_node_hashCode(neighbour->object, 0);

		/* fetch o_connections(neighbour->object) */
		packInt(neighbour->object->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->o_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for object in o_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		/* now: we do not need/must check whther or not to remove this key because the other statement is sitll there */

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->o_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for object in o_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

	/* regenerate it due to the re-indexing above which uses key already */
	packInt(statement->subject->hashcode, outbuf);
	key.data = outbuf;
	key.size = sizeof(int);

	outsize = rdfstore_bits_shorten(outsize, me->bits_decode);

	if ( outsize > 0 ) {
		me->func_encode(outsize, me->bits_decode, &outsize, me->bits_encode);
		if (outsize) {
			data.data = me->bits_encode;
			data.size = outsize;
			err = rdfstore_flat_store_store(me->subjects, key, data);
			if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION

rdfstore_kernel.c  view on Meta::CPAN


		};

#ifdef RDFSTORE_CONNECTIONS
        	/* COPY subjects(SUBJECT) to s_connections(SUBJECT) */
        	bcopy(me->bits_decode, s_connections, outsize);   /* slow? */
        	s_outsize = outsize;
#endif
	} else {
		err = rdfstore_flat_store_delete(me->subjects, key);
		if (err != 0) {
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
                	rdfstore_iterator_close(reindex);
#endif
			if (err != FLAT_STORE_E_NOTFOUND) {
                		perror("rdfstore_remove");
                		fprintf(stderr,"Could not delete statement for store '%s': %s\n", (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->subjects));
                		return -1;
			} else {
				return 1;
				};
                	};
#ifdef RDFSTORE_DEBUG
		printf("DELETED (%d) subjects for S\n", st_id);
#endif
		};

MX;
	/* predicates */
	packInt(statement->predicate->hashcode, outbuf);
	key.data = outbuf;
	key.size = sizeof(int);
MX;

	/*
	 * bzero(me->bits_encode,sizeof(me->bits_encode));
	 * bzero(me->bits_decode,sizeof(me->bits_decode));
	 */
	err = rdfstore_flat_store_fetch(me->predicates, key, &data);
	if (err != 0) {
		if (err != FLAT_STORE_E_NOTFOUND) {
			perror("rdfstore_remove");
			fprintf(stderr,"Could not fetch key '%s' for predicate in predicates for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->predicates));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
			rdfstore_iterator_close(reindex);
#endif
			return -1;
		} else {
			outsize = 0;
		};
	} else {
		me->func_decode(data.size, data.data, &outsize, me->bits_decode);	/* perhaps the
												 * compression for
												 * single bits could be
												 * different */
		RDFSTORE_FREE(data.data);
		};

MX;
	/* reset the right bits to zero */
	rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 0, sizeof(me->bits_decode));

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
        /* 2.2) reindex st_id for connections to predicates(PREDICATE) node */

	/* copy the predicates(PREDICATE) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING subject '%s' for connections to predicates('%s') node in st_id=%d\n",neighbour->subject->value.resource.identifier,statement->predicate->value.resource.identifier,st_id);
#endif
		neighbour->subject->hashcode = rdfstore_digest_get_node_hashCode(neighbour->subject, 0);

		/* fetch s_connections(neighbour->subject) */
		packInt(neighbour->subject->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->s_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for subject in s_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->s_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for subject in s_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING object '%s' for connections to predicates('%s') node in st_id=%d\n",(neighbour->object->type==1) ? neighbour->object->value.literal.string : neighbour->object->value.resource.identifier,statement->predicate->value.resourc...
#endif
		neighbour->object->hashcode = rdfstore_digest_get_node_hashCode(neighbour->object, 0);

		/* fetch o_connections(neighbour->object) */
		packInt(neighbour->object->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->o_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for object in o_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->o_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for object in o_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

	/* regenerate it due to the re-indexing above which uses key already */
	packInt(statement->predicate->hashcode, outbuf);
	key.data = outbuf;
	key.size = sizeof(int);

	outsize = rdfstore_bits_shorten(outsize, me->bits_decode);
	if ( outsize > 0 ) {
		me->func_encode(outsize, me->bits_decode, &outsize, me->bits_encode);
		if (outsize) {
			data.data = me->bits_encode;
			data.size = outsize;
			err = rdfstore_flat_store_store(me->predicates, key, data);
			if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
				fprintf(stderr,"Stored %d bytes for '%s' in predicates for store '%s'\n", outsize, (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)");
#endif
			} else {

rdfstore_kernel.c  view on Meta::CPAN

			}
#endif

		};
#ifdef RDFSTORE_CONNECTIONS
        	/* OR predicates(PREDICATE) to p_connections(PREDICATE) */
        	p_outsize = rdfstore_bits_or(outsize, me->bits_decode, p_outsize, p_connections, me->bits_encode);
        	bcopy(me->bits_encode, p_connections, p_outsize);   /* slow? */
#endif
	} else { 
		err = rdfstore_flat_store_delete(me->predicates, key);
		if (err != 0) {
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
                        rdfstore_iterator_close(reindex);
#endif
                        if (err != FLAT_STORE_E_NOTFOUND) {
                        	perror("rdfstore_remove");
                        	fprintf(stderr,"Could not delete statement for store '%s': %s\n", (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->predicates));
                        	return -1;
			} else {
				return 1;
				};
                        };
#ifdef RDFSTORE_DEBUG
		printf("DELETED (%d) predicates for P\n", st_id);
#endif
		};

MX;

	/* objects */
	packInt(statement->object->hashcode, outbuf);
	key.data = outbuf;
	key.size = sizeof(int);

	/*
	 * bzero(me->bits_encode,sizeof(me->bits_encode));
	 * bzero(me->bits_decode,sizeof(me->bits_decode));
	 */
	err = rdfstore_flat_store_fetch(me->objects, key, &data);
	if (err != 0) {
		if (err != FLAT_STORE_E_NOTFOUND) {
			perror("rdfstore_remove");
			fprintf(stderr,"Could not fetch key '%s' for object in objects for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->objects));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
			rdfstore_iterator_close(reindex);
#endif
			return -1;
		} else {
			outsize = 0;
		};
	} else {
		me->func_decode(data.size, data.data, &outsize, me->bits_decode);	/* perhaps the
												 * compression for
												 * single bits could be
												 * different */
		RDFSTORE_FREE(data.data);
	};

	/* reset the right bit to zero */
	rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 0, sizeof(me->bits_decode));

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
        /* 3.3) reindex st_id for connections to objects(OBJECT) node */

	/* copy the objects(OBJECT) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING subject '%s' for connections to objects('%s') node in st_id=%d\n",neighbour->subject->value.resource.identifier,(statement->object->type==1) ? statement->object->value.literal.string : statement->object->value.resource.id...
#endif
		neighbour->subject->hashcode = rdfstore_digest_get_node_hashCode(neighbour->subject, 0);

		/* fetch s_connections(neighbour->subject) */
		packInt(neighbour->subject->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->s_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for subject in s_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->s_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for subject in s_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING predicate '%s' for connections to objects('%s') node in st_id=%d\n",neighbour->predicate->value.resource.identifier,(statement->object->type==1) ? statement->object->value.literal.string : statement->object->value.resourc...
#endif
		neighbour->predicate->hashcode = rdfstore_digest_get_node_hashCode(neighbour->predicate, 0);

		/* fetch p_connections(neighbour->predicate) */
		packInt(neighbour->predicate->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->p_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for predicate in p_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->p_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for predicate in p_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

	/* regenerate it due to the re-indexing above which uses key already */
	packInt(statement->object->hashcode, outbuf);
	key.data = outbuf;
	key.size = sizeof(int);

	outsize = rdfstore_bits_shorten(outsize, me->bits_decode);
	if ( outsize > 0 ) {
		me->func_encode(outsize, me->bits_decode, &outsize, me->bits_encode);
		if (outsize) {
			data.data = me->bits_encode;
			data.size = outsize;
			err = rdfstore_flat_store_store(me->objects, key, data);
			if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
				fprintf(stderr,"Stored %d bytes for '%s' in objects for store '%s'\n", outsize, (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)");
#endif
			} else {

rdfstore_kernel.c  view on Meta::CPAN

                };

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
	/*
                We need to re-index quite a lot for each new statement component now - hope caching will
                help here!! i.e. the swiss army nife problem (see SWAD-E paper and preso)

                2.1) remove this new statement (st_id) from p_connections(neighbour->predicate) and o_connections(neighbour->object)
                   tables of each other statement (neighbour) connected to this one via subjects(PREDICATE) node
                2.2) remove this new statement (st_id) from s_connections(neighbour->subject) and o_connections(neighbour->object)
                   tables of each other statement (neighbour) connected to this one via predicates(PREDICATE) node
                2.3) remove this new statement (st_id) from s_connections(neighbour->subject) and p_connections(neighbour->predicate)
                   tables of each other statement (neighbour) connected to this one via objects(PREDICATE) node
        */

        /* 2.1) reindex st_id for connections to subjects(PREDICATE) node */

	/* copy the subjects(PREDICATE) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING predicate '%s' for connections to subjects('%s') node in st_id=%d\n",neighbour->predicate->value.resource.identifier,statement->predicate->value.resource.identifier,st_id);
#endif
		neighbour->predicate->hashcode = rdfstore_digest_get_node_hashCode(neighbour->predicate, 0);

		/* fetch p_connections(neighbour->predicate) */
		packInt(neighbour->predicate->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->p_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for predicate in p_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->p_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for predicate in p_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING object '%s' for connections to subjects('%s') node in st_id=%d\n",(neighbour->object->type==1) ? neighbour->object->value.literal.string : neighbour->object->value.resource.identifier,statement->predicate->value.resource....
#endif
		neighbour->object->hashcode = rdfstore_digest_get_node_hashCode(neighbour->object, 0);

		/* fetch o_connections(neighbour->object) */
		packInt(neighbour->object->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->o_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for object in o_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		/* now: we do not need/must check whther or not to remove this key because the other statement is sitll there */

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->o_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for object in o_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

	/* OR subjects(PREDICATE) to s_connections(SUBJECT) */
        s_outsize = rdfstore_bits_or(outsize, me->bits_decode, s_outsize, s_connections, me->bits_encode); 
        bcopy(me->bits_encode, s_connections, s_outsize);   /* slow? */

        /* fetch subjects(OBJECT) */
        packInt(statement->object->hashcode, outbuf);
        key.data = outbuf;
        key.size = sizeof(int);

	err = rdfstore_flat_store_fetch(me->subjects, key, &data);
        if (err != 0) {
                if (err != FLAT_STORE_E_NOTFOUND) {
                        perror("rdfstore_remove");
                        fprintf(stderr,"Could not fetch key '%s' for object in subjects table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->subjects));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)

rdfstore_kernel.c  view on Meta::CPAN

                };

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
	/*
                We need to re-index quite a lot for each new statement component now - hope caching will
                help here!! i.e. the swiss army nife problem (see SWAD-E paper and preso)

                3.1) remove this new statement (st_id) from p_connections(neighbour->predicate) and o_connections(neighbour->object)
                   tables of each other statement (neighbour) connected to this one via subjects(OBJECT) node
                3.2) remove this new statement (st_id) from s_connections(neighbour->subject) and o_connections(neighbour->object)
                   tables of each other statement (neighbour) connected to this one via predicates(OBJECT) node
                3.3) remove this new statement (st_id) from s_connections(neighbour->subject) and p_connections(neighbour->predicate)
                   tables of each other statement (neighbour) connected to this one via objects(OBJECT) node
        */

        /* 3.1) reindex st_id for connections to subjects(OBJECT) node */

	/* copy the subjects(OBJECT) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING predicate '%s' for connections to subjects('%s') node in st_id=%d\n",neighbour->predicate->value.resource.identifier,(statement->object->type==1) ? statement->object->value.literal.string : statement->object->value.resour...
#endif
		neighbour->predicate->hashcode = rdfstore_digest_get_node_hashCode(neighbour->predicate, 0);

		/* fetch p_connections(neighbour->predicate) */
		packInt(neighbour->predicate->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->p_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for predicate in p_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->p_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for predicate in p_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING object '%s' for connections to subjects('%s') node in st_id=%d\n",(neighbour->object->type==1) ? neighbour->object->value.literal.string : neighbour->object->value.resource.identifier,(statement->object->type==1) ? statem...
#endif
		neighbour->object->hashcode = rdfstore_digest_get_node_hashCode(neighbour->object, 0);

		/* fetch o_connections(neighbour->object) */
		packInt(neighbour->object->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->o_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for object in o_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		/* now: we do not need/must check whther or not to remove this key because the other statement is sitll there */

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->o_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for object in o_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

	/* OR subjects(OBJECT) to s_connections(SUBJECT) */
        s_outsize = rdfstore_bits_or(outsize, me->bits_decode, s_outsize, s_connections, me->bits_encode); 
        bcopy(me->bits_encode, s_connections, s_outsize);   /* slow? */

        /* fetch predicates(SUBJECT) */
        packInt(statement->subject->hashcode, outbuf);
        key.data = outbuf;
        key.size = sizeof(int);

	err = rdfstore_flat_store_fetch(me->predicates, key, &data);
        if (err != 0) {
                if (err != FLAT_STORE_E_NOTFOUND) {
                        perror("rdfstore_remove");
                        fprintf(stderr,"Could not fetch key '%s' for subject in predicates table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ?  me->name : "(in-memory)", rdfstore_flat_store_get_error(me->predicates));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
			rdfstore_iterator_close(reindex);
#endif
                        return -1;
                } else {
                        outsize = 0;
                };
        } else {
                me->func_decode(data.size, data.data, &outsize, me->bits_decode);
                RDFSTORE_FREE(data.data);
                };

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
	/* 1.2) reindex st_id for connections to predicates(SUBJECT) node */

	/* copy the predicates(SUBJECT) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING subject '%s' for connections to predicates('%s') node in st_id=%d\n",neighbour->subject->value.resource.identifier,statement->subject->value.resource.identifier,st_id);
#endif
		neighbour->subject->hashcode = rdfstore_digest_get_node_hashCode(neighbour->subject, 0);

		/* fetch s_connections(neighbour->subject) */
		packInt(neighbour->subject->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->s_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for subject in s_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->s_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for subject in s_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING object '%s' for connections to predicates('%s') node in st_id=%d\n",(neighbour->object->type==1) ? neighbour->object->value.literal.string : neighbour->object->value.resource.identifier,statement->subject->value.resource....
#endif
		neighbour->object->hashcode = rdfstore_digest_get_node_hashCode(neighbour->object, 0);

		/* fetch o_connections(neighbour->object) */
		packInt(neighbour->object->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->o_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for object in o_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->o_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for object in o_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

        /* OR predicates(SUBJECT) to p_connections(PREDICATE) */
        p_outsize = rdfstore_bits_or(outsize, me->bits_decode, p_outsize, p_connections, me->bits_encode); 
        bcopy(me->bits_encode, p_connections, p_outsize);   /* slow? */

        /* fetch predicates(OBJECT) */
        packInt(statement->object->hashcode, outbuf);
        key.data = outbuf;
        key.size = sizeof(int);

	err = rdfstore_flat_store_fetch(me->predicates, key, &data);
        if (err != 0) {
                if (err != FLAT_STORE_E_NOTFOUND) {
                        perror("rdfstore_remove");
                        fprintf(stderr,"Could not fetch key '%s' for object in predicates table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->predicates));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
			rdfstore_iterator_close(reindex);
#endif
                        return -1;
                } else {
                        outsize = 0;
                };
        } else {
                me->func_decode(data.size, data.data, &outsize, me->bits_decode);
                RDFSTORE_FREE(data.data);
                };

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
        /* 3.2) reindex st_id for connections to predicates(OBJECT) node */

	/* copy the predicates(OBJECT) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING subject '%s' for connections to predicates('%s') node in st_id=%d\n",neighbour->subject->value.resource.identifier,(statement->object->type==1) ? statement->object->value.literal.string : statement->object->value.resource...
#endif
		neighbour->subject->hashcode = rdfstore_digest_get_node_hashCode(neighbour->subject, 0);

		/* fetch s_connections(neighbour->subject) */
		packInt(neighbour->subject->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->s_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for subject in s_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->s_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for subject in s_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING object '%s' for connections to predicates('%s') node in st_id=%d\n",(neighbour->object->type==1) ? neighbour->object->value.literal.string : neighbour->object->value.resource.identifier,(statement->object->type==1) ? stat...
#endif
		neighbour->object->hashcode = rdfstore_digest_get_node_hashCode(neighbour->object, 0);

		/* fetch o_connections(neighbour->object) */
		packInt(neighbour->object->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->o_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for object in o_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->o_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for object in o_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

        /* OR predicates(OBJECT) to p_connections(PREDICATE) */
        p_outsize = rdfstore_bits_or(outsize, me->bits_decode, p_outsize, p_connections, me->bits_encode); 
        bcopy(me->bits_encode, p_connections, p_outsize);   /* slow? */

        /* fetch objects(SUBJECT) */
        packInt(statement->subject->hashcode, outbuf);
        key.data = outbuf;
        key.size = sizeof(int);

	err = rdfstore_flat_store_fetch(me->objects, key, &data);
        if (err != 0) {
                if (err != FLAT_STORE_E_NOTFOUND) {
                        perror("rdfstore_remove");
                        fprintf(stderr,"Could not fetch key '%s' for subject in objects table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->objects));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
			rdfstore_iterator_close(reindex);
#endif
                        return -1;
                } else {
                        outsize = 0;
                };
        } else {
                me->func_decode(data.size, data.data, &outsize, me->bits_decode);
                RDFSTORE_FREE(data.data);
                };

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
        /* 1.3) reindex st_id for connections to objects(SUBJECT) node */

	/* copy the objects(SUBJECT) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING subject '%s' for connections to objects('%s') node in st_id=%d\n",neighbour->subject->value.resource.identifier,statement->subject->value.resource.identifier,st_id);
#endif
		neighbour->subject->hashcode = rdfstore_digest_get_node_hashCode(neighbour->subject, 0);

		/* fetch s_connections(neighbour->subject) */
		packInt(neighbour->subject->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->s_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for subject in s_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->s_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for subject in s_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING predicate '%s' for connections to objects('%s') node in st_id=%d\n",neighbour->predicate->value.resource.identifier,statement->subject->value.resource.identifier,st_id);
#endif
		neighbour->predicate->hashcode = rdfstore_digest_get_node_hashCode(neighbour->predicate, 0);

		/* fetch p_connections(neighbour->predicate) */
		packInt(neighbour->predicate->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->p_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for predicate in p_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->p_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for predicate in p_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

        /* OR objects(SUBJECT) to o_connections(OBJECT) */
        o_outsize = rdfstore_bits_or(outsize, me->bits_decode, o_outsize, o_connections, me->bits_encode); 
        bcopy(me->bits_encode, o_connections, o_outsize);   /* slow? */

        /* fetch objects(PREDICATE) */
        packInt(statement->predicate->hashcode, outbuf);
        key.data = outbuf;
        key.size = sizeof(int);

	err = rdfstore_flat_store_fetch(me->objects, key, &data);
        if (err != 0) {
                if (err != FLAT_STORE_E_NOTFOUND) {
                        perror("rdfstore_remove");
                        fprintf(stderr,"Could not fetch key '%s' for predicate in objects table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->objects));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
			rdfstore_iterator_close(reindex);
#endif
                        return -1;
                } else {
                        outsize = 0;
                };
        } else {
                me->func_decode(data.size, data.data, &outsize, me->bits_decode);
                RDFSTORE_FREE(data.data);
                };

#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
        /* 2.3) reindex st_id for connections to objects(PREDICATE) node */

	/* copy the objects(PREDICATE) bits through the reindex iterator array */
        memcpy(reindex->ids, me->bits_decode, outsize);
        reindex->ids_size = outsize;
        /* set the size - inefficient!! */
        pos = 0;
        reindex->size = 0;
        /* count the ones (inefficient still) */
        while ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < 8 * outsize) {
                reindex->size++;
                pos++;
        	};

	/* scan the obtained iterator */
	while ( ( neighbour = rdfstore_iterator_each ( reindex ) ) != NULL ) {

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING subject '%s' for connections to objects('%s') node in st_id=%d\n",neighbour->subject->value.resource.identifier,statement->predicate->value.resource.identifier,st_id);
#endif
		neighbour->subject->hashcode = rdfstore_digest_get_node_hashCode(neighbour->subject, 0);

		/* fetch s_connections(neighbour->subject) */
		packInt(neighbour->subject->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->s_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for subject in s_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->s_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for subject in s_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

#ifdef RDFSTORE_DEBUG_CONNECTIONS
		printf("(remove)REINDEXING predicate '%s' for connections to objects('%s') node in st_id=%d\n",neighbour->predicate->value.resource.identifier,statement->predicate->value.resource.identifier,st_id);
#endif
		neighbour->predicate->hashcode = rdfstore_digest_get_node_hashCode(neighbour->predicate, 0);

		/* fetch p_connections(neighbour->predicate) */
		packInt(neighbour->predicate->hashcode, outbuf); /* wrong */
		key.data = outbuf;
		key.size = sizeof(int);

		err = rdfstore_flat_store_fetch(me->p_connections, key, &data);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' for predicate in p_connections table for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize_reindex = 0;
			};
		} else {
			me->func_decode_connections(data.size, data.data, &outsize_reindex, reindex_decode);
			RDFSTORE_FREE(data.data);
			};

		/* reset the corresponding bit of this statement */
		rdfstore_bits_setmask(&outsize_reindex, reindex_decode, st_id, 1, 0, sizeof(reindex_decode));

		/* store it back */
		me->func_encode_connections(outsize_reindex, reindex_decode, &outsize_reindex, reindex_encode);

		data.data = reindex_encode;
		data.size = outsize_reindex;
		err = rdfstore_flat_store_store(me->p_connections, key, data);
		if (err != 0) {
			if (err != FLAT_STORE_E_KEYEXIST) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not store '%d' bytes for predicate in p_connections table for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->p_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			};

		/* free neighbour */
                RDFSTORE_FREE( neighbour->subject->value.resource.identifier );
                RDFSTORE_FREE( neighbour->subject );
                RDFSTORE_FREE( neighbour->predicate->value.resource.identifier );
                RDFSTORE_FREE( neighbour->predicate );
                if ( neighbour->object->type == 1 ) {
                        if ( neighbour->object->value.literal.dataType != NULL )
                                RDFSTORE_FREE( neighbour->object->value.literal.dataType );
                        RDFSTORE_FREE( neighbour->object->value.literal.string );
                } else {
                        RDFSTORE_FREE( neighbour->object->value.resource.identifier );
                        };
                RDFSTORE_FREE( neighbour->object );
                if ( neighbour->context != NULL ) {
                        RDFSTORE_FREE( neighbour->context->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->context );
                        };
                if ( neighbour->node != NULL ) {
                        RDFSTORE_FREE( neighbour->node->value.resource.identifier );
                        RDFSTORE_FREE( neighbour->node );
                        };
                RDFSTORE_FREE( neighbour );
		};
#endif

        /* OR objects(PREDICATE) to o_connections(OBJECT) */
        o_outsize = rdfstore_bits_or(outsize, me->bits_decode, o_outsize, o_connections, me->bits_encode); 
        bcopy(me->bits_encode, o_connections, o_outsize);   /* slow? */

	/* SUBJECT - reset the right bits for s_connections - we need to AND s_connections(SUBJECT) with generated s_connections and store */

        /* fetch s_connections(SUBJECT) */
        packInt(statement->subject->hashcode, outbuf);
        key.data = outbuf;
        key.size = sizeof(int);

	err = rdfstore_flat_store_fetch(me->s_connections, key, &data);
	if (err != 0) {
               	if (err != FLAT_STORE_E_NOTFOUND) {
                       	perror("rdfstore_remove");
                       	fprintf(stderr,"Could not fetch key '%s' for subject in s_connections for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->s_connections));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)

rdfstore_kernel.c  view on Meta::CPAN

			if ((rdfstore_flat_store_fetch(me->o_connections, key, &data)) == 0) {
				me->func_decode_connections(data.size, data.data, &outsize, me->bits_decode);
				RDFSTORE_FREE(data.data);
				};
			printf("REMOVED st_num=%d bitno=%d o_connections for O '%s' -->'", st_id, st_id, (statement->object->type != 1) ? statement->object->value.resource.identifier : statement->object->value.literal.string);
			for(i=0;i<8*outsize;i++) {
				printf("Rec %d %c\n", i, (me->bits_decode[i>>3] & (1<<(i&7))) ? '1':'0');
                                       };
			printf("'\n");
			}
#endif

			};
	} else {
		err = rdfstore_flat_store_delete(me->o_connections, key);
		if (err != 0) {
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
                        rdfstore_iterator_close(reindex);
#endif
                        if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
                        	fprintf(stderr,"Could not delete statement for store '%s': %s\n", (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->o_connections));
                        	return -1;
			} else {
				return 1;
				};
                        };
#ifdef RDFSTORE_DEBUG
		printf("DELETED (%d) o_connections for O '%s'\n", st_id, (statement->object->type != 1) ? statement->object->value.resource.identifier : statement->object->value.literal.string);
#endif
		};

#endif /* RDFSTORE_CONNECTIONS */

	if (context != NULL) {
		/* context */
		packInt(context->hashcode, outbuf);
		key.data = outbuf;
		key.size = sizeof(int);

		/*
		 * bzero(me->bits_encode,sizeof(me->bits_encode));
		 * bzero(me->bits_decode,sizeof(me->bits_decode));
		 */

		err = rdfstore_flat_store_fetch_compressed(me->contexts, me->func_decode, key, &outsize, me->bits_decode);
		if (err != 0) {
			if (err != FLAT_STORE_E_NOTFOUND) {
				perror("rdfstore_remove");
				fprintf(stderr,"Could not fetch key '%s' in contexts for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->contexts));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
			} else {
				outsize = 0;
			};
		};

		/* reset the right bit to zero */
		rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 0, sizeof(me->bits_decode));
		outsize = rdfstore_bits_shorten(outsize, me->bits_decode);
		if ( outsize > 0 ) {
			err = rdfstore_flat_store_store_compressed(me->contexts, me->func_encode,
				key, outsize,me->bits_decode,me->bits_encode);
			if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
				fprintf(stderr,"Stored %d bytes for '%s' in contexts for store '%s'\n", outsize, (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)");
#endif
			} else {
				if (err != FLAT_STORE_E_KEYEXIST) {
					perror("rdfstore_remove");
					fprintf(stderr,"Could not store '%d' bytes in contexts for store '%s': %s\n", (int)data.size, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->contexts));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
					rdfstore_iterator_close(reindex);
#endif
					return -1;
					};
				};

#ifdef RDFSTORE_DEBUG
				{
				int             i;
				if ((rdfstore_flat_store_fetch(me->contexts, key, &data)) == 0) {
					me->func_decode(data.size, data.data, &outsize, me->bits_decode);
					RDFSTORE_FREE(data.data);
				};
				printf("REMOVED st_num=%d bitno=%d contexts for C -->'", st_id, st_id);
				for(i=0;i<8*outsize;i++) {
					printf("Rec %d %c\n", i, (me->bits_decode[i>>3] & (1<<(i&7))) ? '1':'0');
                                               };
				printf("'\n");
				}
#endif
		} else {
			err = rdfstore_flat_store_delete(me->contexts, key);
			if (err != 0) {
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
                        	rdfstore_iterator_close(reindex);
#endif
				if (err != FLAT_STORE_E_NOTFOUND) {
                        		perror("rdfstore_remove");
                        		fprintf(stderr,"Could not delete statement for store '%s': %s\n", (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->contexts));
                        		return -1;
				} else {
					return 1;
					};
                        	};
#ifdef RDFSTORE_DEBUG
			printf("DELETED (%d) contexts for C\n", st_id);
#endif
		};
	};

	/* remove special literal stuff */
	if (statement->object->type == 1) {
		if (	(me->freetext) &&
		    	(statement->object->value.literal.string != NULL) &&
			(statement->object->value.literal.string_len > 0) ) {
			utf8_casefolded_buff = (unsigned char *)RDFSTORE_MALLOC(statement->object->value.literal.string_len * sizeof(unsigned char) * (RDFSTORE_UTF8_MAXLEN_FOLD + 1));	/* what about the ending '\0' here ?? */
			if (utf8_casefolded_buff == NULL) {
				perror("rdfstore_remove");
				fprintf(stderr,"Cannot compute case-folded string out of input literal for store '%s'\n", (me->name != NULL) ? me->name : "(in-memory)");
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			if (rdfstore_utf8_string_to_utf8_foldedcase(statement->object->value.literal.string_len, statement->object->value.literal.string, &utf8_size, utf8_casefolded_buff)) {
				perror("rdfstore_remove");
				fprintf(stderr,"Cannot compute case-folded string out of input literal for store '%s'\n", (me->name != NULL) ? me->name : "(in-memory)");
				RDFSTORE_FREE(utf8_casefolded_buff);
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};

			for (	word = strtok(utf8_casefolded_buff, sep);
		     		word;
		     		word = strtok(NULL, sep) ) {
				int jj=0;
				int kk=0;

				key.data = word;
				key.size = strlen(word);
				err = rdfstore_flat_store_fetch_compressed(me->windex, me->func_decode, key, &outsize, me->bits_decode);
				if (err != 0) {
					if (err != FLAT_STORE_E_NOTFOUND) {
						RDFSTORE_FREE(utf8_casefolded_buff);
						perror("rdfstore_remove");
						fprintf(stderr,"Could not fetch windex of word '%s' for store '%s': %s\n", word, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->windex));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
						rdfstore_iterator_close(reindex);
#endif
						return -1;
					} else {
						outsize = 0;
						};
					};

				/*
				NOTE: perhaps the code below should be substituted as in the above other single-bit tables with

				rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 0, sizeof(me->bits_decode));

                		outsize = rdfstore_bits_shorten(outsize, me->bits_decode);
				*/

				/*
			 	 * match stuff for literal words - we have one bit
			 	 * only for free-text then we use
			 	 * rdfstore_bits_getfirstsetafter()
			 	*/
				pos = 0;
				if ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < outsize * 8)	/* matched once */
					pos++;	/* hop to the next record */
				if ((pos < outsize * 8) &&
			    		((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < outsize * 8)) {	/* matched more the one
															 * record */
#ifdef RDFSTORE_DEBUG
					fprintf(stderr,"object literal word '%s' matched TWICE at pos=%d\n", word, pos);
#endif
					/* reset the right bit to zero */
					rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 0, sizeof(me->bits_decode));
					if (outsize) {
						err = rdfstore_flat_store_store_compressed(me->windex, me->func_encode,key, outsize, me->bits_decode,me->bits_encode);
						if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
							fprintf(stderr,"Stored %d bytes for '%s' in windex for store '%s'\n", outsize, (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)");
#endif
						} else {
							if (err != FLAT_STORE_E_KEYEXIST) {
								RDFSTORE_FREE(utf8_casefolded_buff);
								perror("rdfstore_remove");
								fprintf(stderr,"Could not store '%d' bytes for word '%s' in windex for store '%s': %s\n", (int)data.size, word, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->windex));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
								rdfstore_iterator_close(reindex);
#endif
								return -1;
								};
							};

#ifdef RDFSTORE_DEBUG
						{
						int             i;
						if ((rdfstore_flat_store_fetch(me->windex, key, &data)) == 0) {
							me->func_decode(data.size, data.data, &outsize, me->bits_decode);
							RDFSTORE_FREE(data.data);
						};
						printf("REMOVED (%d) windex for case-folded word '%s' -->'", st_id, word);
						for(i=0;i<8*outsize;i++) {
							printf("Rec %d %c\n", i, (me->bits_decode[i>>3] & (1<<(i&7))) ? '1':'0');
                                                        };
						printf("'\n");
						}
#endif

						};
				} else {
					err = rdfstore_flat_store_delete(me->windex, key);
					/* 	due that words and stems can be duplicated into the same literal we 
						do not check if FLAT_STORE_E_NOTFOUND which means several delete operation might
						be failing for the same literal - this could be avoided by checking duplicates
						of words and stems into the input string */
					if (err != 0) {
						if (err != FLAT_STORE_E_NOTFOUND) {
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
                        				rdfstore_iterator_close(reindex);
#endif
							perror("rdfstore_remove");
							fprintf(stderr,"Could not delete statement for store '%s': %s\n", (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->windex));
                        				return -1;
							};
                        			};
#ifdef RDFSTORE_DEBUG
					printf("DELETED (%d) windex for case-folded word '%s'\n", st_id, word);
#endif
					};

#if RDFSTORE_WORD_STEMMING > 0

				if(	( rdfstore_xsd_deserialize_integer( word, &thelval ) ) ||
					( rdfstore_xsd_deserialize_double( word, &thedval )  ) ||
					( rdfstore_xsd_deserialize_dateTime(	word,
										&thedateval_tm ) ) ||
					( rdfstore_xsd_deserialize_date(	word,
										&thedateval_tm ) ) || /* dates are skipped, even if rdf:datatype is not set */
					(strlen(word)<=1) )
					continue;

                        	/* for efficency we should check if the given partial stem has been already indexed for the same word!!! */
                        	jj=1;
                        	while ( ( jj < strlen(word) ) &&
                                	( kk < RDFSTORE_WORD_STEMMING ) ) {
                                	char stem[MIN((RDFSTORE_WORD_STEMMING*RDFSTORE_UTF8_MAXLEN_FOLD),strlen(word))+1];

                                	bzero(stem,MIN((RDFSTORE_WORD_STEMMING*RDFSTORE_UTF8_MAXLEN_FOLD),strlen(word))+1);

                                	/* look for next utf8 char to add to stemming string */
                                	utf8_size=0;
                                	while ( ( jj < strlen(word) ) &&
                                        	(!( rdfstore_utf8_is_utf8( word+jj, &utf8_size ) )) ) {
                                        	jj++;
                                        	};

                                	if (jj>strlen(word)) {
                                        	strncpy(stem, word, jj-1);
                                	} else {
                                        	strncpy(stem, word, jj);
                                        	};

                                	key.data = stem;
                                	key.size = strlen(stem);

					err = rdfstore_flat_store_fetch_compressed(me->windex, me->func_decode, key, &outsize, me->bits_decode);
					if (err != 0) {
						if (err != FLAT_STORE_E_NOTFOUND) {
							RDFSTORE_FREE(utf8_casefolded_buff);
							perror("rdfstore_remove");
							fprintf(stderr,"Could not fetch windex for stemming '%s' of word '%s' for store '%s': %s\n", stem, word, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->windex));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
							rdfstore_iterator_close(reindex);
#endif
							return -1;
						} else {
							outsize = 0;
							};
						};
					/*
					NOTE: perhaps the code below should be substituted as in the above other single-bit tables with

					rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 0, sizeof(me->bits_decode));

                			outsize = rdfstore_bits_shorten(outsize, me->bits_decode);
					*/

					/*
			 		 * match stuff for literal words - we have one bit
			 		 * only for free-text then we use
			 		 * rdfstore_bits_getfirstsetafter()
			 		 */
					pos = 0;
					if ((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < outsize * 8)	/* matched once */
						pos++;	/* hop to the next record */
					if ((pos < outsize * 8) &&
			    			((pos = rdfstore_bits_getfirstsetafter(outsize, me->bits_decode, pos)) < outsize * 8)) {	/* matched more the one
															 		* record */
#ifdef RDFSTORE_DEBUG
						fprintf(stderr,"object literal stem '%s' matched TWICE at pos=%d\n", word, pos);
#endif
						/* reset the right bit to zero */
						rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 0, sizeof(me->bits_decode));
						if (outsize) {
							err = rdfstore_flat_store_store_compressed(me->windex, me->func_encode, 
								key, outsize, me->bits_decode, me->bits_encode);
							if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
								fprintf(stderr,"Stored %d bytes for stemming '%s' in windex for store '%s'\n", outsize, (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)");
#endif
							} else {
								if (err != FLAT_STORE_E_KEYEXIST) {
									RDFSTORE_FREE(utf8_casefolded_buff);
									perror("rdfstore_remove");
									fprintf(stderr,"Could not store '%d' bytes for stemming '%s' of word '%s' in windex for store '%s': %s\n", (int)data.size, stem, word, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->windex));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
									rdfstore_iterator_close(reindex);
#endif
									return -1;
									};
								};

#ifdef RDFSTORE_DEBUG
							{
							int             i;
							if ((rdfstore_flat_store_fetch(me->windex, key, &data)) == 0) {
								me->func_decode(data.size, data.data, &outsize, me->bits_decode);
								RDFSTORE_FREE(data.data);
								};
							printf("REMOVED (%d) windex for case-folded stemming '%s' of word '%s' -->'", st_id, stem, word);
							for (i = 0; i < outsize; i++) {
								printf("%02X", me->bits_decode[i]);
								};
							printf("'\n");
							}
#endif

							};
					} else {
						err = rdfstore_flat_store_delete(me->windex, key);
						if (err != 0) {
							/* 	due that words and stems can be duplicated into the same literal we 
								do not check if FLAT_STORE_E_NOTFOUND which means several delete operation might
								be failing for the same literal - this could be avoided by checking duplicates
								of words and stems into the input string */
							if (err != FLAT_STORE_E_NOTFOUND) {
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
                        					rdfstore_iterator_close(reindex);
#endif
								perror("rdfstore_remove");
								fprintf(stderr,"Could not delete statement for store '%s': %s\n", (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->windex));
                        					return -1;
								};
                        				};
#ifdef RDFSTORE_DEBUG
						printf("DELETED (%d) windex for case-folded stem '%s'\n", st_id, word);
#endif
						};
					jj++;
					kk++;
					};
#endif

				};
			RDFSTORE_FREE(utf8_casefolded_buff);
			};

		/* languages table */
		if (	(statement->object->value.literal.lang != NULL) &&
			(strlen(statement->object->value.literal.lang) > 0) ) {
			utf8_casefolded_buff = (unsigned char *)RDFSTORE_MALLOC(strlen(statement->object->value.literal.lang) * sizeof(unsigned char) * (RDFSTORE_UTF8_MAXLEN_FOLD + 1));
			if (utf8_casefolded_buff == NULL) {
				perror("rdfstore_remove");
				fprintf(stderr,"Cannot compute case-folded string out of input literal language for store '%s'\n", (me->name != NULL) ? me->name : "(in-memory)");
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};
			if (rdfstore_utf8_string_to_utf8_foldedcase(strlen(statement->object->value.literal.lang), statement->object->value.literal.lang, &utf8_size, utf8_casefolded_buff)) {
				perror("rdfstore_remove");
				fprintf(stderr,"Cannot compute case-folded string out of input literal language for store '%s'\n", (me->name != NULL) ? me->name : "(in-memory)");
				RDFSTORE_FREE(utf8_casefolded_buff);
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
				rdfstore_iterator_close(reindex);
#endif
				return -1;
				};

			key.data = utf8_casefolded_buff;
			key.size = utf8_size;

			err = rdfstore_flat_store_fetch_compressed(me->languages, me->func_decode, key, &outsize, me->bits_decode);
			if (err != 0) {
				if (err != FLAT_STORE_E_NOTFOUND) {
					RDFSTORE_FREE(utf8_casefolded_buff);
					perror("rdfstore_remove");
					fprintf(stderr,"Could not fetch language '%s' of literal '%s' for store '%s': %s\n", statement->object->value.literal.lang, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me-...
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
					rdfstore_iterator_close(reindex);
#endif
					return -1;
				} else {
					outsize = 0;
					};
				};

			/* reset the right bit to zero */
			rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 0, sizeof(me->bits_decode));

                	outsize = rdfstore_bits_shorten(outsize, me->bits_decode);
			if (outsize) {
				err = rdfstore_flat_store_store_compressed(me->languages, me->func_encode, 
							key, outsize, me->bits_decode, me->bits_encode);
				if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
					fprintf(stderr,"Stored %d bytes for language '%s' in languages for store '%s'\n", outsize, (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)");
#endif
				} else {
					if (err != FLAT_STORE_E_KEYEXIST) {
						RDFSTORE_FREE(utf8_casefolded_buff);
						perror("rdfstore_remove");
						fprintf(stderr,"Could not store '%d' bytes for language '%s' of literal '%s' in languages for store '%s': %s\n", (int)data.size, statement->object->value.literal.lang, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(i...
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
						rdfstore_iterator_close(reindex);
#endif
						return -1;
						};
					};

#ifdef RDFSTORE_DEBUG
				{
				int             i;
				if ((rdfstore_flat_store_fetch(me->languages, key, &data)) == 0) {
					me->func_decode(data.size, data.data, &outsize, me->bits_decode);
					RDFSTORE_FREE(data.data);
				};
				printf("REMOVED (%d) language '%s' of literal '%s' -->'", st_id, statement->object->value.literal.lang, statement->object->value.literal.string);
				for (i = 0; i < outsize; i++) {
					printf("%02X", me->bits_decode[i]);
				};
				printf("'\n");
				}
#endif
			} else {
				err = rdfstore_flat_store_delete(me->languages, key);
				if (err != 0) {
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
                        		rdfstore_iterator_close(reindex);
#endif
					if (err != FLAT_STORE_E_NOTFOUND) {
						perror("rdfstore_remove");
						fprintf(stderr,"Could not delete statement for store '%s': %s\n", (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->languages));
               					return -1;
					} else {
						return 1;
						};
               				};
#ifdef RDFSTORE_DEBUG
				printf("DELETED (%d) languages for case-folded literal language '%s'\n", st_id, statement->object->value.literal.lang);
#endif
				};

			RDFSTORE_FREE(utf8_casefolded_buff);
			};

		/* datatypes table */
		if (	(statement->object->value.literal.dataType != NULL) &&
			(strlen(statement->object->value.literal.dataType) > 0) ) {
			key.data = statement->object->value.literal.dataType;
			key.size = strlen(statement->object->value.literal.dataType);

			err = rdfstore_flat_store_fetch_compressed(me->datatypes, me->func_decode, key, &outsize, me->bits_decode);
			if (err != 0) {
				if (err != FLAT_STORE_E_NOTFOUND) {
					perror("rdfstore_remove");
					fprintf(stderr,"Could not fetch datatype '%s' of literal '%s' for store '%s': %s\n", statement->object->value.literal.dataType, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error...
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
					rdfstore_iterator_close(reindex);
#endif
					return -1;
				} else {
					outsize = 0;
					};
				};

			/* reset the right bit to zero */
			rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 0, sizeof(me->bits_decode));

                	outsize = rdfstore_bits_shorten(outsize, me->bits_decode);
			if (outsize) {
				err = rdfstore_flat_store_store_compressed(me->datatypes, me->func_encode, 
							key, outsize, me->bits_decode, me->bits_encode);
				if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
					fprintf(stderr,"Stored %d bytes for datatype '%s' in datatypes for store '%s'\n", outsize, (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)");
#endif
				} else {
					if (err != FLAT_STORE_E_KEYEXIST) {
						perror("rdfstore_remove");
						fprintf(stderr,"Could not store '%d' bytes for datatype '%s' of literal '%s' in datatypes for store '%s': %s\n", (int)data.size, statement->object->value.literal.dataType, statement->object->value.literal.string, (me->name != NULL) ? me->name :...
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
						rdfstore_iterator_close(reindex);
#endif
						return -1;
						};
					};

#ifdef RDFSTORE_DEBUG
				{
				int             i;
				if ((rdfstore_flat_store_fetch(me->datatypes, key, &data)) == 0) {
					me->func_decode(data.size, data.data, &outsize, me->bits_decode);
					RDFSTORE_FREE(data.data);
				};
				printf("REMOVED (%d) datatype '%s' of literal '%s' -->'", st_id, statement->object->value.literal.dataType, statement->object->value.literal.string);
				for (i = 0; i < outsize; i++) {
					printf("%02X", me->bits_decode[i]);
				};
				printf("'\n");
				}
#endif
			} else {
				err = rdfstore_flat_store_delete(me->datatypes, key);
				if (err != 0) {
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
                        		rdfstore_iterator_close(reindex);
#endif
					if (err != FLAT_STORE_E_NOTFOUND) {
						perror("rdfstore_remove");
						fprintf(stderr,"Could not delete statement for store '%s': %s\n", (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->datatypes));
               					return -1;
					} else {
						return 1;
						};
               				};
#ifdef RDFSTORE_DEBUG
				printf("DELETED (%d) datatypes literal datatype '%s'\n", st_id, statement->object->value.literal.dataType);
#endif
				};

			/* date type indexing only if rdf:datatype is set accordingly to xsd:date or xsd:dateTime */
                        if(     (strcmp(statement->object->value.literal.dataType,RDFSTORE_MS_XSD_DATE)==0) ||
                                (strcmp(statement->object->value.literal.dataType,RDFSTORE_MS_XSD_DATETIME)==0) ) {
                                if(	( rdfstore_xsd_deserialize_dateTime(	statement->object->value.literal.string,
										&thedateval_tm ) ) ||
					( rdfstore_xsd_deserialize_date(	statement->object->value.literal.string,
										&thedateval_tm ) ) ) {

					rdfstore_xsd_serialize_dateTime( thedateval_tm, thedateval ); /* we index xsd:dataTime version anyway */

                                        key.data = thedateval;
                                        key.size = strlen(thedateval)+1;

#ifdef RDFSTORE_DEBUG
fprintf(stderr, "REMOVE DATE '%s' for LITERAL '%s' \n", thedateval, statement->object->value.literal.string);
#endif

					err = rdfstore_flat_store_fetch_compressed(me->xsd_date, me->func_decode, key, &outsize, me->bits_decode);
					if (err != 0) {
						if (err != FLAT_STORE_E_NOTFOUND) {
							perror("rdfstore_remove");
							fprintf(stderr,"Could not fetch date '%ld' of literal '%s' for store '%s': %s\n", thedateval, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->xsd_date));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
							rdfstore_iterator_close(reindex);
#endif
							return -1;
						} else {
							outsize = 0;
							};
						};

					/* reset the right bit to zero */
					rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 0, sizeof(me->bits_decode));

                			outsize = rdfstore_bits_shorten(outsize, me->bits_decode);
					if (outsize) {
						err = rdfstore_flat_store_store_compressed(me->xsd_date, me->func_encode, 
									key, outsize, me->bits_decode, me->bits_encode);
						if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
							fprintf(stderr,"Stored %d bytes for date '%s' in date table for store '%s'\n", outsize, thedateval, (me->name != NULL) ? me->name : "(in-memory)");
#endif
						} else {
							if (err != FLAT_STORE_E_KEYEXIST) {
								perror("rdfstore_remove");
								fprintf(stderr,"Could not store '%d' bytes for date '%s' of literal '%s' in date table for store '%s': %s\n", (int)data.size, thedateval, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_st...
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
								rdfstore_iterator_close(reindex);
#endif
								return -1;
								};
							};

#ifdef RDFSTORE_DEBUG
						{
						int             i;
						if ((rdfstore_flat_store_fetch(me->xsd_date, key, &data)) == 0) {
							me->func_decode(data.size, data.data, &outsize, me->bits_decode);
							RDFSTORE_FREE(data.data);
							};
						printf("REMOVED (%d) date '%s' of literal '%s' -->'", st_id, thedateval, statement->object->value.literal.string);
						for (i = 0; i < outsize; i++) {
							printf("%02X", me->bits_decode[i]);
							};
						printf("'\n");
						}
#endif
					} else {
						err = rdfstore_flat_store_delete(me->xsd_date, key);
						if (err != 0) {
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
                        				rdfstore_iterator_close(reindex);
#endif
							if (err != FLAT_STORE_E_NOTFOUND) {
								perror("rdfstore_remove");
								fprintf(stderr,"Could not delete statement for store '%s': %s\n", (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->xsd_date));
               							return -1;
							} else {
								return 1;
								};
               						};
#ifdef RDFSTORE_DEBUG
						printf("DELETED (%d) date table date '%s'\n", st_id, thedateval);
#endif
						};
					};
				}; /* end of date indexing */

			};

		/* for xsd:integer alike literals use special b-tree sorted index if strtol() works.... */
		if( ( islval = rdfstore_xsd_deserialize_integer( statement->object->value.literal.string, &thelval ) ) != 0 ) {
			key.data = (long*) &thelval; /* should pack int perhaps... */
			key.size = sizeof(long);

#ifdef RDFSTORE_DEBUG
fprintf(stderr, "REMOVE INTEGER '%ld' for LITERAL '%s' \n",(long)thelval, statement->object->value.literal.string);
#endif

			err = rdfstore_flat_store_fetch_compressed(me->xsd_integer, me->func_decode, key, &outsize, me->bits_decode);
			if (err != 0) {
				if (err != FLAT_STORE_E_NOTFOUND) {
					perror("rdfstore_remove");
					fprintf(stderr,"Could not fetch integer '%ld' of literal '%s' for store '%s': %s\n", (long)thelval, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->xsd_integer));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
					rdfstore_iterator_close(reindex);
#endif
					return -1;
				} else {
					outsize = 0;
					};
				};

			/* reset the right bit to zero */
			rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 0, sizeof(me->bits_decode));

                	outsize = rdfstore_bits_shorten(outsize, me->bits_decode);
			if (outsize) {
				err = rdfstore_flat_store_store_compressed(me->xsd_integer, me->func_encode, 
							key, outsize, me->bits_decode, me->bits_encode);
				if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
					fprintf(stderr,"Stored %d bytes for integer '%ld' in integer table for store '%s'\n", outsize, (long)thelval, (me->name != NULL) ? me->name : "(in-memory)");
#endif
				} else {
					if (err != FLAT_STORE_E_KEYEXIST) {
						perror("rdfstore_remove");
						fprintf(stderr,"Could not store '%d' bytes for integer '%ld' of literal '%s' in integer table for store '%s': %s\n", (int)data.size, (long)thelval, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)", rdfstore...
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
						rdfstore_iterator_close(reindex);
#endif
						return -1;
						};
					};

#ifdef RDFSTORE_DEBUG
				{
				int             i;
				if ((rdfstore_flat_store_fetch(me->xsd_integer, key, &data)) == 0) {
					me->func_decode(data.size, data.data, &outsize, me->bits_decode);
					RDFSTORE_FREE(data.data);
				};
				printf("REMOVED (%d) integer '%ld' of literal '%s' -->'", st_id, (long)thelval, statement->object->value.literal.string);
				for (i = 0; i < outsize; i++) {
					printf("%02X", me->bits_decode[i]);
				};
				printf("'\n");
				}
#endif
			} else {
				err = rdfstore_flat_store_delete(me->xsd_integer, key);
				if (err != 0) {
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
                        		rdfstore_iterator_close(reindex);
#endif
					if (err != FLAT_STORE_E_NOTFOUND) {
						perror("rdfstore_remove");
						fprintf(stderr,"Could not delete statement for store '%s': %s\n", (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->xsd_integer));
               					return -1;
					} else {
						return 1;
						};
               				};
#ifdef RDFSTORE_DEBUG
				printf("DELETED (%d) integer table integer '%ld'\n", st_id, (long)thelval);
#endif
				};
			};

		/* for xsd:double or xsd:float alike literals use special b-tree sorted index if strtod() works.... */
		if(	( islval == 0 ) && /* do not index xsd:integer(s) twice also as xsd:double */
			( ( isdval = rdfstore_xsd_deserialize_double( statement->object->value.literal.string, &thedval ) ) != 0 ) ) {
			key.data = (double*) &thedval; /* should pack int perhaps... */
			key.size = sizeof(double);

#ifdef RDFSTORE_DEBUG
fprintf(stderr, "REMOVE DOUBLE '%f' for LITERAL '%s' \n",thedval, statement->object->value.literal.string);
#endif

			err = rdfstore_flat_store_fetch_compressed(me->xsd_double, me->func_decode, key, &outsize, me->bits_decode);
			if (err != 0) {
				if (err != FLAT_STORE_E_NOTFOUND) {
					perror("rdfstore_remove");
					fprintf(stderr,"Could not fetch double '%f' of literal '%s' for store '%s': %s\n", thedval, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->xsd_double));
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
					rdfstore_iterator_close(reindex);
#endif
					return -1;
				} else {
					outsize = 0;
					};
				};

			/* reset the right bit to zero */
			rdfstore_bits_setmask(&outsize, me->bits_decode, st_id, 1, 0, sizeof(me->bits_decode));

                	outsize = rdfstore_bits_shorten(outsize, me->bits_decode);
			if (outsize) {
				err = rdfstore_flat_store_store_compressed(me->xsd_double, me->func_encode, 
							key, outsize, me->bits_decode, me->bits_encode);
				if (err == 0) {
#ifdef RDFSTORE_DEBUG_COMPRESSION
					fprintf(stderr,"Stored %d bytes for double '%f' in double table for store '%s'\n", outsize, thedval, (me->name != NULL) ? me->name : "(in-memory)");
#endif
				} else {
					if (err != FLAT_STORE_E_KEYEXIST) {
						perror("rdfstore_remove");
						fprintf(stderr,"Could not store '%d' bytes for double '%f' of literal '%s' in double table for store '%s': %s\n", (int)data.size, thedval, statement->object->value.literal.string, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_sto...
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
						rdfstore_iterator_close(reindex);
#endif
						return -1;
						};
					};

#ifdef RDFSTORE_DEBUG
				{
				int             i;
				if ((rdfstore_flat_store_fetch(me->xsd_double, key, &data)) == 0) {
					me->func_decode(data.size, data.data, &outsize, me->bits_decode);
					RDFSTORE_FREE(data.data);
				};
				printf("REMOVED (%d) double '%f' of literal '%s' -->'", st_id, thedval, statement->object->value.literal.string);
				for (i = 0; i < outsize; i++) {
					printf("%02X", me->bits_decode[i]);
				};
				printf("'\n");
				}
#endif
			} else {
				err = rdfstore_flat_store_delete(me->xsd_double, key);
				if (err != 0) {
#if defined(RDFSTORE_CONNECTIONS) && defined(RDFSTORE_CONNECTIONS_REINDEXING)
                        		rdfstore_iterator_close(reindex);
#endif
					if (err != FLAT_STORE_E_NOTFOUND) {
						perror("rdfstore_remove");
						fprintf(stderr,"Could not delete statement for store '%s': %s\n", (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->xsd_double));
               					return -1;
					} else {
						return 1;
						};
               				};
#ifdef RDFSTORE_DEBUG
				printf("DELETED (%d) double table double '%f'\n", st_id, thedval);
#endif
				};
			};

		}; /* end remove special literal stuff */

	/* removed one statement */
	key.data = RDFSTORE_COUNTER_REMOVED_KEY;
        key.size = sizeof(RDFSTORE_COUNTER_REMOVED_KEY);
	if ((rdfstore_flat_store_inc(me->model, key, &data)) != 0) {

rdfstore_kernel.c  view on Meta::CPAN

};

/* return 0 if the store is empty */
int 
rdfstore_is_empty(
		  rdfstore * me
)
{
	unsigned int    size;

	if (rdfstore_size(me, &size)) {
		perror("rdfstore_is_empty");
		fprintf(stderr,"Could carry out model size for store '%s'\n", (me->name != NULL) ? me->name : "(in-memory)");
		return -1;
	};

	return (size > 0) ? 1 : 0;
};

/*
 * return a statement iterator; the returned object must be garbage-collected
 * by the caller via rdfstore_iterator_close()
 */
rdfstore_iterator *
rdfstore_elements(
		  rdfstore * me
)
{
	rdfstore_iterator *cursor;
	DBT             key, data;
	int             retval = 0;
	unsigned int    st_id = 0;

	memset(&key, 0, sizeof(key));
	memset(&data, 0, sizeof(data));

	cursor = (rdfstore_iterator *) RDFSTORE_MALLOC(sizeof(rdfstore_iterator));
	if (cursor == NULL) {
		perror("rdfstore_elements");
		fprintf(stderr,"Cannot create elements cursor/iterator for store '%s'\n", (me->name != NULL) ? me->name : "(in-memory)");
		return NULL;
	};
	cursor->store = me;
	me->attached++;

	/* bzero(cursor->ids,sizeof(unsigned char)*(RDFSTORE_MAXRECORDS_BYTES_SIZE)); */
	cursor->size = 0;
	cursor->remove_holes = 0;	/* reset the total of holes */
	cursor->st_counter = 0;
	cursor->pos = 0;
	cursor->ids_size = 0;

	if (rdfstore_flat_store_first(me->statements, &key) == 0) {
		do {
			retval = 0;
			if (rdfstore_flat_store_fetch(me->statements, key, &data) == 0) {
				unpackInt(data.data, &st_id);
				RDFSTORE_FREE(data.data);

				/*
				 * not sure rdfstore_bits_setmask() actually
				 * sets ids_size right.....
				 */
				rdfstore_bits_setmask(&cursor->ids_size, cursor->ids, st_id, 1, 1, sizeof(cursor->ids));

				cursor->size++;
			} else {
				RDFSTORE_FREE(key.data);
				RDFSTORE_FREE(cursor);
				perror("rdfstore_elements");
				fprintf(stderr,"Could not fetch key '%s' in statements for store '%s': %s\n", (char *)key.data, (me->name != NULL) ? me->name : "(in-memory)", rdfstore_flat_store_get_error(me->statements));
				return NULL;
			};
			/* set the right bit */
			retval = rdfstore_flat_store_next(me->statements, key, &data);
			RDFSTORE_FREE(key.data);	/* dispose the key
							 * fetched above */
			if (retval == 0) {
				key = rdfstore_flat_store_kvdup(me->statements, data);
				RDFSTORE_FREE(data.data);
			};
		} while (retval == 0);
	};

#ifdef RDFSTORE_DEBUG
	{
		register int    i;
		printf("Actually matched (bits only) '");
		for(i=0;i<8*cursor->ids_size;i++) {
                        printf("%c", (cursor->ids[i>>3] & (1<<(i&7))) ? '1':'0');
                        };
		printf("' (%d)\n", cursor->ids_size);
	}
#endif

	return cursor;
};

#ifndef packInt
/* pack the integer */
void
packInt(uint32_t value, unsigned char *buffer)
{
        /* bzero(buffer, sizeof(int)); */
        *(uint32_t *)buffer=htonl(value);
}
#endif

#ifndef unpackInt
/* unpack the integer */
void
unpackInt(unsigned char *buffer, uint32_t * value)
{
        *value = ntohl(*(uint32_t *)buffer);
}
#endif

/* core API implementation */

/* see http://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-NCName */
int _rdfstore_is_xml_name(
	unsigned char * name_char ) {

        if (    ( ! isalpha((int)*name_char) ) &&



( run in 0.885 second using v1.01-cache-2.11-cpan-39bf76dae61 )