RDFStore
view release on metacpan or search on metacpan
rdfstore_bits.c view on Meta::CPAN
#
# 6. Products derived from this software may not be called "RDFStore"
# nor may "RDFStore" appear in their names without prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
#
# ====================================================================
#
# This software consists of work developed by Alberto Reggiori and
# Dirk-Willem van Gulik. The RDF specific part is based based on public
# domain software written at the Stanford University Database Group by
# Sergey Melnik. For more information on the RDF API Draft work,
# please see <http://www-db.stanford.edu/~melnik/rdf/api.html>
# The DBMS TCP/IP server part is based on software originally written
# by Dirk-Willem van Gulik for Web Weaving Internet Engineering m/v Enschede,
# The Netherlands.
#
##############################################################################
$Id: rdfstore_bits.c,v 1.16 2006/06/19 10:10:21 areggiori Exp $
*/
#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>
#include "dbms.h"
#include "dbms_compat.h"
#include "rdfstore.h"
#include "rdfstore_bits.h"
#include "rdfstore_log.h"
/* within p->size / p->bits
* set at -bit- position 'at'
* the masked bits to value
*
* return the modified bits
*/
/*
* #define RDFSTORE_DEBUG_BITS
*/
int rdfstore_bits_setmask(
unsigned int * size,
unsigned char * bits,
unsigned int at,
unsigned int mask,
unsigned int value,
unsigned int max
) {
register int depth,change;
if (mask == 0) return(0);
/* auto extend if needed... */
if ( (at/8) >= *size) {
unsigned int n=*size;
unsigned int s= STEP * ( 1 + at/8/STEP );
if (s>max) {
fprintf(stderr, "Too many bit=%d byte=%d %d of %d\n",
at, at/8, s, max);
exit(1);
};
*size = s;
bzero(bits+n, s-n);
};
/* x x x x x x as stored
* 0 0 1 1 1 0 mask
* 0 0 0 1 1 0 value
*/
mask <<= at % 8;
value <<= at % 8;
at /= 8;
change =0; depth = 0;
do {
register unsigned char d,c;
if (at>=max) {
fprintf(stderr,"Uncontrolled overflow %d of %d\n",
at, max);
exit(1);
};
c = bits[ at ];
d = ( c & (~ mask) ) | value;
if (d != c) {
bits[ at ] = d;
change |= (d ^ c) << depth;
};
at ++;
depth += 8;
mask >>= 8;
value >>= 8;
} while ((mask) && (at < *size ));
return (change);
};
/* Return the record number (bit number / 4) of the
* first record from record 'at' onwards which has
( run in 2.036 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )