Skip to content

Commit

Permalink
Change mapbit.c bitmask type from char to new 32bit ms_bitarray
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/mapserver/trunk@8741 7532c77e-422f-0410-93f4-f0b67bdd69e2
  • Loading branch information
Julien-Samuel Lacroix committed Mar 9, 2009
1 parent 5a57254 commit ef6fa7a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 38 deletions.
48 changes: 27 additions & 21 deletions mapbits.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* *
****************************************************************************** ******************************************************************************
* Copyright (c) 1996-2005 Regents of the University of Minnesota. * Copyright (c) 1996-2005 Regents of the University of Minnesota.
*
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"), * copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation * to deal in the Software without restriction, including without limitation
Expand All @@ -36,24 +36,30 @@ MS_CVSID("$Id$")


#include <limits.h> #include <limits.h>


/* #define msGetBit(array, index) (*((array) + (index)/CHAR_BIT) & ( 1 << ((index) % CHAR_BIT))) */ /*
* Hardcoded size of our bit array.
* See function msGetNextBit for another hardcoded value.
*/
#define MS_ARRAY_BIT 32

/* #define msGetBit(array, index) (*((array) + (index)/MS_ARRAY_BIT) & ( 1 << ((index) % MS_ARRAY_BIT))) */


size_t msGetBitArraySize(int numbits) size_t msGetBitArraySize(int numbits)
{ {
return((numbits + CHAR_BIT - 1) / CHAR_BIT); return((numbits + MS_ARRAY_BIT - 1) / MS_ARRAY_BIT);
} }


char *msAllocBitArray(int numbits) ms_bitarray msAllocBitArray(int numbits)
{ {
char *array = calloc((numbits + CHAR_BIT - 1) / CHAR_BIT, sizeof(char)); ms_bitarray array = calloc((numbits + MS_ARRAY_BIT - 1) / MS_ARRAY_BIT, MS_ARRAY_BIT);


return(array); return(array);
} }


int msGetBit(char *array, int index) int msGetBit(ms_bitarray array, int index)
{ {
array += index / CHAR_BIT; array += index / MS_ARRAY_BIT;
return (*array & (1 << (index % CHAR_BIT))) != 0; /* 0 or 1 */ return (*array & (1 << (index % MS_ARRAY_BIT))) != 0; /* 0 or 1 */
} }


/* /*
Expand All @@ -63,16 +69,16 @@ int msGetBit(char *array, int index)
** If hits end of bitmap without finding set bit, will return -1. ** If hits end of bitmap without finding set bit, will return -1.
** **
*/ */
int msGetNextBit(char *array, int i, int size) { int msGetNextBit(ms_bitarray array, int i, int size) {


register char b; register ms_uint32 b;


while(i < size) { while(i < size) {
b = *(array + (i/CHAR_BIT)); b = *(array + (i/MS_ARRAY_BIT));
if( b && (b >> (i % CHAR_BIT)) ) { if( b && (b >> (i % MS_ARRAY_BIT)) ) {
/* There is something in this byte */ /* There is something in this byte */
/* And it is not to the right of us */ /* And it is not to the right of us */
if( b & ( 1 << (i % CHAR_BIT)) ) { if( b & ( 1 << (i % MS_ARRAY_BIT)) ) {
/* There is something at this bit! */ /* There is something at this bit! */
return i; return i;
} }
Expand All @@ -82,25 +88,25 @@ int msGetNextBit(char *array, int i, int size) {
} }
else { else {
/* Nothing in this byte, move to start of next byte */ /* Nothing in this byte, move to start of next byte */
i += CHAR_BIT - (i % CHAR_BIT); i += MS_ARRAY_BIT - (i % MS_ARRAY_BIT);
} }
} }


/* Got to the last byte with no hits! */ /* Got to the last byte with no hits! */
return -1; return -1;
} }


void msSetBit(char *array, int index, int value) void msSetBit(ms_bitarray array, int index, int value)
{ {
array += index / CHAR_BIT; array += index / MS_ARRAY_BIT;
if (value) if (value)
*array |= 1 << (index % CHAR_BIT); /* set bit */ *array |= 1 << (index % MS_ARRAY_BIT); /* set bit */
else else
*array &= ~(1 << (index % CHAR_BIT)); /* clear bit */ *array &= ~(1 << (index % MS_ARRAY_BIT)); /* clear bit */
} }


void msFlipBit(char *array, int index) void msFlipBit(ms_bitarray array, int index)
{ {
array += index / CHAR_BIT; array += index / MS_ARRAY_BIT;
*array ^= 1 << (index % CHAR_BIT); /* flip bit */ *array ^= 1 << (index % MS_ARRAY_BIT); /* flip bit */
} }
13 changes: 8 additions & 5 deletions mapserver.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ typedef int32_t ms_int32;
typedef uint32_t ms_uint32; typedef uint32_t ms_uint32;
#endif #endif


/* ms_bitarray is used by the bit mask in mapbit.c */
typedef ms_uint32 * ms_bitarray;

#include "maperror.h" #include "maperror.h"
#include "mapprimitive.h" #include "mapprimitive.h"
#include "mapshape.h" #include "mapshape.h"
Expand Down Expand Up @@ -1773,11 +1776,11 @@ MS_DLL_EXPORT int msDrawRasterLayer(mapObj *map, layerObj *layer, imageObj *imag
MS_DLL_EXPORT imageObj *msDrawReferenceMap(mapObj *map); MS_DLL_EXPORT imageObj *msDrawReferenceMap(mapObj *map);


MS_DLL_EXPORT size_t msGetBitArraySize(int numbits); /* in mapbits.c */ MS_DLL_EXPORT size_t msGetBitArraySize(int numbits); /* in mapbits.c */
MS_DLL_EXPORT char *msAllocBitArray(int numbits); MS_DLL_EXPORT ms_bitarray msAllocBitArray(int numbits);
MS_DLL_EXPORT int msGetBit(char *array, int index); MS_DLL_EXPORT int msGetBit(ms_bitarray array, int index);
MS_DLL_EXPORT void msSetBit(char *array, int index, int value); MS_DLL_EXPORT void msSetBit(ms_bitarray array, int index, int value);
MS_DLL_EXPORT void msFlipBit(char *array, int index); MS_DLL_EXPORT void msFlipBit(ms_bitarray array, int index);
MS_DLL_EXPORT int msGetNextBit(char *array, int index, int size); MS_DLL_EXPORT int msGetNextBit(ms_bitarray array, int index, int size);


MS_DLL_EXPORT int msLayerInitItemInfo(layerObj *layer); MS_DLL_EXPORT int msLayerInitItemInfo(layerObj *layer);
MS_DLL_EXPORT void msLayerFreeItemInfo(layerObj *layer); MS_DLL_EXPORT void msLayerFreeItemInfo(layerObj *layer);
Expand Down
4 changes: 2 additions & 2 deletions mapshape.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ typedef struct {


int *panRecOffset; int *panRecOffset;
int *panRecSize; int *panRecSize;
char *panRecLoaded; ms_bitarray panRecLoaded;
int panRecAllLoaded; int panRecAllLoaded;


double adBoundsMin[4]; double adBoundsMin[4];
Expand Down Expand Up @@ -165,7 +165,7 @@ typedef struct {


int lastshape; int lastshape;


char *status; ms_bitarray status;
rectObj statusbounds; /* holds extent associated with the status vector */ rectObj statusbounds; /* holds extent associated with the status vector */


int isopen; int isopen;
Expand Down
14 changes: 7 additions & 7 deletions maptree.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ static int treeAddShapeId(treeObj *tree, int id, rectObj rect)
return(treeNodeAddShapeId(tree->root, id, rect, tree->maxdepth)); return(treeNodeAddShapeId(tree->root, id, rect, tree->maxdepth));
} }


static void treeCollectShapeIds(treeNodeObj *node, rectObj aoi, char *status) static void treeCollectShapeIds(treeNodeObj *node, rectObj aoi, ms_bitarray status)
{ {
int i; int i;


Expand All @@ -404,9 +404,9 @@ static void treeCollectShapeIds(treeNodeObj *node, rectObj aoi, char *status)
} }
} }


char *msSearchTree(treeObj *tree, rectObj aoi) ms_bitarray msSearchTree(treeObj *tree, rectObj aoi)
{ {
char *status=NULL; ms_bitarray status=NULL;


status = msAllocBitArray(tree->numshapes); status = msAllocBitArray(tree->numshapes);
if(!status) { if(!status) {
Expand Down Expand Up @@ -452,7 +452,7 @@ void msTreeTrim(treeObj *tree)
treeNodeTrim(tree->root); treeNodeTrim(tree->root);
} }


static void searchDiskTreeNode(SHPTreeHandle disktree, rectObj aoi, char *status) static void searchDiskTreeNode(SHPTreeHandle disktree, rectObj aoi, ms_bitarray status)
{ {
int i; int i;
ms_int32 offset; ms_int32 offset;
Expand Down Expand Up @@ -507,10 +507,10 @@ static void searchDiskTreeNode(SHPTreeHandle disktree, rectObj aoi, char *status
return; return;
} }


char *msSearchDiskTree(char *filename, rectObj aoi, int debug) ms_bitarray msSearchDiskTree(char *filename, rectObj aoi, int debug)
{ {
SHPTreeHandle disktree; SHPTreeHandle disktree;
char *status=NULL; ms_bitarray status=NULL;


disktree = msSHPDiskTreeOpen (filename, debug); disktree = msSHPDiskTreeOpen (filename, debug);
if(!disktree) { if(!disktree) {
Expand Down Expand Up @@ -763,7 +763,7 @@ int msWriteTree(treeObj *tree, char *filename, int B_order)
} }


/* Function to filter search results further against feature bboxes */ /* Function to filter search results further against feature bboxes */
void msFilterTreeSearch(shapefileObj *shp, char *status, rectObj search_rect) void msFilterTreeSearch(shapefileObj *shp, ms_bitarray status, rectObj search_rect)
{ {
int i; int i;
rectObj shape_rect; rectObj shape_rect;
Expand Down
6 changes: 3 additions & 3 deletions maptree.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ MS_DLL_EXPORT treeObj *msCreateTree(shapefileObj *shapefile, int maxdepth);
MS_DLL_EXPORT void msTreeTrim(treeObj *tree); MS_DLL_EXPORT void msTreeTrim(treeObj *tree);
MS_DLL_EXPORT void msDestroyTree(treeObj *tree); MS_DLL_EXPORT void msDestroyTree(treeObj *tree);


MS_DLL_EXPORT char *msSearchTree(treeObj *tree, rectObj aoi); MS_DLL_EXPORT ms_bitarray msSearchTree(treeObj *tree, rectObj aoi);
MS_DLL_EXPORT char *msSearchDiskTree(char *filename, rectObj aoi, int debug); MS_DLL_EXPORT ms_bitarray msSearchDiskTree(char *filename, rectObj aoi, int debug);


MS_DLL_EXPORT treeObj *msReadTree(char *filename, int debug); MS_DLL_EXPORT treeObj *msReadTree(char *filename, int debug);
MS_DLL_EXPORT int msWriteTree(treeObj *tree, char *filename, int LSB_order); MS_DLL_EXPORT int msWriteTree(treeObj *tree, char *filename, int LSB_order);


MS_DLL_EXPORT void msFilterTreeSearch(shapefileObj *shp, char *status, rectObj search_rect); MS_DLL_EXPORT void msFilterTreeSearch(shapefileObj *shp, ms_bitarray status, rectObj search_rect);


#ifdef __cplusplus #ifdef __cplusplus
} }
Expand Down

0 comments on commit ef6fa7a

Please sign in to comment.