Changeset: 450509095c59 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=450509095c59
Modified Files:
geom/monetdb5/geom.h
geom/monetdb5/geomPoints.c
Branch: geo
Log Message:
pbsmIndex created independently
diffs (truncated from 447 to 300 lines):
diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -270,3 +270,4 @@ geom_export str wkbPointsDistance_geom_b
geom_export str wkbPointsFilter_geom_bat(bat*, wkb**, bat*, bat*, int*
filterVersion);
+geom_export str pbsmIndex_bat(bat* outBAT_id, bat* xBAT_id, bat* yBAT_id,
double* xmin, double* ymin, double* xmax, double* ymax);
diff --git a/geom/monetdb5/geomPoints.c b/geom/monetdb5/geomPoints.c
--- a/geom/monetdb5/geomPoints.c
+++ b/geom/monetdb5/geomPoints.c
@@ -30,9 +30,17 @@ typedef struct pbsm_ptr {
unsigned long count;
} pbsm_ptr;
+typedef struct {
+ double xmin;
+ double ymin;
+ double xmax;
+ double ymax;
+ unsigned int oidsNum;
+} pbsm_info;
+
static pbsm_ptr *pbsm_idx = NULL;
static oid *oids = NULL;
-static mbr *limits = NULL;
+static pbsm_info *limits = NULL;
//hard coded filename
static char* filename = "../pbsmIndex_20m";
@@ -890,7 +898,7 @@ static str wkbPointsFilterWithImprints_g
static str createFilenames(str module) {
char* idxEnding = ".idx";
char* dataEnding = ".data";
- char* limitsEnding =".mbb";
+ char* limitsEnding =".info";
//allocate space for the files
if((idxFilename = (char*)
GDKmalloc(strlen(filename)+strlen(idxEnding)+1)) == NULL) {
@@ -932,7 +940,7 @@ static str allocateStructs(str module, u
return createException(MAL, module, "Problem allocating space
for oids");
}
- if ((limits = (mbr*)GDKmalloc(sizeof(mbr))) == NULL) {
+ if ((limits = (pbsm_info*)GDKmalloc(sizeof(pbsm_info))) == NULL) {
GDKfree(pbsm_idx);
GDKfree(oids);
return createException(MAL, module, "Problem allocating space
for limits");
@@ -943,97 +951,124 @@ static str allocateStructs(str module, u
static str store(str module, unsigned int numberOfOIDs) {
FILE *f;
+ str ret = MAL_SUCCEED;
if ((f = fopen(idxFilename, "wb"))) {
if (fwrite(pbsm_idx, sizeof(pbsm_idx[0]), USHRT_MAX,f) !=
USHRT_MAX) {
fclose(f);
- GDKfree(pbsm_idx);
- GDKfree(oids);
- GDKfree(limits);
- GDKfree(idxFilename);
- GDKfree(dataFilename);
- GDKfree(limitsFilename);
- return createException(MAL, module, "Could not save the
PBSM index to disk (target: %s)", idxFilename);
+ ret = createException(MAL, module, "Could not save the
PBSM index to disk (target: %s)", idxFilename);
+ goto clean;
}
fflush(f);
fclose(f);
+ } else {
+ ret = createException(MAL, module, "Could not open for writting
(target: %s)", idxFilename);
+ goto clean;
}
if ((f = fopen(dataFilename, "wb"))) {
if (fwrite(oids, sizeof(oids[0]), numberOfOIDs, f) !=
numberOfOIDs) {
fclose(f);
- GDKfree(pbsm_idx);
- GDKfree(oids);
- GDKfree(limits);
- GDKfree(idxFilename);
- GDKfree(dataFilename);
- GDKfree(limitsFilename);
- return createException(MAL, module, "Could not save the
PBSM index to disk (target: %s)", dataFilename);
+ ret = createException(MAL, module, "Could not save the
PBSM index to disk (target: %s)", dataFilename);
+ goto clean;
}
fflush(f);
fclose(f);
+ } else {
+ ret = createException(MAL, module, "Could not open for writting
(target: %s)", dataFilename);
+ goto clean;
}
+
if ((f = fopen(limitsFilename, "wb"))) {
if (fwrite(limits, sizeof(*limits), 1, f) != 1) {
fclose(f);
- GDKfree(pbsm_idx);
- GDKfree(oids);
- GDKfree(limits);
- GDKfree(idxFilename);
- GDKfree(dataFilename);
- GDKfree(limitsFilename);
- return createException(MAL, module, "Could not save the
PBSM index to disk (target: %s)", limitsFilename);
+ ret = createException(MAL, module, "Could not save the
PBSM index to disk (target: %s)", limitsFilename);
+ goto clean;
}
fflush(f);
fclose(f);
+ } else {
+ ret = createException(MAL, module, "Could not open for writting
(target: %s)", limitsFilename);
+ goto clean;
}
+
+
+ GDKfree(idxFilename);
+ GDKfree(dataFilename);
+ GDKfree(limitsFilename);
+
return MAL_SUCCEED;
+
+clean:
+ GDKfree(pbsm_idx);
+ GDKfree(oids);
+ GDKfree(limits);
+ GDKfree(idxFilename);
+ GDKfree(dataFilename);
+ GDKfree(limitsFilename);
+
+ return ret;
}
static str load(str module, unsigned int numberOfOIDs, bit* found) {
FILE *f;
+ str ret = MAL_SUCCEED;
*found = 0;
if ((f = fopen(idxFilename, "rb"))) {
*found = 1;
if (fread(pbsm_idx, sizeof(pbsm_idx[0]), USHRT_MAX, f) !=
USHRT_MAX) {
fclose(f);
- GDKfree(pbsm_idx);
- GDKfree(oids);
- GDKfree(limits);
- GDKfree(idxFilename);
- GDKfree(dataFilename);
- GDKfree(limitsFilename);
- return createException(MAL, module, "Could not read the
PBSM index from disk (source: %s)", idxFilename);
+ ret = createException(MAL, module, "Could not read the
PBSM index from disk (source: %s)", idxFilename);
+ goto clean;
}
fclose(f);
if ((f = fopen(dataFilename, "rb"))) {
if (fread(oids, sizeof(oids[0]), numberOfOIDs, f) !=
numberOfOIDs) {
fclose(f);
- GDKfree(pbsm_idx);
- GDKfree(oids);
- GDKfree(limits);
- GDKfree(idxFilename);
- GDKfree(dataFilename);
- GDKfree(limitsFilename);
- return createException(MAL, module, "Could not
read the PBSM index from disk (source: %s)", dataFilename);
+ ret = createException(MAL, module, "Could not
read the PBSM index from disk (source: %s)", dataFilename);
+ goto clean;
}
fclose(f);
} else {
- GDKfree(pbsm_idx);
- GDKfree(oids);
- GDKfree(limits);
- GDKfree(idxFilename);
- GDKfree(dataFilename);
- GDKfree(limitsFilename);
- return createException(MAL, module, "Could not read the
PBSM index (.dat).");
+ ret = createException(MAL, module, "Could not read file
%s.", dataFilename);
+ goto clean;
}
+
+ if ((f = fopen(limitsFilename, "rb"))) {
+ if (fread(limits, sizeof(*limits), 1, f) != 1) {
+ fclose(f);
+ ret = createException(MAL, module, "Could not
read the PBSM index from disk (source: %s)", limitsFilename);
+ goto clean;
+ }
+
+ fclose(f);
+ } else {
+ ret = createException(MAL, module, "Could not read file
%s.", limitsFilename);
+ goto clean;
+ }
+
+ //index has been loaded, files are not needed anymore
+ GDKfree(idxFilename);
+ GDKfree(dataFilename);
+ GDKfree(limitsFilename);
}
+
return MAL_SUCCEED;
+
+clean:
+ GDKfree(pbsm_idx);
+ GDKfree(oids);
+ GDKfree(limits);
+ GDKfree(idxFilename);
+ GDKfree(dataFilename);
+ GDKfree(limitsFilename);
+
+ return ret;
}
static char *
@@ -1112,14 +1147,6 @@ PBSMcomputeindex2(const dbl *x, const db
unsigned long i;
int shift = sizeof(sht) * 8 / 2;
- if ((pbsm_idx = GDKmalloc(USHRT_MAX * sizeof(pbsm_ptr))) == NULL)
- throw(MAL, "pbsm.createindex", MAL_MALLOC_FAIL);
-
- if ((oids = GDKmalloc(n * sizeof(oid))) == NULL) {
- GDKfree(pbsm_idx);
- throw(MAL, "pbsm.createindex", MAL_MALLOC_FAIL);
- }
-
if ((tmpCount = GDKmalloc(USHRT_MAX * sizeof(unsigned long))) == NULL) {
GDKfree(pbsm_idx);
GDKfree(oids);
@@ -1127,13 +1154,14 @@ PBSMcomputeindex2(const dbl *x, const db
}
for (i = 0; i < USHRT_MAX; i++) {
- pbsm_idx[i].count = 0;
- pbsm_idx[i].offset = 0;
+ tmpCount[i] = 0;
}
- for (i = 0; i < USHRT_MAX; i++) {
- tmpCount[i] = 0;
- }
+ limits->xmin = minx;
+ limits->xmax = maxx;
+ limits->ymin = miny;
+ limits->ymax = maxy;
+ limits->oidsNum = n;
// count pbsm values per cell
for (i = 0; i < n; i++) {
@@ -1175,14 +1203,16 @@ PBSMcreateindex (const dbl *x, const dbl
assert (pbsm_idx == NULL && oids == NULL && limits == NULL);
- if((err = createFilenames("batgeom.Filter")) != MAL_SUCCEED) {
- str msg = createException(MAL, "batgeom.Filter", "%s", err);
+ //create the filenames
+ if((err = createFilenames("batgeom.pbsmIndex")) != MAL_SUCCEED) {
+ str msg = createException(MAL, "batgeom.pbsmIndex", "%s", err);
GDKfree(err);
return msg;
}
- if((err = allocateStructs("batgeom.Filter", n)) != MAL_SUCCEED) {
- str msg = createException(MAL, "batgeom.Filter", "%s", err);
+ //allocate memory for the necessary structures
+ if((err = allocateStructs("batgeom.pbsmIndex", n)) != MAL_SUCCEED) {
+ str msg = createException(MAL, "batgeom.pbsmIndex", "%s", err);
GDKfree(err);
GDKfree(idxFilename);
@@ -1196,11 +1226,6 @@ PBSMcreateindex (const dbl *x, const dbl
if((err = load("batgeom.Filter", n, &found)) != MAL_SUCCEED) {
str msg = createException(MAL, "batgeom.Filter", "%s", err);
GDKfree(err);
-
- GDKfree(idxFilename);
- GDKfree(dataFilename);
- GDKfree(limitsFilename);
-
return msg;
}
t = clock() - t;
@@ -1224,69 +1249,15 @@ fprintf(stderr, "Creating index\n");
if((err = store("batgeom.Filter", n)) != MAL_SUCCEED) {
str msg = createException(MAL, "batgeom.Filter", "%s",
err);
GDKfree(err);
-
- GDKfree(pbsm_idx);
- GDKfree(oids);
- GDKfree(limits);
- GDKfree(idxFilename);
- GDKfree(dataFilename);
- GDKfree(limitsFilename);
-
return msg;
}
- }
+fprintf(stderr, "createIndex CREATE: (%f,%f) - (%f, %f) \t %u \n",
limits->xmin, limits->ymin, limits->xmax, limits->ymax, limits->oidsNum);
+
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list