Remove trailing white space from .c files

This commit is contained in:
Paul Ramsey 2013-03-08 13:46:06 -08:00
parent 6bcd483f34
commit 73da920ff0
20 changed files with 551 additions and 551 deletions

View File

@ -20,7 +20,7 @@ static const char *simplexmlfile = "data/simple-schema.xml";
static const char *lasxmlfile = "data/las-schema.xml";
/* Setup/teardown for this suite */
static int
static int
init_suite(void)
{
char *xmlstr = file_to_str(xmlfile);
@ -41,7 +41,7 @@ init_suite(void)
return 0;
}
static int
static int
clean_suite(void)
{
pc_schema_free(schema);
@ -53,14 +53,14 @@ clean_suite(void)
/* TESTS **************************************************************/
static void
test_endian_flip()
static void
test_endian_flip()
{
PCPOINT *pt;
double a1, a2, a3, a4, b1, b2, b3, b4;
int rv;
uint8_t *ptr;
/* All at once */
pt = pc_point_make(schema);
a1 = 1.5;
@ -78,12 +78,12 @@ test_endian_flip()
CU_ASSERT_DOUBLE_EQUAL(a1, b1, 0.0000001);
CU_ASSERT_DOUBLE_EQUAL(a2, b2, 0.0000001);
CU_ASSERT_DOUBLE_EQUAL(a3, b3, 0.0000001);
CU_ASSERT_DOUBLE_EQUAL(a4, b4, 0.0000001);
CU_ASSERT_DOUBLE_EQUAL(a4, b4, 0.0000001);
ptr = uncompressed_bytes_flip_endian(pt->data, schema, 1);
pcfree(pt->data);
pt->data = uncompressed_bytes_flip_endian(ptr, schema, 1);
rv = pc_point_get_double_by_name(pt, "X", &b1);
rv = pc_point_get_double_by_name(pt, "Z", &b2);
rv = pc_point_get_double_by_name(pt, "Intensity", &b3);
@ -91,10 +91,10 @@ test_endian_flip()
CU_ASSERT_DOUBLE_EQUAL(a1, b1, 0.0000001);
CU_ASSERT_DOUBLE_EQUAL(a2, b2, 0.0000001);
CU_ASSERT_DOUBLE_EQUAL(a3, b3, 0.0000001);
CU_ASSERT_DOUBLE_EQUAL(a4, b4, 0.0000001);
CU_ASSERT_DOUBLE_EQUAL(a4, b4, 0.0000001);
}
static void
static void
test_patch_hex_in()
{
// 00 endian (big)
@ -122,13 +122,13 @@ test_patch_hex_in()
pc_pointlist_free(pl);
pc_patch_free(pa);
pcfree(wkb);
pcfree(wkb);
}
/*
* Write an uncompressed patch out to hex
* Write an uncompressed patch out to hex
*/
static void
static void
test_patch_hex_out()
{
// 00 endian
@ -137,11 +137,11 @@ test_patch_hex_out()
// 00000002 npoints
// 0000000200000003000000050006 pt1 (XYZi)
// 0000000200000003000000050008 pt2 (XYZi)
static char *wkt_result = "{\"pcid\":0,\"pts\":[[0.02,0.03,0.05,6],[0.02,0.03,0.05,8]]}";
static char *hexresult_xdr =
static char *hexresult_xdr =
"0000000000000000000000000200000002000000030000000500060000000200000003000000050008";
static char *hexresult_ndr =
static char *hexresult_ndr =
"0100000000000000000200000002000000030000000500000006000200000003000000050000000800";
double d0[4] = { 0.02, 0.03, 0.05, 6 };
@ -150,7 +150,7 @@ test_patch_hex_out()
PCPOINT *pt0 = pc_point_from_double_array(simpleschema, d0, 4);
PCPOINT *pt1 = pc_point_from_double_array(simpleschema, d1, 4);
PCPATCH_UNCOMPRESSED *pa;
PCPATCH_UNCOMPRESSED *pa;
uint8_t *wkb;
size_t wkbsize;
char *hexwkb;
@ -159,7 +159,7 @@ test_patch_hex_out()
PCPOINTLIST *pl = pc_pointlist_make(2);
pc_pointlist_add_point(pl, pt0);
pc_pointlist_add_point(pl, pt1);
pa = pc_patch_uncompressed_from_pointlist(pl);
wkb = pc_patch_uncompressed_to_wkb(pa, &wkbsize);
// printf("wkbsize %zu\n", wkbsize);
@ -176,11 +176,11 @@ test_patch_hex_out()
{
CU_ASSERT_STRING_EQUAL(hexwkb, hexresult_xdr);
}
wkt = pc_patch_uncompressed_to_string(pa);
// printf("wkt %s\n", wkt);
CU_ASSERT_STRING_EQUAL(wkt, wkt_result);
pc_pointlist_free(pl);
pc_patch_uncompressed_free(pa);
pcfree(hexwkb);
@ -191,7 +191,7 @@ test_patch_hex_out()
/*
* Can we read this example point value?
*/
static void
static void
test_schema_xy()
{
/*
@ -199,19 +199,19 @@ test_schema_xy()
25, 1, 1, 1, 0, 1, 6, 124, 7327, 246093, 39, 57, 56, 20, 0, -125.0417204, 49.2540081, 128.85
*/
static char *hexpt = "01010000000AE9C90307A1100522A5000019000101010001067C9F1C4953C474650A0E412700390038001400000000000000876B6601962F750155320000";
uint8_t *bytes = bytes_from_hexbytes(hexpt, strlen(hexpt));
PCPOINT *pt;
double val;
pt = pc_point_from_wkb(lasschema, bytes, strlen(hexpt)/2);
pc_point_get_double_by_name(pt, "x", &val);
CU_ASSERT_DOUBLE_EQUAL(val, -125.0417204, 0.00001);
CU_ASSERT_DOUBLE_EQUAL(val, -125.0417204, 0.00001);
pt = pc_point_from_wkb(lasschema, bytes, strlen(hexpt)/2);
pc_point_get_double_by_name(pt, "y", &val);
CU_ASSERT_DOUBLE_EQUAL(val, 49.2540081, 0.00001);
CU_ASSERT_DOUBLE_EQUAL(val, 49.2540081, 0.00001);
}
static PCBYTES initbytes(uint8_t *bytes, size_t size, uint32_t interp)
@ -230,7 +230,7 @@ static PCBYTES initbytes(uint8_t *bytes, size_t size, uint32_t interp)
* Lots of identical words means great
* compression ratios.
*/
static void
static void
test_run_length_encoding()
{
char *bytes, *bytes_rle, *bytes_de_rle;
@ -241,7 +241,7 @@ test_run_length_encoding()
uint8_t interp;
size_t interp_size;
PCBYTES pcb, epcb, pcb2;
/*
typedef struct
{
@ -252,7 +252,7 @@ typedef struct
uint8_t *bytes;
} PCBYTES;
*/
bytes = "aaaabbbbccdde";
pcb = initbytes(bytes, strlen(bytes), PC_UINT8);
nr = pc_bytes_run_count(&pcb);
@ -287,7 +287,7 @@ typedef struct
pcb = initbytes(bytes, strlen(bytes), PC_UINT8);
nr = pc_bytes_run_count(&pcb);
CU_ASSERT_EQUAL(nr, 1);
epcb = pc_bytes_run_length_encode(pcb);
pcb2 = pc_bytes_run_length_decode(epcb);
@ -326,15 +326,15 @@ typedef struct
CU_ASSERT_EQUAL(pcb.npoints, pcb2.npoints);
pc_bytes_free(epcb);
pc_bytes_free(pcb2);
}
/*
* Strip the common bits off a stream and pack the
* Strip the common bits off a stream and pack the
* remaining bits in behind. Test bit counting and
* round-trip encode/decode paths.
*/
static void
static void
test_sigbits_encoding()
{
int i;
@ -342,13 +342,13 @@ test_sigbits_encoding()
uint16_t *bytes16, *ebytes16;
uint32_t *bytes32, *ebytes32;
size_t ebytes_size;
uint32_t count, nelems;
uint8_t common8;
uint16_t common16;
uint32_t common32;
PCBYTES pcb, epcb, pcb2;
/*
01100001 a
01100010 b
@ -379,7 +379,7 @@ test_sigbits_encoding()
CU_ASSERT_EQUAL(count, 6);
/*
"abca" encoded:
"abca" encoded:
base a b c a
01100000 01 10 11 01
*/
@ -419,7 +419,7 @@ test_sigbits_encoding()
/* Test the 16 bit implementation path */
nelems = 6;
bytes16 = (uint16_t[]){
bytes16 = (uint16_t[]){
24929, /* 0110000101100001 */
24930, /* 0110000101100010 */
24931, /* 0110000101100011 */
@ -430,7 +430,7 @@ test_sigbits_encoding()
/* encoded 0110000101100 001 010 011 100 101 110 */
bytes = (uint8_t*)bytes16;
pcb = initbytes(bytes, nelems*2, PC_INT16);
/* Test the 16 bit implementation path */
common16 = pc_bytes_sigbits_count_16(&pcb, &count);
CU_ASSERT_EQUAL(common16, 24928);
@ -453,11 +453,11 @@ test_sigbits_encoding()
CU_ASSERT_EQUAL(bytes16[4], 24933);
CU_ASSERT_EQUAL(bytes16[5], 24934);
pc_bytes_free(pcb2);
/* Test the 32 bit implementation path */
nelems = 6;
bytes32 = (uint32_t[]){
bytes32 = (uint32_t[]){
103241, /* 0000000000000001 1001 0011 0100 1001 */
103251, /* 0000000000000001 1001 0011 0101 0011 */
103261, /* 0000000000000001 1001 0011 0101 1101 */
@ -477,7 +477,7 @@ test_sigbits_encoding()
CU_ASSERT_EQUAL(ebytes32[0], 6); /* unique bit count */
CU_ASSERT_EQUAL(ebytes32[1], 103232); /* common bits */
CU_ASSERT_EQUAL(ebytes32[2], 624388039); /* packed uint32 */
pcb2 = pc_bytes_sigbits_decode(epcb);
pc_bytes_free(epcb);
bytes32 = (uint32_t*)(pcb2.bytes);
@ -488,10 +488,10 @@ test_sigbits_encoding()
CU_ASSERT_EQUAL(bytes32[4], 103281);
CU_ASSERT_EQUAL(bytes32[5], 103291);
pc_bytes_free(pcb2);
/* What if all the words are the same? */
nelems = 6;
bytes16 = (uint16_t[]){
bytes16 = (uint16_t[]){
24929, /* 0000000000000001 1001 0011 0100 1001 */
24929, /* 0000000000000001 1001 0011 0101 0011 */
24929, /* 0000000000000001 1001 0011 0101 1101 */
@ -505,13 +505,13 @@ test_sigbits_encoding()
pcb2 = pc_bytes_sigbits_decode(epcb);
pc_bytes_free(epcb);
pc_bytes_free(pcb2);
}
/*
* Encode and decode a byte stream. Data matches?
*/
static void
static void
test_zlib_encoding()
{
uint8_t *bytes, *ebytes;
@ -533,10 +533,10 @@ test_zlib_encoding()
}
/**
* Pivot a pointlist into a dimlist and back.
* Pivot a pointlist into a dimlist and back.
* Test for data loss or alteration.
*/
static void
static void
test_patch_dimensional()
{
PCPOINT *pt;
@ -545,9 +545,9 @@ test_patch_dimensional()
PCPOINTLIST *pl1, *pl2;
PCPATCH_DIMENSIONAL *pdl;
PCDIMSTATS *pds;
pl1 = pc_pointlist_make(npts);
for ( i = 0; i < npts; i++ )
{
pt = pc_point_make(simpleschema);
@ -557,10 +557,10 @@ test_patch_dimensional()
pc_point_set_double_by_name(pt, "intensity", 10);
pc_pointlist_add_point(pl1, pt);
}
pdl = pc_patch_dimensional_from_pointlist(pl1);
pl2 = pc_pointlist_from_dimensional(pdl);
for ( i = 0; i < npts; i++ )
{
pt = pc_pointlist_get_point(pl2, i);
@ -575,12 +575,12 @@ test_patch_dimensional()
CU_ASSERT_DOUBLE_EQUAL(v3, i*0.34, 0.001);
CU_ASSERT_DOUBLE_EQUAL(v4, 10, 0.001);
}
pds = pc_dimstats_make(simpleschema);
pc_dimstats_update(pds, pdl);
pc_dimstats_update(pds, pdl);
pc_patch_dimensional_free(pdl);
pc_pointlist_free(pl1);
pc_pointlist_free(pl2);
@ -588,7 +588,7 @@ test_patch_dimensional()
}
static void
static void
test_patch_dimensional_compression()
{
PCPOINT *pt;
@ -599,9 +599,9 @@ test_patch_dimensional_compression()
PCDIMSTATS *pds = NULL;
size_t z1, z2;
char *str;
pl1 = pc_pointlist_make(npts);
for ( i = 0; i < npts; i++ )
{
pt = pc_point_make(simpleschema);
@ -611,11 +611,11 @@ test_patch_dimensional_compression()
pc_point_set_double_by_name(pt, "intensity", 10);
pc_pointlist_add_point(pl1, pt);
}
pch1 = pc_patch_dimensional_from_pointlist(pl1);
z1 = pc_patch_dimensional_serialized_size(pch1);
// printf("z1 %ld\n", z1);
pds = pc_dimstats_make(simpleschema);
pc_dimstats_update(pds, pch1);
pc_dimstats_update(pds, pch1);
@ -628,8 +628,8 @@ test_patch_dimensional_compression()
// printf("%s\n", str);
pcfree(str);
pl2 = pc_pointlist_from_dimensional(pch2);
pl2 = pc_pointlist_from_dimensional(pch2);
for ( i = 0; i < npts; i++ )
{
pt = pc_pointlist_get_point(pl2, i);
@ -644,7 +644,7 @@ test_patch_dimensional_compression()
CU_ASSERT_DOUBLE_EQUAL(v3, i*0.34, 0.001);
CU_ASSERT_DOUBLE_EQUAL(v4, 10, 0.001);
}
pc_patch_dimensional_free(pch1);
pc_patch_dimensional_free(pch2);
// pc_patch_dimensional_free(pch3);
@ -653,7 +653,7 @@ test_patch_dimensional_compression()
if ( pds ) pc_dimstats_free(pds);
}
static void
static void
test_patch_union()
{
int i;
@ -664,9 +664,9 @@ test_patch_union()
PCDIMSTATS *pds = NULL;
size_t z1, z2;
char *str;
pl1 = pc_pointlist_make(npts);
for ( i = 0; i < npts; i++ )
{
PCPOINT *pt = pc_point_make(simpleschema);
@ -676,15 +676,15 @@ test_patch_union()
pc_point_set_double_by_name(pt, "intensity", 10);
pc_pointlist_add_point(pl1, pt);
}
palist = pcalloc(2*sizeof(PCPATCH*));
palist[0] = (PCPATCH*)pc_patch_dimensional_from_pointlist(pl1);
palist[1] = (PCPATCH*)pc_patch_uncompressed_from_pointlist(pl1);
pu = pc_patch_from_patchlist(palist, 2);
CU_ASSERT_EQUAL(pu->npoints, 2*npts);
pc_pointlist_free(pl1);
pc_patch_free(pu);
pc_patch_free(palist[0]);
@ -693,7 +693,7 @@ test_patch_union()
}
static void
static void
test_patch_wkb()
{
int i;
@ -705,9 +705,9 @@ test_patch_wkb()
size_t z1, z2;
uint8_t *wkb1, *wkb2;
char *str;
pl1 = pc_pointlist_make(npts);
for ( i = 0; i < npts; i++ )
{
PCPOINT *pt = pc_point_make(simpleschema);
@ -717,7 +717,7 @@ test_patch_wkb()
pc_point_set_double_by_name(pt, "intensity", 13);
pc_pointlist_add_point(pl1, pt);
}
pa1 = (PCPATCH*)pc_patch_dimensional_from_pointlist(pl1);
wkb1 = pc_patch_to_wkb(pa1, &z1);
str = hexbytes_from_bytes(wkb1, z1);
@ -725,7 +725,7 @@ test_patch_wkb()
pa2 = pc_patch_from_wkb(simpleschema, wkb1, z1);
// printf("pa2\n%s\n",pc_patch_to_string(pa2));
pa3 = pc_patch_compress(pa2, NULL);
// printf("pa3\n%s\n",pc_patch_to_string(pa3));
@ -734,18 +734,18 @@ test_patch_wkb()
pa4 = pc_patch_from_wkb(simpleschema, wkb2, z2);
// printf("pa4\n%s\n",pc_patch_to_string(pa4));
pu1 = (PCPATCH_UNCOMPRESSED*)pc_patch_uncompressed_from_dimensional((PCPATCH_DIMENSIONAL*)pa1);
pu2 = (PCPATCH_UNCOMPRESSED*)pc_patch_uncompressed_from_dimensional((PCPATCH_DIMENSIONAL*)pa4);
// printf("pu1\n%s\n", pc_patch_to_string((PCPATCH*)pu1));
// printf("pu2\n%s\n", pc_patch_to_string((PCPATCH*)pu2));
CU_ASSERT_EQUAL(pu1->datasize, pu2->datasize);
CU_ASSERT_EQUAL(pu1->npoints, pu2->npoints);
CU_ASSERT(memcmp(pu1->data, pu2->data, pu1->datasize) == 0);
pc_pointlist_free(pl1);
pc_patch_free(pa1);
pc_patch_free(pa2);

View File

@ -19,10 +19,10 @@ static const char *xmlfile = "data/simple-schema.xml";
// int32_t x
// int32_t y
// int32_t z
// int16_t intensity
// int16_t intensity
/* Setup/teardown for this suite */
static int
static int
init_suite(void)
{
char *xmlstr = file_to_str(xmlfile);
@ -32,7 +32,7 @@ init_suite(void)
return 0;
}
static int
static int
clean_suite(void)
{
pc_schema_free(schema);
@ -42,13 +42,13 @@ clean_suite(void)
/* TESTS **************************************************************/
static void
static void
test_point_hex_inout()
{
// byte: endianness (1 = NDR, 0 = XDR)
// uint32: pcid (key to POINTCLOUD_SCHEMAS)
// uchar[]: pointdata (interpret relative to pcid)
double d;
char *hexbuf = "00000000010000000100000002000000030004";
size_t hexsize = strlen(hexbuf);
@ -64,7 +64,7 @@ test_point_hex_inout()
CU_ASSERT_DOUBLE_EQUAL(d, 4, 0.0001);
pc_point_free(pt);
pcfree(wkb);
hexbuf = "01010000000100000002000000030000000500";
hexsize = strlen(hexbuf);
wkb = bytes_from_hexbytes(hexbuf, hexsize);
@ -79,7 +79,7 @@ test_point_hex_inout()
CU_ASSERT_DOUBLE_EQUAL(d, 5, 0.0001);
pc_point_free(pt);
pcfree(wkb);
}

View File

@ -16,7 +16,7 @@ static PCSCHEMA *schema = NULL;
static const char *xmlfile = "data/pdal-schema.xml";
/* Setup/teardown for this suite */
static int
static int
init_suite(void)
{
char *xmlstr = file_to_str(xmlfile);
@ -25,7 +25,7 @@ init_suite(void)
return rv == PC_FAILURE;
}
static int
static int
clean_suite(void)
{
pc_schema_free(schema);
@ -35,8 +35,8 @@ clean_suite(void)
/* TESTS **************************************************************/
static void
test_schema_from_xml()
static void
test_schema_from_xml()
{
static PCSCHEMA *myschema = NULL;
char *xmlstr = file_to_str(xmlfile);
@ -47,23 +47,23 @@ test_schema_from_xml()
// printf("ndims %d\n", schema->ndims);
// printf("name0 %s\n", schema->dims[0]->name);
// printf("%s\n", schemastr);
CU_ASSERT(myschema != NULL);
pc_schema_free(myschema);
}
static void
test_schema_size()
static void
test_schema_size()
{
size_t sz = schema->size;
CU_ASSERT_EQUAL(sz, 37);
}
static void
test_dimension_get()
static void
test_dimension_get()
{
PCDIMENSION *d;
d = pc_schema_get_dimension(schema, 0);
CU_ASSERT_EQUAL(d->position, 0);
CU_ASSERT_STRING_EQUAL(d->name, "X");
@ -90,15 +90,15 @@ test_dimension_get()
CU_ASSERT_STRING_EQUAL(d->name, "Y");
}
static void
test_dimension_byteoffsets()
static void
test_dimension_byteoffsets()
{
PCDIMENSION *d;
int i;
int prev_byteoffset;
int prev_size;
int pc_size;
for ( i = 0; i < schema->ndims; i++ )
{
d = pc_schema_get_dimension(schema, i);
@ -112,17 +112,17 @@ test_dimension_byteoffsets()
prev_size = d->size;
pc_size = pc_interpretation_size(d->interpretation);
}
}
static void
test_point_access()
static void
test_point_access()
{
PCPOINT *pt;
int rv;
double a1, a2, a3, a4, b1, b2, b3, b4;
int idx = 0;
pt = pc_point_make(schema);
CU_ASSERT( pt != NULL );
@ -144,9 +144,9 @@ test_point_access()
rv = pc_point_set_double_by_name(pt, "NumberOfReturns", a3);
rv = pc_point_get_double_by_name(pt, "NumberOfReturns", &b3);
CU_ASSERT_DOUBLE_EQUAL(a3, b3, 0.0000001);
pc_point_free(pt);
/* All at once */
pt = pc_point_make(schema);
a1 = 1.5;
@ -165,9 +165,9 @@ test_point_access()
CU_ASSERT_DOUBLE_EQUAL(a2, b2, 0.0000001);
CU_ASSERT_DOUBLE_EQUAL(a3, b3, 0.0000001);
CU_ASSERT_DOUBLE_EQUAL(a4, b4, 0.0000001);
pc_point_free(pt);
}
static void

View File

@ -162,10 +162,10 @@ int main(int argc, char *argv[])
* Log message in a global var instead of printing in stderr
*
* CAUTION: Not stop execution on rterror case !!!
static void cu_error_reporter(const char *fmt, va_list ap)
static void cu_error_reporter(const char *fmt, va_list ap)
{
char *msg;
if (!vasprintf (&msg, fmt, ap))
if (!vasprintf (&msg, fmt, ap))
{
va_end (ap);
return;
@ -190,7 +190,7 @@ file_to_str(const char *fname)
char *str = pcalloc(sz);
char *ptr = str;
char *ln;
fr = fopen (fname, "rt");
while( ln = fgetln(fr, &lnsz) )
{
@ -202,9 +202,9 @@ file_to_str(const char *fname)
ptr = str + bsz;
}
memcpy(ptr, ln, lnsz);
ptr += lnsz;
ptr += lnsz;
}
fclose(fr);
return str;
}

14
lib/hashtable.c Executable file → Normal file
View File

@ -138,7 +138,7 @@ hashtable_expand(hashtable *h)
h->table = newtable;
}
/* Plan B: realloc instead */
else
else
{
newtable = (struct entry **)
realloc(h->table, newsize * sizeof(struct entry *));
@ -286,23 +286,23 @@ hashtable_destroy(hashtable *h, int free_values)
/*
* Copyright (c) 2002, Christopher Clark
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
*
* * Neither the name of the original author; nor the names of any contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
*
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

View File

@ -44,7 +44,7 @@ pc_bytes_make(const PCDIMENSION *dim, uint32_t npoints)
return pcb;
}
static PCBYTES
static PCBYTES
pc_bytes_clone(PCBYTES pcb)
{
PCBYTES pcbnew = pcb;
@ -135,7 +135,7 @@ pc_bytes_run_count(const PCBYTES *pcb)
const uint8_t *ptr1;
size_t size = pc_interpretation_size(pcb->interpretation);
uint32_t runcount = 1;
for ( i = 1; i < pcb->npoints; i++ )
{
ptr0 = pcb->bytes + (i-1)*size;
@ -145,11 +145,11 @@ pc_bytes_run_count(const PCBYTES *pcb)
runcount++;
}
}
return runcount;
return runcount;
}
/**
* Take the uncompressed bytes and run-length encode (RLE) them.
* Take the uncompressed bytes and run-length encode (RLE) them.
* Structure of RLE array as:
* <uint8> number of elements
* <val> value
@ -166,14 +166,14 @@ pc_bytes_run_length_encode(const PCBYTES pcb)
size_t size = pc_interpretation_size(pcb.interpretation);
uint8_t runlength = 1;
PCBYTES pcbout = pcb;
/* Allocate more size than we need (worst case: n elements, n runs) */
buf = pcalloc(pcb.npoints*size + sizeof(uint8_t)*pcb.npoints);
bufptr = buf;
/* First run starts at the start! */
runstart = pcb.bytes;
for ( i = 1; i <= pcb.npoints; i++ )
{
bytesptr = pcb.bytes + i*size;
@ -209,7 +209,7 @@ pc_bytes_run_length_encode(const PCBYTES pcb)
}
/**
* Take the compressed bytes and run-length dencode (RLE) them.
* Take the compressed bytes and run-length dencode (RLE) them.
* Structure of RLE array is:
* <uint8> number of elements
* <val> value
@ -229,18 +229,18 @@ pc_bytes_run_length_decode(const PCBYTES pcb)
uint8_t runlength;
uint32_t npoints = 0;
PCBYTES pcbout = pcb;
assert(pcb.compression == PC_DIM_RLE);
/* Count up how big our output is. */
while( bytes_rle_ptr < bytes_rle_end )
{
npoints += *bytes_rle_ptr;
bytes_rle_ptr += 1 + size;
}
assert(npoints == pcb.npoints);
/* Alocate output and fill it up */
size_out = size * npoints;
bytes = pcalloc(size_out);
@ -254,7 +254,7 @@ pc_bytes_run_length_decode(const PCBYTES pcb)
{
memcpy(bytes_ptr, bytes_rle_ptr, size);
bytes_ptr += size;
}
}
bytes_rle_ptr += size;
}
pcbout.compression = PC_DIM_NONE;
@ -307,13 +307,13 @@ pc_bytes_run_length_flip_endian(PCBYTES pcb)
bytes_ptr[n] = bytes_ptr[size-n-1];
bytes_ptr[size-n-1] = tmp;
}
/* Move past this word */
bytes_ptr += size;
/* Advance past next count */
bytes_ptr++;
}
return pcb;
}
@ -333,7 +333,7 @@ pc_bytes_sigbits_count_8(const PCBYTES *pcb, uint32_t *nsigbits)
elem_and &= bytes[i];
elem_or |= bytes[i];
}
while ( elem_and != elem_or )
{
elem_and >>= 1;
@ -342,7 +342,7 @@ pc_bytes_sigbits_count_8(const PCBYTES *pcb, uint32_t *nsigbits)
}
elem_and <<= nbits - commonbits;
if ( nsigbits ) *nsigbits = commonbits;
return elem_and;
return elem_and;
}
uint16_t
@ -360,7 +360,7 @@ pc_bytes_sigbits_count_16(const PCBYTES *pcb, uint32_t *nsigbits)
elem_and &= bytes[i];
elem_or |= bytes[i];
}
while ( elem_and != elem_or )
{
elem_and >>= 1;
@ -369,7 +369,7 @@ pc_bytes_sigbits_count_16(const PCBYTES *pcb, uint32_t *nsigbits)
}
elem_and <<= nbits - commonbits;
if ( nsigbits ) *nsigbits = commonbits;
return elem_and;
return elem_and;
}
uint32_t
@ -387,7 +387,7 @@ pc_bytes_sigbits_count_32(const PCBYTES *pcb, uint32_t *nsigbits)
elem_and &= bytes[i];
elem_or |= bytes[i];
}
while ( elem_and != elem_or )
{
elem_and >>= 1;
@ -396,7 +396,7 @@ pc_bytes_sigbits_count_32(const PCBYTES *pcb, uint32_t *nsigbits)
}
elem_and <<= nbits - commonbits;
if ( nsigbits ) *nsigbits = commonbits;
return elem_and;
return elem_and;
}
uint64_t
@ -414,7 +414,7 @@ pc_bytes_sigbits_count_64(const PCBYTES *pcb, uint32_t *nsigbits)
elem_and &= bytes[i];
elem_or |= bytes[i];
}
while ( elem_and != elem_or )
{
elem_and >>= 1;
@ -423,7 +423,7 @@ pc_bytes_sigbits_count_64(const PCBYTES *pcb, uint32_t *nsigbits)
}
elem_and <<= nbits - commonbits;
if ( nsigbits ) *nsigbits = commonbits;
return elem_and;
return elem_and;
}
/**
@ -508,12 +508,12 @@ pc_bytes_sigbits_encode_8(const PCBYTES pcb, uint8_t commonvalue, uint8_t common
pcbout.compression = PC_DIM_SIGBITS;
return pcbout;
}
for ( i = 0; i < pcb.npoints; i++ )
{
uint8_t val = bytes[i];
/* Clear off common parts */
val &= mask;
val &= mask;
/* How far to move unique parts to get to write head? */
shift = bit - nbits;
/* If positive, we can fit this part into the current word */
@ -533,7 +533,7 @@ pc_bytes_sigbits_encode_8(const PCBYTES pcb, uint8_t commonvalue, uint8_t common
{
/* First the bit into the current word */
uint8_t v = val;
int s = abs(shift);
int s = abs(shift);
v >>= s;
*byte_ptr |= v;
/* The reset to write the next word */
@ -543,7 +543,7 @@ pc_bytes_sigbits_encode_8(const PCBYTES pcb, uint8_t commonvalue, uint8_t common
shift = bit - s;
/* But only those parts we didn't already write */
v <<= shift;
*byte_ptr |= v;
*byte_ptr |= v;
bit -= s;
}
}
@ -567,7 +567,7 @@ pc_bytes_sigbits_encode_16(const PCBYTES pcb, uint16_t commonvalue, uint8_t comm
int i;
int shift;
uint16_t *bytes = (uint16_t*)(pcb.bytes);
/* How wide are our words? */
static int bitwidth = 16;
/* How wide are our unique values? */
@ -590,7 +590,7 @@ pc_bytes_sigbits_encode_16(const PCBYTES pcb, uint16_t commonvalue, uint8_t comm
*byte_ptr = nbits; byte_ptr++;
/* The common value we'll add the unique values to */
*byte_ptr = commonvalue; byte_ptr++;
/* All the values are the same... */
if ( bitwidth == commonbits )
{
@ -599,12 +599,12 @@ pc_bytes_sigbits_encode_16(const PCBYTES pcb, uint16_t commonvalue, uint8_t comm
pcbout.compression = PC_DIM_SIGBITS;
return pcbout;
}
for ( i = 0; i < pcb.npoints; i++ )
{
uint16_t val = bytes[i];
/* Clear off common parts */
val &= mask;
val &= mask;
/* How far to move unique parts to get to write head? */
shift = bit - nbits;
/* If positive, we can fit this part into the current word */
@ -624,7 +624,7 @@ pc_bytes_sigbits_encode_16(const PCBYTES pcb, uint16_t commonvalue, uint8_t comm
{
/* First the bit into the current word */
uint16_t v = val;
int s = abs(shift);
int s = abs(shift);
v >>= s;
*byte_ptr |= v;
/* The reset to write the next word */
@ -634,7 +634,7 @@ pc_bytes_sigbits_encode_16(const PCBYTES pcb, uint16_t commonvalue, uint8_t comm
shift = bit - s;
/* But only those parts we didn't already write */
v <<= shift;
*byte_ptr |= v;
*byte_ptr |= v;
bit -= s;
}
}
@ -658,7 +658,7 @@ pc_bytes_sigbits_encode_32(const PCBYTES pcb, uint32_t commonvalue, uint8_t comm
int i;
int shift;
uint32_t *bytes = (uint32_t*)(pcb.bytes);
/* How wide are our words? */
static int bitwidth = 32;
/* How wide are our unique values? */
@ -689,12 +689,12 @@ pc_bytes_sigbits_encode_32(const PCBYTES pcb, uint32_t commonvalue, uint8_t comm
pcbout.compression = PC_DIM_SIGBITS;
return pcbout;
}
for ( i = 0; i < pcb.npoints; i++ )
{
uint32_t val = bytes[i];
/* Clear off common parts */
val &= mask;
val &= mask;
/* How far to move unique parts to get to write head? */
shift = bit - nbits;
/* If positive, we can fit this part into the current word */
@ -714,7 +714,7 @@ pc_bytes_sigbits_encode_32(const PCBYTES pcb, uint32_t commonvalue, uint8_t comm
{
/* First the bit into the current word */
uint32_t v = val;
int s = abs(shift);
int s = abs(shift);
v >>= s;
*byte_ptr |= v;
/* The reset to write the next word */
@ -724,7 +724,7 @@ pc_bytes_sigbits_encode_32(const PCBYTES pcb, uint32_t commonvalue, uint8_t comm
shift = bit - s;
/* But only those parts we didn't already write */
v <<= shift;
*byte_ptr |= v;
*byte_ptr |= v;
bit -= s;
}
}
@ -736,8 +736,8 @@ pc_bytes_sigbits_encode_32(const PCBYTES pcb, uint32_t commonvalue, uint8_t comm
}
/**
* Convert a raw byte array into with common bits stripped and the
* remaining bits packed in.
* Convert a raw byte array into with common bits stripped and the
* remaining bits packed in.
* <uint8|uint16|uint32> number of bits per unique section
* <uint8|uint16|uint32> common bits for the array
* [n_bits]... unique bits packed in
@ -782,11 +782,11 @@ pc_bytes_sigbits_flip_endian(const PCBYTES pcb)
size_t size = pc_interpretation_size(pcb.interpretation);
uint8_t *b1 = pcb.bytes;
uint8_t *b2 = pcb.bytes + size;
/* If it's not multi-byte words, it doesn't need flipping */
if ( size < 2 )
return pcb;
/* We only need to flip the first two words, */
/* which are the common bit count and common bits word */
for ( n = 0; n < size / 2; n++ )
@ -800,7 +800,7 @@ pc_bytes_sigbits_flip_endian(const PCBYTES pcb)
b2[n] = b2[size-n-1];
b2[size-n-1] = tmp2;
}
return pcb;
}
@ -808,7 +808,7 @@ pc_bytes_sigbits_flip_endian(const PCBYTES pcb)
PCBYTES
pc_bytes_sigbits_decode_8(const PCBYTES pcb)
{
int i;
int i;
const uint8_t *bytes_ptr = (const uint8_t*)(pcb.bytes);
uint8_t nbits;
uint8_t commonvalue;
@ -818,14 +818,14 @@ pc_bytes_sigbits_decode_8(const PCBYTES pcb)
uint8_t *outbytes = pcalloc(outbytes_size);
uint8_t *obytes = (uint8_t*)outbytes;
PCBYTES pcbout = pcb;
/* How many unique bits? */
nbits = *bytes_ptr; bytes_ptr++;
/* What is the shared bit value? */
commonvalue = *bytes_ptr; bytes_ptr++;
commonvalue = *bytes_ptr; bytes_ptr++;
/* Mask for just the unique parts */
mask = (0xFF >> (bit-nbits));
for ( i = 0; i < pcb.npoints; i++ )
{
int shift = bit - nbits;
@ -850,7 +850,7 @@ pc_bytes_sigbits_decode_8(const PCBYTES pcb)
int s = abs(shift);
val <<= s;
val &= mask;
val |= commonvalue;
val |= commonvalue;
obytes[i] = val;
bytes_ptr++;
bit = 8;
@ -871,7 +871,7 @@ pc_bytes_sigbits_decode_8(const PCBYTES pcb)
PCBYTES
pc_bytes_sigbits_decode_16(const PCBYTES pcb)
{
int i;
int i;
const uint16_t *bytes_ptr = (const uint16_t *)(pcb.bytes);
uint16_t nbits;
uint16_t commonvalue;
@ -881,14 +881,14 @@ pc_bytes_sigbits_decode_16(const PCBYTES pcb)
uint8_t *outbytes = pcalloc(outbytes_size);
uint16_t *obytes = (uint16_t*)outbytes;
PCBYTES pcbout = pcb;
/* How many unique bits? */
nbits = *bytes_ptr; bytes_ptr++;
/* What is the shared bit value? */
commonvalue = *bytes_ptr; bytes_ptr++;
commonvalue = *bytes_ptr; bytes_ptr++;
/* Calculate mask */
mask = (0xFFFF >> (bit-nbits));
for ( i = 0; i < pcb.npoints; i++ )
{
int shift = bit - nbits;
@ -906,7 +906,7 @@ pc_bytes_sigbits_decode_16(const PCBYTES pcb)
int s = abs(shift);
val <<= s;
val &= mask;
val |= commonvalue;
val |= commonvalue;
obytes[i] = val;
bytes_ptr++;
bit = 16;
@ -927,7 +927,7 @@ pc_bytes_sigbits_decode_16(const PCBYTES pcb)
PCBYTES
pc_bytes_sigbits_decode_32(const PCBYTES pcb)
{
int i;
int i;
const uint32_t *bytes_ptr = (const uint32_t *)(pcb.bytes);
uint32_t nbits;
uint32_t commonvalue;
@ -937,14 +937,14 @@ pc_bytes_sigbits_decode_32(const PCBYTES pcb)
uint8_t *outbytes = pcalloc(outbytes_size);
uint32_t *obytes = (uint32_t*)outbytes;
PCBYTES pcbout = pcb;
/* How many unique bits? */
nbits = *bytes_ptr; bytes_ptr++;
/* What is the shared bit value? */
commonvalue = *bytes_ptr; bytes_ptr++;
commonvalue = *bytes_ptr; bytes_ptr++;
/* Calculate mask */
mask = (0xFFFFFFFF >> (bit-nbits));
for ( i = 0; i < pcb.npoints; i++ )
{
int shift = bit - nbits;
@ -962,7 +962,7 @@ pc_bytes_sigbits_decode_32(const PCBYTES pcb)
int s = abs(shift);
val <<= s;
val &= mask;
val |= commonvalue;
val |= commonvalue;
obytes[i] = val;
bytes_ptr++;
bit = 32;
@ -1039,7 +1039,7 @@ pc_bytes_zlib_encode(const PCBYTES pcb)
size_t bufsize = 4*pcb.size;
uint8_t *buf = pcalloc(bufsize);
PCBYTES pcbout = pcb;
/* Use our own allocators */
strm.zalloc = pc_zlib_alloc;
strm.zfree = pc_zlib_free;
@ -1076,12 +1076,12 @@ pc_bytes_zlib_decode(const PCBYTES pcb)
z_stream strm;
int ret;
PCBYTES pcbout = pcb;
pcbout.size = pc_interpretation_size(pcb.interpretation) * pcb.npoints;
/* Set up output memory */
pcbout.bytes = pcalloc(pcbout.size);
/* Use our own allocators */
strm.zalloc = pc_zlib_alloc;
strm.zfree = pc_zlib_free;
@ -1096,20 +1096,20 @@ pc_bytes_zlib_decode(const PCBYTES pcb)
ret = inflate(&strm, Z_FINISH);
assert(ret != Z_STREAM_ERROR);
inflateEnd(&strm);
pcbout.compression = PC_DIM_NONE;
return pcbout;
}
/**
* This flips bytes in-place, so won't work on readonly bytes
* This flips bytes in-place, so won't work on readonly bytes
*/
PCBYTES
pc_bytes_flip_endian(PCBYTES pcb)
{
if ( pcb.readonly )
if ( pcb.readonly )
pcerror("pc_bytes_flip_endian: cannot flip readonly bytes");
switch(pcb.compression)
{
case PC_DIM_NONE:
@ -1121,9 +1121,9 @@ pc_bytes_flip_endian(PCBYTES pcb)
case PC_DIM_RLE:
return pc_bytes_run_length_flip_endian(pcb);
default:
pcerror("pc_bytes_flip_endian: unknown compression");
pcerror("pc_bytes_flip_endian: unknown compression");
}
return pcb;
}
@ -1140,12 +1140,12 @@ pc_bytes_serialize(const PCBYTES *pcb, uint8_t *buf, size_t *size)
static int compression_num_size = 1;
static int size_num_size = 4;
int32_t pcbsize = pcb->size;
/* Compression type number */
*buf = pcb->compression;
*buf = pcb->compression;
buf += compression_num_size;
/* Buffer size */
memcpy(buf, &pcbsize, size_num_size);
memcpy(buf, &pcbsize, size_num_size);
buf += size_num_size;
/* Buffer contents */
memcpy(buf, pcb->bytes, pcb->size);
@ -1182,7 +1182,7 @@ pc_bytes_deserialize(const uint8_t *buf, const PCDIMENSION *dim, PCBYTES *pcb, i
}
static int
static int
pc_bytes_uncompressed_minmax(const PCBYTES *pcb, double *min, double *max)
{
int i;
@ -1202,7 +1202,7 @@ pc_bytes_uncompressed_minmax(const PCBYTES *pcb, double *min, double *max)
*max = mx;
}
static int
static int
pc_bytes_run_length_minmax(const PCBYTES *pcb, double *min, double *max)
{
int element_size = pc_interpretation_size(pcb->interpretation);
@ -1214,7 +1214,7 @@ pc_bytes_run_length_minmax(const PCBYTES *pcb, double *min, double *max)
/* Move past first count */
ptr++;
while( ptr < ptr_end )
{
d = pc_double_from_ptr(ptr, pcb->interpretation);
@ -1226,13 +1226,13 @@ pc_bytes_run_length_minmax(const PCBYTES *pcb, double *min, double *max)
ptr += element_size;
}
*min = mn;
*max = mx;
}
static int
static int
pc_bytes_zlib_minmax(const PCBYTES *pcb, double *min, double *max)
{
PCBYTES zcb = pc_bytes_zlib_decode(*pcb);
@ -1241,7 +1241,7 @@ pc_bytes_zlib_minmax(const PCBYTES *pcb, double *min, double *max)
return rv;
}
static int
static int
pc_bytes_sigbits_minmax(const PCBYTES *pcb, double *min, double *max)
{
PCBYTES zcb = pc_bytes_sigbits_decode(*pcb);
@ -1263,7 +1263,7 @@ int pc_bytes_minmax(const PCBYTES *pcb, double *min, double *max)
case PC_DIM_RLE:
return pc_bytes_run_length_minmax(pcb, min, max);
default:
pcerror("pc_bytes_minmax: unknown compression");
pcerror("pc_bytes_minmax: unknown compression");
}
return PC_FAILURE;
return PC_FAILURE;
}

View File

@ -62,10 +62,10 @@ pc_dimstats_to_string(const PCDIMSTATS *pds)
int i;
stringbuffer_t *sb = stringbuffer_create();
char *str;
stringbuffer_aprintf(sb,"{\"ndims\":%d,\"total_points\":%d,\"total_patches\":%d,\"dims\":[",
pds->ndims,
pds->total_points,
stringbuffer_aprintf(sb,"{\"ndims\":%d,\"total_points\":%d,\"total_patches\":%d,\"dims\":[",
pds->ndims,
pds->total_points,
pds->total_patches
);
@ -73,8 +73,8 @@ pc_dimstats_to_string(const PCDIMSTATS *pds)
{
if ( i ) stringbuffer_append(sb, ",");
stringbuffer_aprintf(sb, "{\"total_runs\":%d,\"total_commonbits\":%d,\"recommended_compression\":%d}",
pds->stats[i].total_runs,
pds->stats[i].total_commonbits,
pds->stats[i].total_runs,
pds->stats[i].total_commonbits,
pds->stats[i].recommended_compression
);
}
@ -91,11 +91,11 @@ pc_dimstats_update(PCDIMSTATS *pds, const PCPATCH_DIMENSIONAL *pdl)
int i, j;
uint32_t nelems = pdl->npoints;
const PCSCHEMA *schema = pdl->schema;
/* Update global stats */
pds->total_points += pdl->npoints;
pds->total_patches += 1;
/* Update dimensional stats */
for ( i = 0; i < pds->ndims; i++ )
{
@ -103,7 +103,7 @@ pc_dimstats_update(PCDIMSTATS *pds, const PCPATCH_DIMENSIONAL *pdl)
pds->stats[i].total_runs += pc_bytes_run_count(&pcb);
pds->stats[i].total_commonbits += pc_bytes_sigbits_count(&pcb);
}
/* Update recommended compression schema */
for ( i = 0; i < pds->ndims; i++ )
{

View File

@ -2,7 +2,7 @@
* pc_mem.c
*
* Memory and message management routines.
* Allow this library to be used both inside and outside a
* Allow this library to be used both inside and outside a
* PgSQL backend.
*
* Portions Copyright (c) 2012, OpenGeo
@ -12,7 +12,7 @@
#include <stdarg.h>
#include "pc_api_internal.h"
struct pc_context_t
struct pc_context_t
{
pc_allocator alloc;
pc_reallocator realloc;
@ -104,7 +104,7 @@ void pc_set_handlers(pc_allocator allocator, pc_reallocator reallocator,
void *
pcalloc(size_t size)
pcalloc(size_t size)
{
void *mem = pc_context.alloc(size);
memset(mem, 0, size); /* Always clean memory */

View File

@ -41,7 +41,7 @@ pc_patch_free(PCPATCH *patch)
{
pc_patch_uncompressed_free((PCPATCH_UNCOMPRESSED*)patch);
break;
}
}
case PC_GHT:
{
pcerror("pc_patch_free: GHT not supported");
@ -61,7 +61,7 @@ pc_patch_free(PCPATCH *patch)
}
PCPATCH *
PCPATCH *
pc_patch_from_pointlist(const PCPOINTLIST *ptl)
{
return (PCPATCH*)pc_patch_uncompressed_from_pointlist(ptl);
@ -73,8 +73,8 @@ pc_patch_compress(const PCPATCH *patch, void *userdata)
{
uint32_t schema_compression = patch->schema->compression;
uint32_t patch_compression = patch->type;
if ( schema_compression == PC_DIMENSIONAL &&
if ( schema_compression == PC_DIMENSIONAL &&
patch_compression == PC_NONE )
{
PCPATCH_DIMENSIONAL *pcdu = pc_patch_dimensional_from_uncompressed((PCPATCH_UNCOMPRESSED*)patch);
@ -82,14 +82,14 @@ pc_patch_compress(const PCPATCH *patch, void *userdata)
pc_patch_dimensional_free(pcdu);
return (PCPATCH*)pcdd;
}
if ( schema_compression == PC_DIMENSIONAL &&
if ( schema_compression == PC_DIMENSIONAL &&
patch_compression == PC_DIMENSIONAL )
{
return (PCPATCH*)pc_patch_dimensional_compress((PCPATCH_DIMENSIONAL*)patch, (PCDIMSTATS*)userdata);
}
if ( schema_compression == PC_NONE &&
if ( schema_compression == PC_NONE &&
patch_compression == PC_NONE )
{
return (PCPATCH*)patch;
@ -104,30 +104,30 @@ PCPATCH *
pc_patch_uncompress(const PCPATCH *patch)
{
uint32_t patch_compression = patch->type;
if ( patch_compression == PC_DIMENSIONAL )
{
PCPATCH_UNCOMPRESSED *pu = pc_patch_uncompressed_from_dimensional((PCPATCH_DIMENSIONAL*)patch);
return (PCPATCH*)pu;
}
if ( patch_compression == PC_NONE )
{
return (PCPATCH*)patch;
}
if ( patch_compression == PC_GHT )
{
pcerror("pc_patch_uncompress: GHT compression not yet supported");
return NULL;
}
return NULL;
}
PCPATCH *
PCPATCH *
pc_patch_from_wkb(const PCSCHEMA *s, uint8_t *wkb, size_t wkbsize)
{
/*
@ -137,12 +137,12 @@ pc_patch_from_wkb(const PCSCHEMA *s, uint8_t *wkb, size_t wkbsize)
uchar[]: data (interpret relative to pcid and compression)
*/
uint32_t compression, pcid;
if ( ! wkbsize )
{
pcerror("pc_patch_from_wkb: zero length wkb");
}
/*
* It is possible for the WKB compression to be different from the
* schema compression at this point. The schema compression is only
@ -155,7 +155,7 @@ pc_patch_from_wkb(const PCSCHEMA *s, uint8_t *wkb, size_t wkbsize)
{
pcerror("pc_patch_from_wkb: wkb pcid (%d) not consistent with schema pcid (%d)", pcid, s->pcid);
}
switch ( compression )
{
case PC_NONE:
@ -172,7 +172,7 @@ pc_patch_from_wkb(const PCSCHEMA *s, uint8_t *wkb, size_t wkbsize)
return NULL;
}
}
/* Don't get here */
pcerror("pc_patch_from_wkb: unknown compression '%d' requested", compression);
return NULL;
@ -204,7 +204,7 @@ pc_patch_to_wkb(const PCPATCH *patch, size_t *wkbsize)
pcerror("pc_patch_to_wkb: GHT compression not yet supported");
return NULL;
}
}
}
pcerror("pc_patch_to_wkb: unknown compression requested '%d'", patch->schema->compression);
return NULL;
}
@ -257,7 +257,7 @@ pc_patch_to_geometry_wkb_envelope(const PCPATCH *pa, size_t *wkbsize)
int has_srid = PC_FALSE;
size_t size = 1 + 4 + 4 + 4 + 2*npoints*8; /* endian + type + nrings + npoints + 5 dbl pts */
double x, y;
if ( pa->schema->srid > 0 )
{
has_srid = PC_TRUE;
@ -267,39 +267,39 @@ pc_patch_to_geometry_wkb_envelope(const PCPATCH *pa, size_t *wkbsize)
wkb = pcalloc(size);
ptr = wkb;
ptr = pc_patch_wkb_set_char(ptr, machine_endian()); /* Endian flag */
ptr = pc_patch_wkb_set_int32(ptr, wkbtype); /* TYPE = Polygon */
if ( has_srid )
{
ptr = pc_patch_wkb_set_int32(ptr, pa->schema->srid); /* SRID */
}
ptr = pc_patch_wkb_set_int32(ptr, nrings); /* NRINGS = 1 */
ptr = pc_patch_wkb_set_int32(ptr, npoints); /* NPOINTS = 5 */
/* Point 0 */
ptr = pc_patch_wkb_set_double(ptr, pa->xmin);
ptr = pc_patch_wkb_set_double(ptr, pa->ymin);
/* Point 1 */
ptr = pc_patch_wkb_set_double(ptr, pa->xmin);
ptr = pc_patch_wkb_set_double(ptr, pa->ymax);
/* Point 2 */
ptr = pc_patch_wkb_set_double(ptr, pa->xmax);
ptr = pc_patch_wkb_set_double(ptr, pa->ymax);
/* Point 3 */
ptr = pc_patch_wkb_set_double(ptr, pa->xmax);
ptr = pc_patch_wkb_set_double(ptr, pa->ymin);
/* Point 4 */
ptr = pc_patch_wkb_set_double(ptr, pa->xmin);
ptr = pc_patch_wkb_set_double(ptr, pa->ymin);
if ( wkbsize ) *wkbsize = size;
return wkb;
}
@ -312,13 +312,13 @@ pc_patch_from_patchlist(PCPATCH **palist, int numpatches)
PCPATCH_UNCOMPRESSED *paout;
const PCSCHEMA *schema = NULL;
uint8_t *buf;
assert(palist);
assert(numpatches);
/* All schemas better be the same... */
schema = palist[0]->schema;
/* How many points will this output have? */
for ( i = 0; i < numpatches; i++ )
{
@ -329,11 +329,11 @@ pc_patch_from_patchlist(PCPATCH **palist, int numpatches)
}
totalpoints += palist[i]->npoints;
}
/* Blank output */
paout = pc_patch_uncompressed_make(schema, totalpoints);
buf = paout->data;
/* Uncompress dimensionals, copy uncompressed */
for ( i = 0; i < numpatches; i++ )
{
@ -344,7 +344,7 @@ pc_patch_from_patchlist(PCPATCH **palist, int numpatches)
if ( pa->ymin < paout->ymin ) paout->ymin = pa->ymin;
if ( pa->xmax > paout->xmax ) paout->xmax = pa->xmax;
if ( pa->ymax > paout->ymax ) paout->ymax = pa->ymax;
switch ( pa->type )
{
case PC_DIMENSIONAL:
@ -376,7 +376,7 @@ pc_patch_from_patchlist(PCPATCH **palist, int numpatches)
}
}
}
paout->npoints = totalpoints;
return (PCPATCH*)paout;
}

View File

@ -18,7 +18,7 @@ typedef struct
int type;
int8_t readonly;
const PCSCHEMA *schema;
uint32_t npoints;
uint32_t npoints;
double xmin, xmax, ymin, ymax;
PCBYTES *bytes;
} PCPATCH_DIMENSIONAL;
@ -62,19 +62,19 @@ pc_patch_dimensional_from_uncompressed(const PCPATCH_UNCOMPRESSED *pa)
/* Cannot handle empty patches */
if ( npoints == 0 ) return NULL;
/* Initialize list */
pdl = pcalloc(sizeof(PCPATCH_DIMENSIONAL));
pdl->schema = schema;
pdl->npoints = npoints;
pdl->bytes = pcalloc(ndims * sizeof(PCBYTES));
pdl->bytes = pcalloc(ndims * sizeof(PCBYTES));
pdl->readonly = PC_FALSE;
pdl->type = PC_DIMENSIONAL;
pdl->xmin = pa->xmin;
pdl->xmax = pa->xmax;
pdl->ymin = pa->ymin;
pdl->ymax = pa->ymax;
for ( i = 0; i < ndims; i++ )
{
PCDIMENSION *dim = pc_schema_get_dimension(schema, i);
@ -95,27 +95,27 @@ pc_patch_dimensional_compress(const PCPATCH_DIMENSIONAL *pdl, PCDIMSTATS *pds)
int i;
int ndims = pdl->schema->ndims;
PCPATCH_DIMENSIONAL *pdl_compressed;
assert(pdl);
assert(pdl->schema);
if ( ! pds )
pds = pc_dimstats_make(pdl->schema);
/* Still sampling, update stats */
if ( pds->total_points < PCDIMSTATS_MIN_SAMPLE )
pc_dimstats_update(pds, pdl);
pdl_compressed = pcalloc(sizeof(PCPATCH_DIMENSIONAL));
memcpy(pdl_compressed, pdl, sizeof(PCPATCH_DIMENSIONAL));
pdl_compressed->bytes = pcalloc(ndims*sizeof(PCBYTES));
/* Compress each dimension as dictated by stats */
for ( i = 0; i < ndims; i++ )
{
pdl_compressed->bytes[i] = pc_bytes_encode(pdl->bytes[i], pds->stats[i].recommended_compression);
}
return pdl_compressed;
}
@ -137,7 +137,7 @@ pc_patch_dimensional_decompress(const PCPATCH_DIMENSIONAL *pdl)
for ( i = 0; i < ndims; i++ )
{
pdl_decompressed->bytes[i] = pc_bytes_decode(pdl->bytes[i]);
}
}
return pdl_decompressed;
}
@ -148,7 +148,7 @@ pc_patch_dimensional_free(PCPATCH_DIMENSIONAL *pdl)
int i;
assert(pdl);
assert(pdl->schema);
if ( pdl->bytes )
{
for ( i = 0; i < pdl->schema->ndims; i++ )
@ -156,7 +156,7 @@ pc_patch_dimensional_free(PCPATCH_DIMENSIONAL *pdl)
pcfree(pdl->bytes);
}
pcfree(pdl);
}
@ -167,10 +167,10 @@ pc_patch_dimensional_compute_extent(PCPATCH_DIMENSIONAL *pdl)
double xmin, xmax, ymin, ymax;
int rv;
PCBYTES *pcb;
assert(pdl);
assert(pdl->schema);
/* Get x extremes */
pcb = &(pdl->bytes[pdl->schema->x_position]);
rv = pc_bytes_minmax(pcb, &xmin, &xmax);
@ -186,7 +186,7 @@ pc_patch_dimensional_compute_extent(PCPATCH_DIMENSIONAL *pdl)
ymax = pc_value_scale_offset(xmax, pdl->schema->dims[pdl->schema->y_position]);
pdl->ymin = ymin;
pdl->ymax = ymax;
return PC_SUCCESS;
}
@ -221,7 +221,7 @@ pc_patch_dimensional_to_wkb(const PCPATCH_DIMENSIONAL *patch, size_t *wkbsize)
size_t bsz;
PCBYTES *pcb = &(patch->bytes[i]);
// XXX printf("pcb->(size=%d, interp=%d, npoints=%d, compression=%d, readonly=%d)\n",pcb->size, pcb->interpretation, pcb->npoints, pcb->compression, pcb->readonly);
pc_bytes_serialize(pcb, buf, &bsz);
buf += bsz;
}
@ -231,7 +231,7 @@ pc_patch_dimensional_to_wkb(const PCPATCH_DIMENSIONAL *patch, size_t *wkbsize)
}
PCPATCH *
PCPATCH *
pc_patch_dimensional_from_wkb(const PCSCHEMA *schema, const uint8_t *wkb, size_t wkbsize)
{
/*
@ -247,16 +247,16 @@ pc_patch_dimensional_from_wkb(const PCSCHEMA *schema, const uint8_t *wkb, size_t
uint32_t npoints, ndims;
const uint8_t *buf;
int i;
if ( wkb_get_compression(wkb) != PC_DIMENSIONAL )
{
pcerror("pc_patch_dimensional_from_wkb: call with wkb that is not dimensionally compressed");
return NULL;
}
npoints = wkb_get_npoints(wkb);
ndims = schema->ndims;
patch = pcalloc(sizeof(PCPATCH_DIMENSIONAL));
patch->npoints = npoints;
patch->type = PC_DIMENSIONAL;

View File

@ -18,7 +18,7 @@ pc_patch_uncompressed_to_string(const PCPATCH_UNCOMPRESSED *patch)
PCPOINTLIST *pl;
char *str;
int i, j;
pl = pc_pointlist_from_uncompressed(patch);
stringbuffer_aprintf(sb, "{\"pcid\":%d,\"pts\":[", patch->schema->pcid);
for ( i = 0; i < pl->npoints; i++ )
@ -77,11 +77,11 @@ pc_patch_uncompressed_to_wkb(const PCPATCH_UNCOMPRESSED *patch, size_t *wkbsize)
memcpy(wkb + 9, &npoints, 4); /* Write npoints */
memcpy(wkb + 13, patch->data, patch->datasize); /* Write data */
if ( wkbsize ) *wkbsize = size;
return wkb;
return wkb;
}
PCPATCH *
PCPATCH *
pc_patch_uncompressed_from_wkb(const PCSCHEMA *s, const uint8_t *wkb, size_t wkbsize)
{
/*
@ -96,7 +96,7 @@ pc_patch_uncompressed_from_wkb(const PCSCHEMA *s, const uint8_t *wkb, size_t wkb
uint8_t *data;
uint8_t swap_endian = (wkb[0] != machine_endian());
uint32_t npoints;
if ( wkb_get_compression(wkb) != PC_NONE )
{
pcerror("pc_patch_uncompressed_from_wkb: call with wkb that is not uncompressed");
@ -109,7 +109,7 @@ pc_patch_uncompressed_from_wkb(const PCSCHEMA *s, const uint8_t *wkb, size_t wkb
pcerror("pc_patch_uncompressed_from_wkb: wkb size and expected data size do not match");
return NULL;
}
if ( swap_endian )
{
data = uncompressed_bytes_flip_endian(wkb+hdrsz, s, npoints);
@ -119,7 +119,7 @@ pc_patch_uncompressed_from_wkb(const PCSCHEMA *s, const uint8_t *wkb, size_t wkb
data = pcalloc(npoints * s->size);
memcpy(data, wkb+hdrsz, npoints*s->size);
}
patch = pcalloc(sizeof(PCPATCH_UNCOMPRESSED));
patch->npoints = npoints;
patch->type = PC_NONE;
@ -135,27 +135,27 @@ pc_patch_uncompressed_from_wkb(const PCSCHEMA *s, const uint8_t *wkb, size_t wkb
return (PCPATCH*)patch;
}
PCPATCH_UNCOMPRESSED *
PCPATCH_UNCOMPRESSED *
pc_patch_uncompressed_make(const PCSCHEMA *s, uint32_t maxpoints)
{
PCPATCH_UNCOMPRESSED *pch;
size_t datasize;
if ( ! s )
{
pcerror("null schema passed into pc_patch_uncompressed_make");
return NULL;
}
/* Width of the data area */
if ( ! s->size )
{
pcerror("invalid size calculation in pc_patch_uncompressed_make");
return NULL;
}
/* Make our own data area */
pch = pcalloc(sizeof(PCPATCH_UNCOMPRESSED));
pch = pcalloc(sizeof(PCPATCH_UNCOMPRESSED));
datasize = s->size * maxpoints;
pch->data = pcalloc(datasize);
pch->datasize = datasize;
@ -163,7 +163,7 @@ pc_patch_uncompressed_make(const PCSCHEMA *s, uint32_t maxpoints)
/* Initialize bounds */
pch->xmin = pch->ymin = MAXFLOAT;
pch->xmax = pch->ymax = -1 * MAXFLOAT;
/* Set up basic info */
pch->readonly = PC_FALSE;
pch->npoints = 0;
@ -182,7 +182,7 @@ pc_patch_uncompressed_compute_extent(PCPATCH_UNCOMPRESSED *patch)
/* Initialize bounds */
patch->xmin = patch->ymin = MAXFLOAT;
patch->xmax = patch->ymax = -1 * MAXFLOAT;
/* Calculate bounds */
for ( i = 0; i < patch->npoints; i++ )
{
@ -212,7 +212,7 @@ pc_patch_uncompressed_free(PCPATCH_UNCOMPRESSED *patch)
PCPATCH_UNCOMPRESSED *
PCPATCH_UNCOMPRESSED *
pc_patch_uncompressed_from_pointlist(const PCPOINTLIST *pl)
{
PCPATCH_UNCOMPRESSED *pch;
@ -221,7 +221,7 @@ pc_patch_uncompressed_from_pointlist(const PCPOINTLIST *pl)
uint8_t *ptr;
int i;
uint32_t numpts;
if ( ! pl )
{
pcerror("null PCPOINTLIST passed into pc_patch_uncompressed_from_pointlist");
@ -246,7 +246,7 @@ pc_patch_uncompressed_from_pointlist(const PCPOINTLIST *pl)
pcerror("pc_patch_uncompressed_from_pointlist: null schema encountered");
return NULL;
}
/* Confirm width of a point data buffer */
if ( ! s->size )
{
@ -255,7 +255,7 @@ pc_patch_uncompressed_from_pointlist(const PCPOINTLIST *pl)
}
/* Make our own data area */
pch = pcalloc(sizeof(PCPATCH_UNCOMPRESSED));
pch = pcalloc(sizeof(PCPATCH_UNCOMPRESSED));
pch->datasize = s->size * numpts;
pch->data = pcalloc(pch->datasize);
ptr = pch->data;
@ -263,7 +263,7 @@ pc_patch_uncompressed_from_pointlist(const PCPOINTLIST *pl)
/* Initialize bounds */
pch->xmin = pch->ymin = MAXFLOAT;
pch->xmax = pch->ymax = -1 * MAXFLOAT;
/* Set up basic info */
pch->readonly = PC_FALSE;
pch->maxpoints = numpts;
@ -297,7 +297,7 @@ pc_patch_uncompressed_from_pointlist(const PCPOINTLIST *pl)
return NULL;
}
return pch;
return pch;
}
@ -309,7 +309,7 @@ pc_patch_uncompressed_from_dimensional(const PCPATCH_DIMENSIONAL *pdl)
PCPATCH_DIMENSIONAL *pdl_uncompressed;
const PCSCHEMA *schema;
uint8_t *buf;
npoints = pdl->npoints;
schema = pdl->schema;
patch = pcalloc(sizeof(PCPATCH_UNCOMPRESSED));
@ -325,10 +325,10 @@ pc_patch_uncompressed_from_dimensional(const PCPATCH_DIMENSIONAL *pdl)
patch->datasize = schema->size * pdl->npoints;
patch->data = pcalloc(patch->datasize);
buf = patch->data;
/* Can only read from uncompressed dimensions */
pdl_uncompressed = pc_patch_dimensional_decompress(pdl);
for ( i = 0; i < npoints; i++ )
{
for ( j = 0; j < schema->ndims; j++ )
@ -340,26 +340,26 @@ pc_patch_uncompressed_from_dimensional(const PCPATCH_DIMENSIONAL *pdl)
}
buf += schema->size;
}
pc_patch_dimensional_free(pdl_uncompressed);
return patch;
}
int
int
pc_patch_uncompressed_add_point(PCPATCH_UNCOMPRESSED *c, const PCPOINT *p)
{
size_t sz;
uint8_t *ptr;
double x, y;
if ( ! ( c && p ) )
{
pcerror("pc_patch_uncompressed_add_point: null point or patch argument");
return PC_FAILURE;
}
if ( c->schema->pcid != p->schema->pcid )
{
pcerror("pc_patch_uncompressed_add_point: pcids of point (%d) and patch (%d) not equal", c->schema->pcid, p->schema->pcid);
@ -377,9 +377,9 @@ pc_patch_uncompressed_add_point(PCPATCH_UNCOMPRESSED *c, const PCPOINT *p)
pcerror("pc_patch_uncompressed_add_point: cannot add point to compressed patch");
return PC_FAILURE;
}
sz = c->schema->size;
/* Double the data buffer if it's already full */
if ( c->npoints == c->maxpoints )
{
@ -387,12 +387,12 @@ pc_patch_uncompressed_add_point(PCPATCH_UNCOMPRESSED *c, const PCPOINT *p)
c->datasize = c->maxpoints * sz;
c->data = pcrealloc(c->data, c->datasize);
}
/* Copy the data buffer from point to patch */
ptr = c->data + sz * c->npoints;
memcpy(ptr, p->data, sz);
c->npoints += 1;
/* Update bounding box */
x = pc_point_get_x(p);
y = pc_point_get_y(p);
@ -400,6 +400,6 @@ pc_patch_uncompressed_add_point(PCPATCH_UNCOMPRESSED *c, const PCPOINT *p)
if ( c->ymin > y ) c->ymin = y;
if ( c->xmax < x ) c->xmax = x;
if ( c->ymax < y ) c->ymax = y;
return PC_SUCCESS;
return PC_SUCCESS;
}

View File

@ -11,18 +11,18 @@
#include "pc_api_internal.h"
#include "stringbuffer.h"
PCPOINT *
PCPOINT *
pc_point_make(const PCSCHEMA *s)
{
size_t sz;
PCPOINT *pt;
if ( ! s )
{
pcerror("null schema passed into pc_point_make");
return NULL;
}
/* Width of the data area */
sz = s->size;
if ( ! sz )
@ -30,34 +30,34 @@ pc_point_make(const PCSCHEMA *s)
pcerror("invalid size calculation in pc_point_make");
return NULL;
}
/* Make our own data area */
pt = pcalloc(sizeof(PCPOINT));
pt = pcalloc(sizeof(PCPOINT));
pt->data = pcalloc(sz);
/* Set up basic info */
pt->schema = s;
pt->readonly = PC_FALSE;
return pt;
};
PCPOINT *
PCPOINT *
pc_point_from_data(const PCSCHEMA *s, const uint8_t *data)
{
size_t sz;
PCPOINT *pt;
uint32_t pcid;
if ( ! s )
{
pcerror("null schema passed into pc_point_from_data");
return NULL;
}
/* Reference the external data */
pt = pcalloc(sizeof(PCPOINT));
pt->data = (uint8_t*)data;
/* Set up basic info */
pt->schema = s;
pt->readonly = PC_TRUE;
@ -80,7 +80,7 @@ pc_point_get_double(const PCPOINT *pt, const PCDIMENSION *dim, double *d)
{
uint8_t *ptr;
double val;
/* Read raw value from byte buffer */
ptr = pt->data + dim->byteoffset;
val = pc_double_from_ptr(ptr, dim->interpretation);
@ -92,7 +92,7 @@ pc_point_get_double(const PCPOINT *pt, const PCDIMENSION *dim, double *d)
/* Offset value */
if ( dim->offset )
val += dim->offset;
*d = val;
return PC_SUCCESS;
}
@ -115,7 +115,7 @@ pc_point_get_double_by_index(const PCPOINT *pt, uint32_t idx, double *d)
return pc_point_get_double(pt, dim, d);
}
int
int
pc_point_set_double(PCPOINT *pt, const PCDIMENSION *d, double val)
{
uint8_t *ptr;
@ -130,11 +130,11 @@ pc_point_set_double(PCPOINT *pt, const PCDIMENSION *d, double val)
/* Get pointer into byte buffer */
ptr = pt->data + d->byteoffset;
return pc_double_to_ptr(ptr, d->interpretation, val);
}
int
int
pc_point_set_double_by_index(PCPOINT *pt, uint32_t idx, double val)
{
PCDIMENSION *d;
@ -142,7 +142,7 @@ pc_point_set_double_by_index(PCPOINT *pt, uint32_t idx, double val)
return pc_point_set_double(pt, d, val);
}
int
int
pc_point_set_double_by_name(PCPOINT *pt, const char *name, double val)
{
PCDIMENSION *d;
@ -158,7 +158,7 @@ pc_point_get_x(const PCPOINT *pt)
return d;
}
double
double
pc_point_get_y(const PCPOINT *pt)
{
double d;
@ -173,7 +173,7 @@ pc_point_to_string(const PCPOINT *pt)
stringbuffer_t *sb = stringbuffer_create();
char *str;
int i;
stringbuffer_aprintf(sb, "{\"pcid\":%d,\"pt\":[", pt->schema->pcid);
for ( i = 0; i < pt->schema->ndims; i++ )
{
@ -194,7 +194,7 @@ pc_point_to_string(const PCPOINT *pt)
return str;
}
PCPOINT *
PCPOINT *
pc_point_from_double_array(const PCSCHEMA *s, double *array, uint32_t nelems)
{
int i;
@ -205,7 +205,7 @@ pc_point_from_double_array(const PCSCHEMA *s, double *array, uint32_t nelems)
pcerror("null schema passed into pc_point_from_double_array");
return NULL;
}
if ( s->ndims != nelems )
{
pcerror("number of elements in schema and array differ in pc_point_from_double_array");
@ -213,11 +213,11 @@ pc_point_from_double_array(const PCSCHEMA *s, double *array, uint32_t nelems)
}
/* Reference the external data */
pt = pcalloc(sizeof(PCPOINT));
pt = pcalloc(sizeof(PCPOINT));
pt->data = pcalloc(s->size);
pt->schema = s;
pt->readonly = PC_FALSE;
for ( i = 0; i < nelems; i++ )
{
if ( PC_FAILURE == pc_point_set_double_by_index(pt, i, array[i]) )
@ -226,7 +226,7 @@ pc_point_from_double_array(const PCSCHEMA *s, double *array, uint32_t nelems)
return NULL;
}
}
return pt;
}
@ -243,20 +243,20 @@ pc_point_from_wkb(const PCSCHEMA *schema, uint8_t *wkb, size_t wkblen)
uint32_t pcid;
uint8_t *data;
PCPOINT *pt;
if ( ! wkblen )
{
pcerror("pc_point_from_wkb: zero length wkb");
}
wkb_endian = wkb[0];
pcid = wkb_get_pcid(wkb);
if ( (wkblen-hdrsz) != schema->size )
{
pcerror("pc_point_from_wkb: wkb size inconsistent with schema size");
}
if ( wkb_endian != machine_endian() )
{
/* uncompressed_bytes_flip_endian creates a flipped copy */
@ -302,10 +302,10 @@ pc_point_to_geometry_wkb(const PCPOINT *pt, size_t *wkbsize)
uint32_t srid;
int has_srid = PC_FALSE, has_z = PC_FALSE;
double x, y, z;
x = pc_point_get_x(pt);
y = pc_point_get_y(pt);
if ( pt->schema->srid > 0 )
{
has_srid = PC_TRUE;
@ -313,7 +313,7 @@ pc_point_to_geometry_wkb(const PCPOINT *pt, size_t *wkbsize)
size += 4;
srid = pt->schema->srid;
}
if ( pc_point_get_double_by_name(pt, "Z", &z) )
{
has_z = PC_TRUE;
@ -326,19 +326,19 @@ pc_point_to_geometry_wkb(const PCPOINT *pt, size_t *wkbsize)
ptr[0] = machine_endian(); /* Endian flag */
ptr += 1;
memcpy(ptr, &wkbtype, 4); /* WKB type */
ptr += 4;
if ( has_srid )
{
memcpy(ptr, &srid, 4); /* SRID */
ptr += 4;
}
memcpy(ptr, &x, 8); /* X */
ptr += 8;
memcpy(ptr, &y, 8); /* Y */
ptr += 8;
@ -347,7 +347,7 @@ pc_point_to_geometry_wkb(const PCPOINT *pt, size_t *wkbsize)
memcpy(ptr, &z, 8); /* Z */
ptr += 8;
}
if ( wkbsize ) *wkbsize = size;
return wkb;
}

View File

@ -44,7 +44,7 @@ pc_pointlist_add_point(PCPOINTLIST *pl, PCPOINT *pt)
pl->maxpoints *= 2;
pl->points = pcrealloc(pl->points, pl->maxpoints * sizeof(PCPOINT*));
}
pl->points[pl->npoints] = pt;
pl->npoints += 1;
return;
@ -64,20 +64,20 @@ pc_pointlist_from_dimensional(const PCPATCH_DIMENSIONAL *pdl)
const PCSCHEMA *schema = pdl->schema;
int i, j, ndims, npoints;
assert(pdl);
pdl_uncompressed = pc_patch_dimensional_decompress(pdl);
ndims = schema->ndims;
npoints = pdl->npoints;
pl = pc_pointlist_make(npoints);
for ( i = 0; i < npoints; i++ )
{
PCPOINT *pt = pc_point_make(schema);
for ( j = 0; j < ndims; j++ )
{
PCDIMENSION *dim = pc_schema_get_dimension(schema, j);
uint8_t *in = pdl_uncompressed->bytes[j].bytes + dim->size * i;
uint8_t *out = pt->data + dim->byteoffset;
memcpy(out, in, dim->size);
@ -85,7 +85,7 @@ pc_pointlist_from_dimensional(const PCPATCH_DIMENSIONAL *pdl)
pc_pointlist_add_point(pl, pt);
}
pc_patch_dimensional_free(pdl_uncompressed);
return pl;
}
@ -96,7 +96,7 @@ pc_pointlist_from_uncompressed(const PCPATCH_UNCOMPRESSED *patch)
PCPOINTLIST *pl;
size_t pt_size = patch->schema->size;
uint32_t npoints = patch->npoints;
pl = pc_pointlist_make(npoints);
for ( i = 0; i < npoints; i++ )
{
@ -105,7 +105,7 @@ pc_pointlist_from_uncompressed(const PCPATCH_UNCOMPRESSED *patch)
return pl;
}
PCPOINTLIST *
PCPOINTLIST *
pc_pointlist_from_patch(const PCPATCH *patch)
{
switch ( patch->type )
@ -123,7 +123,7 @@ pc_pointlist_from_patch(const PCPATCH *patch)
return pc_pointlist_from_dimensional((PCPATCH_DIMENSIONAL*)patch);
}
}
/* Don't get here */
pcerror("pc_pointlist_from_patch: unsupported compression type %d", patch->type);
return NULL;

View File

@ -16,7 +16,7 @@
/** Convert XML string token to type interpretation number */
static const char *
static const char *
pc_interpretation_string(uint32_t interp)
{
if ( interp >= 0 && interp < NUM_INTERPRETATIONS )
@ -27,7 +27,7 @@ pc_interpretation_string(uint32_t interp)
/** Convert XML string token to type interpretation number */
static int
static int
pc_interpretation_number(const char *str)
{
if ( str[0] == 'i' || str[0] == 'I' )
@ -64,12 +64,12 @@ pc_interpretation_number(const char *str)
return PC_UNKNOWN;
}
static int
static int
pc_compression_number(const char *str)
{
if ( ! str )
if ( ! str )
return PC_NONE;
if ( (str[0] == 'd' || str[0] == 'D') &&
(strcasecmp(str, "dimensional") == 0) )
{
@ -87,7 +87,7 @@ pc_compression_number(const char *str)
{
return PC_NONE;
}
return PC_NONE;
}
@ -142,7 +142,7 @@ static PCSCHEMA*
pc_schema_new(uint32_t ndims)
{
PCSCHEMA *pcs = pcalloc(sizeof(PCSCHEMA));
pcs->dims = pcalloc(sizeof(PCDIMENSION*) * ndims);
pcs->dims = pcalloc(sizeof(PCDIMENSION*) * ndims);
pcs->namehash = create_string_hashtable();
pcs->ndims = ndims;
pcs->x_position = -1;
@ -199,7 +199,7 @@ pc_schema_clone(const PCSCHEMA *s)
/** Release the memory behind the PCSCHEMA struct */
void
void
pc_schema_free(PCSCHEMA *pcs)
{
int i;
@ -216,19 +216,19 @@ pc_schema_free(PCSCHEMA *pcs)
if ( pcs->namehash )
hashtable_destroy(pcs->namehash, 0);
pcfree(pcs);
}
/** Convert a PCSCHEMA to a human-readable JSON string */
char *
char *
pc_schema_to_json(const PCSCHEMA *pcs)
{
int i;
char *str;
stringbuffer_t *sb = stringbuffer_create();
stringbuffer_append(sb, "{");
if ( pcs->pcid )
stringbuffer_aprintf(sb, "\"pcid\" : %d,\n", pcs->pcid);
if ( pcs->srid )
@ -239,9 +239,9 @@ pc_schema_to_json(const PCSCHEMA *pcs)
if ( pcs->ndims )
{
stringbuffer_append(sb, "\"dims\" : [\n");
for ( i = 0; i < pcs->ndims; i++ )
{
if ( pcs->dims[i] )
@ -279,7 +279,7 @@ static void pc_schema_check_xy(const PCSCHEMA *s)
{
if ( s->x_position < 0 )
pcerror("pc_schema_check_xy: invalid x_position '%d'", s->x_position);
if ( s->y_position < 0 )
pcerror("pc_schema_check_xy: invalid y_position '%d'", s->y_position);
}
@ -309,23 +309,23 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
xmlDocPtr xml_doc = NULL;
xmlNodePtr xml_root = NULL;
xmlNsPtr xml_ns = NULL;
xmlXPathContextPtr xpath_ctx;
xmlXPathObjectPtr xpath_obj;
xmlXPathContextPtr xpath_ctx;
xmlXPathObjectPtr xpath_obj;
xmlNodeSetPtr nodes;
PCSCHEMA *s;
const char *xml_ptr = xml_str;
/* Roll forward to start of XML string */
while( (*xml_ptr != '\0') && (*xml_ptr != '<') )
{
xml_ptr++;
}
size_t xml_size = strlen(xml_ptr);
static xmlChar *xpath_str = "/pc:PointCloudSchema/pc:dimension";
static xmlChar *xpath_metadata_str = "/pc:PointCloudSchema/pc:metadata/Metadata";
/* Parse XML doc */
*schema = NULL;
xmlInitParser();
@ -336,12 +336,12 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
pcwarn("unable to parse schema XML");
return PC_FAILURE;
}
/* Capture the namespace */
xml_root = xmlDocGetRootElement(xml_doc);
if ( xml_root->ns )
xml_ns = xml_root->ns;
/* Create xpath evaluation context */
xpath_ctx = xmlXPathNewContext(xml_doc);
if( ! xpath_ctx )
@ -355,12 +355,12 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
/* Register the root namespace if there is one */
if ( xml_ns )
xmlXPathRegisterNs(xpath_ctx, "pc", xml_ns->href);
/* Evaluate xpath expression */
xpath_obj = xmlXPathEvalExpression(xpath_str, xpath_ctx);
if( ! xpath_obj )
{
xmlXPathFreeContext(xpath_ctx);
xmlXPathFreeContext(xpath_ctx);
xmlFreeDoc(xml_doc);
xmlCleanupParser();
pcwarn("unable to evaluate xpath expression \"%s\" against schema XML", xpath_str);
@ -374,7 +374,7 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
int i;
s = pc_schema_new(ndims);
*schema = s;
for ( i = 0; i < ndims; i++ )
{
/* This is a "dimension" */
@ -384,7 +384,7 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
xmlNodePtr child;
PCDIMENSION *d = pc_dimension_new();
char xydim = 0;
/* These are the values of the dimension */
for ( child = cur->children; child; child = child->next )
{
@ -428,17 +428,17 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
pcinfo("unhandled schema type element \"%s\" encountered", child->name);
}
}
/* Convert interprestation to size */
d->size = pc_interpretation_size(d->interpretation);
/* Store the dimension in the schema */
if ( d->position >= 0 && d->position < ndims )
{
if ( s->dims[d->position] )
{
xmlXPathFreeObject(xpath_obj);
xmlXPathFreeContext(xpath_ctx);
xmlXPathFreeContext(xpath_ctx);
xmlFreeDoc(xml_doc);
xmlCleanupParser();
pc_schema_free(s);
@ -452,7 +452,7 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
else
{
xmlXPathFreeObject(xpath_obj);
xmlXPathFreeContext(xpath_ctx);
xmlXPathFreeContext(xpath_ctx);
xmlFreeDoc(xml_doc);
xmlCleanupParser();
pc_schema_free(s);
@ -461,26 +461,26 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
}
}
}
/* Complete the byte offsets of dimensions from the ordered sizes */
pc_schema_calculate_byteoffsets(s);
/* Check X/Y positions */
pc_schema_check_xy(s);
}
xmlXPathFreeObject(xpath_obj);
/* SEARCH FOR METADATA ENTRIES */
xpath_obj = xmlXPathEvalExpression(xpath_metadata_str, xpath_ctx);
if( ! xpath_obj )
{
xmlXPathFreeContext(xpath_ctx);
xmlXPathFreeContext(xpath_ctx);
xmlFreeDoc(xml_doc);
xmlCleanupParser();
pcwarn("unable to evaluate xpath expression \"%s\" against schema XML", xpath_metadata_str);
return PC_FAILURE;
}
/* Iterate on the <Metadata> we find */
if ( nodes = xpath_obj->nodesetval )
{
@ -498,7 +498,7 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
metadata_name = xmlGetProp(cur, "name");
metadata_value = xml_node_get_content(cur);
}
/* Store the compression type on the schema */
if ( strcmp(metadata_name, "compression") == 0 )
{
@ -511,13 +511,13 @@ pc_schema_from_xml(const char *xml_str, PCSCHEMA **schema)
xmlFree(metadata_name);
}
}
xmlXPathFreeObject(xpath_obj);
xmlXPathFreeContext(xpath_ctx);
xmlXPathFreeContext(xpath_ctx);
xmlFreeDoc(xml_doc);
xmlCleanupParser();
return PC_SUCCESS;
}
@ -525,7 +525,7 @@ uint32_t
pc_schema_is_valid(const PCSCHEMA *s)
{
int i;
if ( s->x_position < 0 )
{
pcwarn("schema does not include an X coordinate");
@ -537,13 +537,13 @@ pc_schema_is_valid(const PCSCHEMA *s)
pcwarn("schema does not include a Y coordinate");
return PC_FALSE;
}
if ( ! s->ndims )
{
pcwarn("schema has no dimensions");
return PC_FALSE;
}
for ( i = 0; i < s->ndims; i++ )
{
if ( ! s->dims[i] )
@ -552,7 +552,7 @@ pc_schema_is_valid(const PCSCHEMA *s)
return PC_FALSE;
}
}
return PC_TRUE;
}

View File

@ -40,7 +40,7 @@ static uint8_t hex2char[256] = {
};
uint8_t*
uint8_t*
bytes_from_hexbytes(const char *hexbuf, size_t hexsize)
{
uint8_t *buf = NULL;
@ -69,13 +69,13 @@ bytes_from_hexbytes(const char *hexbuf, size_t hexsize)
return buf;
}
char*
char*
hexbytes_from_bytes(const uint8_t *bytebuf, size_t bytesize)
{
char *buf = pcalloc(2*bytesize + 1); /* 2 chars per byte + null terminator */
int i;
char *ptr = buf;
for ( i = 0; i < bytesize; i++ )
{
int incr = snprintf(ptr, 3, "%02X", bytebuf[i]);
@ -86,7 +86,7 @@ hexbytes_from_bytes(const uint8_t *bytebuf, size_t bytesize)
}
ptr += incr;
}
return buf;
}
@ -136,7 +136,7 @@ wkb_get_int32(const uint8_t *wkb, int flip_endian)
{
int32_t i;
memcpy(&i, wkb, 4);
if ( flip_endian )
if ( flip_endian )
return int32_flip_endian(i);
else
return i;
@ -147,7 +147,7 @@ wkb_get_int16(const uint8_t *wkb, int flip_endian)
{
int16_t i;
memcpy(&i, wkb, 2);
if ( flip_endian )
if ( flip_endian )
return int16_flip_endian(i);
else
return i;
@ -203,7 +203,7 @@ wkb_get_npoints(const uint8_t *wkb)
}
return npoints;
}
uint8_t*
uint8_t*
uncompressed_bytes_flip_endian(const uint8_t *bytebuf, const PCSCHEMA *schema, uint32_t npoints)
{
int i, j, k;
@ -211,14 +211,14 @@ uncompressed_bytes_flip_endian(const uint8_t *bytebuf, const PCSCHEMA *schema, u
uint8_t *buf = pcalloc(bufsize);
memcpy(buf, bytebuf, bufsize);
for ( i = 0; i < npoints ; i++ )
{
for ( j = 0; j < schema->ndims; j++ )
{
PCDIMENSION *dimension = schema->dims[j];
uint8_t *ptr = buf + i * schema->size + dimension->byteoffset;
for ( k = 0; k < ((dimension->size)/2); k++ )
{
int l = dimension->size - k - 1;
@ -228,17 +228,17 @@ uncompressed_bytes_flip_endian(const uint8_t *bytebuf, const PCSCHEMA *schema, u
}
}
}
return buf;
}
typedef struct
typedef struct
{
uint8_t *buf;
uint8_t *ptr;
size_t sz;
} bytebuffer_t;
static bytebuffer_t *
bytebuffer_new(void)
{
@ -248,7 +248,7 @@ bytebuffer_new(void)
bb->ptr = bb->buf;
}
static void
static void
bytebuffer_destroy(bytebuffer_t *bb)
{
pcfree(bb->buf);

View File

@ -20,8 +20,8 @@ double pc_value_scale_offset(double val, const PCDIMENSION *dim)
/* Offset value */
if ( dim->offset )
val += dim->offset;
return val;
return val;
}
double
@ -31,10 +31,10 @@ pc_value_from_ptr(const uint8_t *ptr, const PCDIMENSION *dim)
return pc_value_scale_offset(val, dim);
}
double
double
pc_double_from_ptr(const uint8_t *ptr, uint32_t interpretation)
{
switch( interpretation )
{
switch( interpretation )
{
case PC_UINT8:
{
@ -105,10 +105,10 @@ pc_double_from_ptr(const uint8_t *ptr, uint32_t interpretation)
}
int
int
pc_double_to_ptr(uint8_t *ptr, uint32_t interpretation, double val)
{
switch( interpretation )
{
switch( interpretation )
{
case PC_UINT8:
{

View File

@ -40,7 +40,7 @@
/**
* Allocate a new stringbuffer_t. Use stringbuffer_destroy to free.
*/
stringbuffer_t*
stringbuffer_t*
stringbuffer_create(void)
{
return stringbuffer_create_with_size(STRINGBUFFER_STARTSIZE);
@ -49,7 +49,7 @@ stringbuffer_create(void)
/**
* Allocate a new stringbuffer_t. Use stringbuffer_destroy to free.
*/
stringbuffer_t*
stringbuffer_t*
stringbuffer_create_with_size(size_t size)
{
stringbuffer_t *s;
@ -65,7 +65,7 @@ stringbuffer_create_with_size(size_t size)
/**
* Free the stringbuffer_t and all memory managed within it.
*/
void
void
stringbuffer_destroy(stringbuffer_t *s)
{
if ( s->str_start ) free(s->str_start);
@ -77,7 +77,7 @@ stringbuffer_destroy(stringbuffer_t *s)
* without the expense of freeing and re-allocating a new
* stringbuffer_t.
*/
void
void
stringbuffer_clear(stringbuffer_t *s)
{
s->str_start[0] = '\0';
@ -88,7 +88,7 @@ stringbuffer_clear(stringbuffer_t *s)
* If necessary, expand the stringbuffer_t internal buffer to accomodate the
* specified additional size.
*/
static inline void
static inline void
stringbuffer_makeroom(stringbuffer_t *s, size_t size_to_add)
{
size_t current_size = (s->str_end - s->str_start);
@ -109,19 +109,19 @@ stringbuffer_makeroom(stringbuffer_t *s, size_t size_to_add)
/**
* Return the last character in the buffer.
*/
char
char
stringbuffer_lastchar(stringbuffer_t *s)
{
if( s->str_end == s->str_start )
if( s->str_end == s->str_start )
return 0;
return *(s->str_end - 1);
}
/**
* Append the specified string to the stringbuffer_t.
*/
void
void
stringbuffer_append(stringbuffer_t *s, const char *a)
{
int alen = strlen(a); /* Length of string to append */
@ -136,7 +136,7 @@ stringbuffer_append(stringbuffer_t *s, const char *a)
* the stringbuffer. The current string will be null-terminated
* within the internal string.
*/
const char*
const char*
stringbuffer_getstring(stringbuffer_t *s)
{
return s->str_start;
@ -147,7 +147,7 @@ stringbuffer_getstring(stringbuffer_t *s)
* current state of the string. Caller is responsible for
* freeing the return value.
*/
char*
char*
stringbuffer_getstringcopy(stringbuffer_t *s)
{
size_t size = (s->str_end - s->str_start) + 1;
@ -161,7 +161,7 @@ stringbuffer_getstringcopy(stringbuffer_t *s)
* Returns the length of the current string, not including the
* null terminator (same behavior as strlen()).
*/
int
int
stringbuffer_getlength(stringbuffer_t *s)
{
return (s->str_end - s->str_start);
@ -170,7 +170,7 @@ stringbuffer_getlength(stringbuffer_t *s)
/**
* Clear the stringbuffer_t and re-start it with the specified string.
*/
void
void
stringbuffer_set(stringbuffer_t *s, const char *str)
{
stringbuffer_clear(s);
@ -180,7 +180,7 @@ stringbuffer_set(stringbuffer_t *s, const char *str)
/**
* Copy the contents of src into dst.
*/
void
void
stringbuffer_copy(stringbuffer_t *dst, stringbuffer_t *src)
{
stringbuffer_set(dst, stringbuffer_getstring(src));
@ -191,7 +191,7 @@ stringbuffer_copy(stringbuffer_t *dst, stringbuffer_t *src)
* using the format and argument list provided. Returns -1 on error,
* check errno for reasons, documented in the printf man page.
*/
static int
static int
stringbuffer_avprintf(stringbuffer_t *s, const char *fmt, va_list ap)
{
int maxlen = (s->capacity - (s->str_end - s->str_start));
@ -205,7 +205,7 @@ stringbuffer_avprintf(stringbuffer_t *s, const char *fmt, va_list ap)
va_end(ap2);
/* Propogate errors up */
if ( len < 0 )
if ( len < 0 )
return len;
/* We didn't have enough space! */
@ -236,7 +236,7 @@ stringbuffer_avprintf(stringbuffer_t *s, const char *fmt, va_list ap)
* Returns -1 on error, check errno for reasons,
* as documented in the printf man page.
*/
int
int
stringbuffer_aprintf(stringbuffer_t *s, const char *fmt, ...)
{
int r;
@ -251,15 +251,15 @@ stringbuffer_aprintf(stringbuffer_t *s, const char *fmt, ...)
* Trims whitespace off the end of the stringbuffer. Returns
* the number of characters trimmed.
*/
int
int
stringbuffer_trim_trailing_white(stringbuffer_t *s)
{
char *ptr = s->str_end;
int dist = 0;
/* Roll backwards until we hit a non-space. */
while( ptr > s->str_start )
{
{
ptr--;
if( (*ptr == ' ') || (*ptr == '\t') )
{
@ -274,7 +274,7 @@ stringbuffer_trim_trailing_white(stringbuffer_t *s)
return dist;
}
}
return dist;
return dist;
}
/**
@ -282,24 +282,24 @@ stringbuffer_trim_trailing_white(stringbuffer_t *s)
* The number has to be the very last thing in the buffer. Only the
* last number will be trimmed. Returns the number of characters
* trimmed.
*
*
* eg: 1.22000 -> 1.22
* 1.0 -> 1
* 0.0 -> 0
*/
int
int
stringbuffer_trim_trailing_zeroes(stringbuffer_t *s)
{
char *ptr = s->str_end;
char *decimal_ptr = NULL;
int dist;
if ( s->str_end - s->str_start < 2)
if ( s->str_end - s->str_start < 2)
return 0;
/* Roll backwards to find the decimal for this number */
while( ptr > s->str_start )
{
{
ptr--;
if ( *ptr == '.' )
{
@ -315,9 +315,9 @@ stringbuffer_trim_trailing_zeroes(stringbuffer_t *s)
/* No decimal? Nothing to trim! */
if ( ! decimal_ptr )
return 0;
ptr = s->str_end;
/* Roll backwards again, with the decimal as stop point, trimming contiguous zeroes */
while( ptr >= decimal_ptr )
{
@ -327,13 +327,13 @@ stringbuffer_trim_trailing_zeroes(stringbuffer_t *s)
else
break;
}
/* Huh, we get anywhere. Must not have trimmed anything. */
if ( ptr == s->str_end )
return 0;
/* If we stopped at the decimal, we want to null that out.
It we stopped on a numeral, we want to preserve that, so push the
/* If we stopped at the decimal, we want to null that out.
It we stopped on a numeral, we want to preserve that, so push the
pointer forward one space. */
if ( *ptr != '.' )
ptr++;

View File

@ -52,13 +52,13 @@ Datum pcpoint_get_value(PG_FUNCTION_ARGS)
PCSCHEMA *schema = pc_schema_from_pcid(serpt->pcid, fcinfo);
PCPOINT *pt = pc_point_deserialize(serpt, schema);
if ( ! pt )
PG_RETURN_NULL();
PG_RETURN_NULL();
dim_str = text_to_cstring(dim_name);
dim_str = text_to_cstring(dim_name);
if ( ! pc_point_get_double_by_name(pt, dim_str, &double_result) )
{
pc_point_free(pt);
elog(ERROR, "dimension \"%s\" does not exist in schema", dim_str);
elog(ERROR, "dimension \"%s\" does not exist in schema", dim_str);
}
pfree(dim_str);
pc_point_free(pt);
@ -99,9 +99,9 @@ pcpatch_from_point_array(ArrayType *array, FunctionCallInfoData *fcinfo)
bitmap = ARR_NULLBITMAP(array);
/* Empty array? Null return */
if ( nelems == 0 )
if ( nelems == 0 )
return NULL;
/* Make our holder */
pl = pc_pointlist_make(nelems);
@ -115,13 +115,13 @@ pcpatch_from_point_array(ArrayType *array, FunctionCallInfoData *fcinfo)
{
SERIALIZED_POINT *serpt = (SERIALIZED_POINT *)(ARR_DATA_PTR(array)+offset);
PCPOINT *pt;
if ( ! schema )
{
schema = pc_schema_from_pcid(serpt->pcid, fcinfo);
}
if ( ! pcid )
if ( ! pcid )
{
pcid = serpt->pcid;
}
@ -129,20 +129,20 @@ pcpatch_from_point_array(ArrayType *array, FunctionCallInfoData *fcinfo)
{
elog(ERROR, "pcpatch_from_point_array: pcid mismatch (%d != %d)", serpt->pcid, pcid);
}
pt = pc_point_deserialize(serpt, schema);
if ( ! pt )
{
elog(ERROR, "pcpatch_from_point_array: point deserialization failed");
}
pc_pointlist_add_point(pl, pt);
offset += INTALIGN(VARSIZE(serpt));
offset += INTALIGN(VARSIZE(serpt));
}
}
if ( pl->npoints == 0 )
return NULL;
@ -173,9 +173,9 @@ pcpatch_from_patch_array(ArrayType *array, FunctionCallInfoData *fcinfo)
bitmap = ARR_NULLBITMAP(array);
/* Empty array? Null return */
if ( nelems == 0 )
if ( nelems == 0 )
return NULL;
/* Make our temporary list of patches */
palist = pcalloc(nelems*sizeof(PCPATCH*));
@ -189,13 +189,13 @@ pcpatch_from_patch_array(ArrayType *array, FunctionCallInfoData *fcinfo)
if ( ! array_get_isnull(bitmap, i) )
{
SERIALIZED_PATCH *serpatch = (SERIALIZED_PATCH *)(ARR_DATA_PTR(array)+offset);
if ( ! schema )
{
schema = pc_schema_from_pcid(serpatch->pcid, fcinfo);
}
if ( ! pcid )
if ( ! pcid )
{
pcid = serpatch->pcid;
}
@ -203,34 +203,34 @@ pcpatch_from_patch_array(ArrayType *array, FunctionCallInfoData *fcinfo)
{
elog(ERROR, "pcpatch_from_patch_array: pcid mismatch (%d != %d)", serpatch->pcid, pcid);
}
pa = pc_patch_deserialize(serpatch, schema);
if ( ! pa )
{
elog(ERROR, "pcpatch_from_patch_array: patch deserialization failed");
}
palist[numpatches++] = pa;
offset += INTALIGN(VARSIZE(serpatch));
}
}
/* Can't do anything w/ NULL */
if ( numpatches == 0 )
return NULL;
/* Pass to the lib to build the output patch from the list */
pa = pc_patch_from_patchlist(palist, numpatches);
/* Free the temporary patch list */
for ( i = 0; i < numpatches; i++ )
{
pc_patch_free(palist[i]);
}
pcfree(palist);
return pa;
}
@ -359,7 +359,7 @@ pointcloud_agg_final(abs_trans *a, MemoryContext mctx, FunctionCallInfo fcinfo)
state = a->s;
dims[0] = state->nelems;
lbs[0] = 1;
return makeMdArrayResult(state, 1, dims, lbs, mctx, false);
return makeMdArrayResult(state, 1, dims, lbs, mctx, false);
}
PG_FUNCTION_INFO_V1(pcpoint_agg_final_array);
@ -370,9 +370,9 @@ Datum pcpoint_agg_final_array(PG_FUNCTION_ARGS)
if (PG_ARGISNULL(0))
PG_RETURN_NULL(); /* returns null iff no input values */
a = (abs_trans*) PG_GETARG_POINTER(0);
result = pointcloud_agg_final(a, CurrentMemoryContext, fcinfo);
PG_RETURN_DATUM(result);
}
@ -386,9 +386,9 @@ Datum pcpatch_agg_final_array(PG_FUNCTION_ARGS)
if (PG_ARGISNULL(0))
PG_RETURN_NULL(); /* returns null iff no input values */
a = (abs_trans*) PG_GETARG_POINTER(0);
result = pointcloud_agg_final(a, CurrentMemoryContext, fcinfo);
PG_RETURN_DATUM(result);
}
@ -411,7 +411,7 @@ Datum pcpoint_agg_final_pcpatch(PG_FUNCTION_ARGS)
pa = pcpatch_from_point_array(array, fcinfo);
if ( ! pa )
PG_RETURN_NULL();
serpa = pc_patch_serialize(pa, NULL);
pc_patch_free(pa);
PG_RETURN_POINTER(serpa);
@ -435,7 +435,7 @@ Datum pcpatch_agg_final_pcpatch(PG_FUNCTION_ARGS)
pa = pcpatch_from_patch_array(array, fcinfo);
if ( ! pa )
PG_RETURN_NULL();
serpa = pc_patch_serialize(pa, NULL);
pc_patch_free(pa);
PG_RETURN_POINTER(serpa);
@ -458,10 +458,10 @@ Datum pcpatch_unnest(PG_FUNCTION_ARGS)
/* stuff done only on the first call of the function */
if (SRF_IS_FIRSTCALL())
{
{
PCPATCH *patch;
SERIALIZED_PATCH *serpatch;
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
@ -536,10 +536,10 @@ Datum pcpatch_intersects(PG_FUNCTION_ARGS)
{
SERIALIZED_PATCH *serpa1 = PG_GETARG_SERPATCH_P(0);
SERIALIZED_PATCH *serpa2 = PG_GETARG_SERPATCH_P(1);
if ( serpa1->pcid != serpa2->pcid )
elog(ERROR, "pcpatch_intersects: pcid mismatch (%d != %d)", serpa1->pcid, serpa2->pcid);
if ( serpa1->xmin > serpa2->xmax ||
serpa1->xmax < serpa2->xmin ||
serpa1->ymin > serpa2->ymax ||
@ -547,7 +547,7 @@ Datum pcpatch_intersects(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(FALSE);
}
PG_RETURN_BOOL(TRUE);
}

View File

@ -37,9 +37,9 @@ pcid_consistent(const uint32 pcid, const uint32 column_pcid)
{
ereport(ERROR, (
errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("point/patch pcid (%u) does not match column pcid (%d)", pcid, column_pcid)
errmsg("point/patch pcid (%u) does not match column pcid (%d)", pcid, column_pcid)
));
}
}
}
@ -52,8 +52,8 @@ Datum pcpoint_in(PG_FUNCTION_ARGS)
uint32 pcid = 0;
PCPOINT *pt;
SERIALIZED_POINT *serpt;
if ( (PG_NARGS()>2) && (!PG_ARGISNULL(2)) )
if ( (PG_NARGS()>2) && (!PG_ARGISNULL(2)) )
{
typmod = PG_GETARG_INT32(2);
pcid = pcid_from_typmod(typmod);
@ -67,7 +67,7 @@ Datum pcpoint_in(PG_FUNCTION_ARGS)
/* Binary or text form? Let's find out. */
if ( str[0] == '0' )
{
{
/* Hex-encoded binary */
pt = pc_point_from_hexwkb(str, strlen(str), fcinfo);
pcid_consistent(pt->schema->pcid, pcid);
@ -107,8 +107,8 @@ Datum pcpatch_in(PG_FUNCTION_ARGS)
uint32 typmod = 0, pcid = 0;
PCPATCH *patch;
SERIALIZED_PATCH *serpatch;
if ( (PG_NARGS()>2) && (!PG_ARGISNULL(2)) )
if ( (PG_NARGS()>2) && (!PG_ARGISNULL(2)) )
{
typmod = PG_GETARG_INT32(2);
pcid = pcid_from_typmod(typmod);
@ -122,7 +122,7 @@ Datum pcpatch_in(PG_FUNCTION_ARGS)
/* Binary or text form? Let's find out. */
if ( str[0] == '0' )
{
{
/* Hex-encoded binary */
patch = pc_patch_from_hexwkb(str, strlen(str), fcinfo);
pcid_consistent(patch->schema->pcid, pcid);
@ -162,7 +162,7 @@ Datum pcschema_is_valid(PG_FUNCTION_ARGS)
PCSCHEMA *schema;
int err = pc_schema_from_xml(xmlstr, &schema);
pfree(xmlstr);
if ( ! err )
{
PG_RETURN_BOOL(FALSE);
@ -206,17 +206,17 @@ Datum pcpoint_from_double_array(PG_FUNCTION_ARGS)
if ( ARR_ELEMTYPE(arrptr) != FLOAT8OID )
elog(ERROR, "array must be of float8[]");
if ( ARR_NDIM(arrptr) != 1 )
elog(ERROR, "float8[] must have only one dimension");
if ( ARR_HASNULL(arrptr) )
elog(ERROR, "float8[] must not have null elements");
nelems = ARR_DIMS(arrptr)[0];
if ( nelems != schema->ndims || ARR_LBOUND(arrptr)[0] > 1 )
elog(ERROR, "array dimenensions do not match schema dimensions of pcid = %d", pcid);
vals = (float8*) ARR_DATA_PTR(arrptr);
pt = pc_point_from_double_array(schema, vals, nelems);
@ -233,9 +233,9 @@ Datum pcpoint_as_text(PG_FUNCTION_ARGS)
char *str;
PCSCHEMA *schema = pc_schema_from_pcid(serpt->pcid, fcinfo);
PCPOINT *pt = pc_point_deserialize(serpt, schema);
if ( ! pt )
PG_RETURN_NULL();
if ( ! pt )
PG_RETURN_NULL();
str = pc_point_to_string(pt);
pc_point_free(pt);
txt = cstring_to_text(str);
@ -251,9 +251,9 @@ Datum pcpatch_as_text(PG_FUNCTION_ARGS)
char *str;
PCSCHEMA *schema = pc_schema_from_pcid(serpatch->pcid, fcinfo);
PCPATCH *patch = pc_patch_deserialize(serpatch, schema);
if ( ! patch )
PG_RETURN_NULL();
if ( ! patch )
PG_RETURN_NULL();
str = pc_patch_to_string(patch);
pc_patch_free(patch);
txt = cstring_to_text(str);
@ -272,15 +272,15 @@ Datum pcpoint_as_bytea(PG_FUNCTION_ARGS)
PCSCHEMA *schema = pc_schema_from_pcid(serpt->pcid, fcinfo);
PCPOINT *pt = pc_point_deserialize(serpt, schema);
if ( ! pt )
PG_RETURN_NULL();
if ( ! pt )
PG_RETURN_NULL();
bytes = pc_point_to_geometry_wkb(pt, &bytes_size);
wkb_size = VARHDRSZ + bytes_size;
wkb = palloc(wkb_size);
memcpy(VARDATA(wkb), bytes, bytes_size);
SET_VARSIZE(wkb, wkb_size);
pc_point_free(pt);
pfree(bytes);
@ -298,15 +298,15 @@ Datum pcpatch_bytea_envelope(PG_FUNCTION_ARGS)
PCSCHEMA *schema = pc_schema_from_pcid(serpatch->pcid, fcinfo);
PCPATCH *pa = pc_patch_deserialize(serpatch, schema);
if ( ! pa )
PG_RETURN_NULL();
if ( ! pa )
PG_RETURN_NULL();
bytes = pc_patch_to_geometry_wkb_envelope(pa, &bytes_size);
wkb_size = VARHDRSZ + bytes_size;
wkb = palloc(wkb_size);
memcpy(VARDATA(wkb), bytes, bytes_size);
SET_VARSIZE(wkb, wkb_size);
pc_patch_free(pa);
pfree(bytes);
@ -364,7 +364,7 @@ Datum pc_typmod_out(PG_FUNCTION_ARGS)
char *str = (char*)palloc(64);
uint32 typmod = PG_GETARG_INT32(0);
uint32 pcid = pcid_from_typmod(typmod);
/* No PCID value? Then no typmod at all. Return empty string. */
if ( ! pcid )

View File

@ -17,7 +17,7 @@
PG_MODULE_MAGIC;
/**********************************************************************************
* POSTGRESQL MEMORY MANAGEMENT HOOKS
* POSTGRESQL MEMORY MANAGEMENT HOOKS
*/
static void *
@ -90,7 +90,7 @@ pgsql_info(const char *fmt, va_list ap)
/**
* On module load we want to hook the message writing and memory allocation
* functions of libpc to the PostgreSQL ones.
* functions of libpc to the PostgreSQL ones.
* TODO: also hook the libxml2 hooks into PostgreSQL.
*/
void _PG_init(void);
@ -132,9 +132,9 @@ pc_point_from_hexwkb(const char *hexwkb, size_t hexlen, FunctionCallInfoData *fc
uint32 pcid;
uint8 *wkb = bytes_from_hexbytes(hexwkb, hexlen);
size_t wkblen = hexlen/2;
pcid = wkb_get_pcid(wkb);
pcid = wkb_get_pcid(wkb);
schema = pc_schema_from_pcid(pcid, fcinfo);
pt = pc_point_from_wkb(schema, wkb, wkblen);
pt = pc_point_from_wkb(schema, wkb, wkblen);
pfree(wkb);
return pt;
}
@ -145,7 +145,7 @@ pc_point_to_hexwkb(const PCPOINT *pt)
uint8 *wkb;
size_t wkb_size;
char *hexwkb;
wkb = pc_point_to_wkb(pt, &wkb_size);
hexwkb = hexbytes_from_bytes(wkb, wkb_size);
pfree(wkb);
@ -165,9 +165,9 @@ pc_patch_from_hexwkb(const char *hexwkb, size_t hexlen, FunctionCallInfoData *fc
uint32 pcid;
uint8 *wkb = bytes_from_hexbytes(hexwkb, hexlen);
size_t wkblen = hexlen/2;
pcid = wkb_get_pcid(wkb);
pcid = wkb_get_pcid(wkb);
schema = pc_schema_from_pcid(pcid, fcinfo);
patch = pc_patch_from_wkb(schema, wkb, wkblen);
patch = pc_patch_from_wkb(schema, wkb, wkblen);
pfree(wkb);
return patch;
}
@ -178,7 +178,7 @@ pc_patch_to_hexwkb(const PCPATCH *patch)
uint8 *wkb;
size_t wkb_size;
char *hexwkb;
wkb = pc_patch_to_wkb(patch, &wkb_size);
hexwkb = hexbytes_from_bytes(wkb, wkb_size);
pfree(wkb);
@ -217,7 +217,7 @@ pc_schema_from_pcid_uncached(uint32 pcid)
return NULL;
}
sprintf(sql, "select %s, %s from %s where pcid = %d",
sprintf(sql, "select %s, %s from %s where pcid = %d",
POINTCLOUD_FORMATS_XML, POINTCLOUD_FORMATS_SRID, POINTCLOUD_FORMATS, pcid);
err = SPI_exec(sql, 1);
@ -226,7 +226,7 @@ pc_schema_from_pcid_uncached(uint32 pcid)
SPI_finish();
elog(ERROR, "pc_schema_from_pcid: error (%d) executing query: %s", err, sql);
return NULL;
}
}
/* No entry in POINTCLOUD_FORMATS */
if (SPI_processed <= 0)
@ -238,7 +238,7 @@ pc_schema_from_pcid_uncached(uint32 pcid)
/* Result */
xml_spi = SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1);
srid_spi = SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 2);
srid_spi = SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 2);
/* NULL result */
if ( ! ( xml_spi && srid_spi ) )
@ -261,17 +261,17 @@ pc_schema_from_pcid_uncached(uint32 pcid)
/* Build the schema object */
err = pc_schema_from_xml(xml, &schema);
if ( ! err )
{
ereport(ERROR,
(errcode(ERRCODE_NOT_AN_XML_DOCUMENT),
errmsg("unable to parse XML for pcid = %d in \"%s\"", pcid, POINTCLOUD_FORMATS)));
}
schema->pcid = pcid;
schema->srid = srid;
return schema;
}
@ -302,24 +302,24 @@ typedef struct {
* concert with PostGIS, so here we not only ape
* the container, but avoid the first 10 slots,
* so as to miss any existing cached PostGIS objects.
*/
*/
typedef struct {
GenericCache *entry[16];
} GenericCacheCollection;
#define PC_SCHEMA_CACHE 10
#define PC_STATS_CACHE 11
/**
* Get the generic collection off the statement, allocate a
* Get the generic collection off the statement, allocate a
* new one if we don't have one already.
*/
static GenericCacheCollection *
*/
static GenericCacheCollection *
GetGenericCacheCollection(FunctionCallInfoData *fcinfo)
{
GenericCacheCollection *cache = fcinfo->flinfo->fn_extra;
if ( ! cache )
if ( ! cache )
{
cache = MemoryContextAlloc(fcinfo->flinfo->fn_mcxt, sizeof(GenericCacheCollection));
memset(cache, 0, sizeof(GenericCacheCollection));
@ -337,7 +337,7 @@ GetSchemaCache(FunctionCallInfoData* fcinfo)
{
GenericCacheCollection *generic_cache = GetGenericCacheCollection(fcinfo);
SchemaCache* cache = (SchemaCache*)(generic_cache->entry[PC_SCHEMA_CACHE]);
if ( ! cache )
{
/* Allocate in the upper context */
@ -345,7 +345,7 @@ GetSchemaCache(FunctionCallInfoData* fcinfo)
memset(cache, 0, sizeof(SchemaCache));
cache->type = PC_SCHEMA_CACHE;
}
generic_cache->entry[PC_SCHEMA_CACHE] = (GenericCache*)cache;
return cache;
}
@ -358,7 +358,7 @@ pc_schema_from_pcid(uint32 pcid, FunctionCallInfoData *fcinfo)
int i;
PCSCHEMA *schema;
MemoryContext oldcontext;
/* Unable to find/make a schema cache? Odd. */
if ( ! schema_cache )
{
@ -366,7 +366,7 @@ pc_schema_from_pcid(uint32 pcid, FunctionCallInfoData *fcinfo)
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("unable to create/load statement level schema cache")));
}
/* Find our PCID if it's in there (usually it will be first) */
for ( i = 0; i < SchemaCacheSize; i++ )
{
@ -375,12 +375,12 @@ pc_schema_from_pcid(uint32 pcid, FunctionCallInfoData *fcinfo)
return schema_cache->schemas[i];
}
}
/* Not in there, load one the old-fashioned way. */
oldcontext = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
schema = pc_schema_from_pcid_uncached(pcid);
MemoryContextSwitchTo(oldcontext);
/* Failed to load the XML? Odd. */
if ( ! schema )
{
@ -402,7 +402,7 @@ pc_schema_from_pcid(uint32 pcid, FunctionCallInfoData *fcinfo)
* SERIALIZATION/DESERIALIZATION UTILITIES
*/
SERIALIZED_POINT *
SERIALIZED_POINT *
pc_point_serialize(const PCPOINT *pcpt)
{
size_t serpt_size = sizeof(SERIALIZED_POINT) - 1 + pcpt->schema->size;
@ -413,13 +413,13 @@ pc_point_serialize(const PCPOINT *pcpt)
return serpt;
}
PCPOINT *
PCPOINT *
pc_point_deserialize(const SERIALIZED_POINT *serpt, const PCSCHEMA *schema)
{
PCPOINT *pcpt;
size_t pgsize = VARSIZE(serpt) + 1 - sizeof(SERIALIZED_POINT);
/*
* Big problem, the size on disk doesn't match what we expect,
size_t pgsize = VARSIZE(serpt) + 1 - sizeof(SERIALIZED_POINT);
/*
* Big problem, the size on disk doesn't match what we expect,
* so we cannot reliably interpret the contents.
*/
if ( schema->size != pgsize )
@ -458,16 +458,16 @@ pc_patch_serialized_size(const PCPATCH *patch)
return -1;
}
static SERIALIZED_PATCH *
static SERIALIZED_PATCH *
pc_patch_uncompressed_serialize(const PCPATCH *patch_in)
{
size_t serpch_size;
SERIALIZED_PATCH *serpch;
const PCPATCH_UNCOMPRESSED *patch = (PCPATCH_UNCOMPRESSED *)patch_in;
serpch_size = pc_patch_serialized_size(patch_in);
serpch = pcalloc(serpch_size);
/* Copy */
serpch->pcid = patch->schema->pcid;
serpch->npoints = patch->npoints;
@ -481,7 +481,7 @@ pc_patch_uncompressed_serialize(const PCPATCH *patch_in)
}
static SERIALIZED_PATCH *
static SERIALIZED_PATCH *
pc_patch_dimensional_serialize(const PCPATCH *patch_in)
{
int i;
@ -500,7 +500,7 @@ pc_patch_dimensional_serialize(const PCPATCH *patch_in)
serpch->ymin = patch->ymin;
serpch->xmax = patch->xmax;
serpch->ymax = patch->ymax;
/* Copy byte buffers, one by one */
buf = serpch->data;
for ( i = 0; i < patch->schema->ndims; i++ )
@ -521,12 +521,12 @@ pc_patch_dimensional_serialize(const PCPATCH *patch_in)
* Userdata is currently only PCDIMSTATS, hopefully updated across
* a number of iterations and saved.
*/
SERIALIZED_PATCH *
SERIALIZED_PATCH *
pc_patch_serialize(const PCPATCH *patch_in, void *userdata)
{
{
PCPATCH *patch = (PCPATCH*)patch_in;
SERIALIZED_PATCH *serpatch;
/*
/*
* Convert the patch to the final target compression,
* which is the one in the schema.
*/
@ -534,7 +534,7 @@ pc_patch_serialize(const PCPATCH *patch_in, void *userdata)
{
patch = pc_patch_compress(patch_in, userdata);
}
switch( patch->type )
{
case PC_NONE:
@ -555,10 +555,10 @@ pc_patch_serialize(const PCPATCH *patch_in, void *userdata)
pcerror("pc_patch_serialize: unsupported compression type %d", patch->type);
}
}
if ( patch != patch_in )
pc_patch_free(patch);
return serpatch;
}
@ -568,23 +568,23 @@ pc_patch_serialize(const PCPATCH *patch_in, void *userdata)
* Userdata is currently only PCDIMSTATS, hopefully updated across
* a number of iterations and saved.
*/
SERIALIZED_PATCH *
SERIALIZED_PATCH *
pc_patch_serialize_uncompressed(const PCPATCH *patch_in)
{
{
PCPATCH *patch = (PCPATCH*)patch_in;
SERIALIZED_PATCH *serpatch;
/* Convert the patch to uncompressed, if necessary */
if ( patch->type != PC_NONE )
{
patch = pc_patch_uncompress(patch_in);
}
serpatch = pc_patch_uncompressed_serialize(patch);
if ( patch != patch_in )
pc_patch_free(patch);
return serpatch;
}
@ -592,7 +592,7 @@ static PCPATCH *
pc_patch_uncompressed_deserialize(const SERIALIZED_PATCH *serpatch, const PCSCHEMA *schema)
{
PCPATCH_UNCOMPRESSED *patch;
/* Reference the external data */
patch = pcalloc(sizeof(PCPATCH_UNCOMPRESSED));
patch->data = (uint8*)serpatch->data;
@ -620,7 +620,7 @@ pc_patch_dimensional_deserialize(const SERIALIZED_PATCH *serpatch, const PCSCHEM
const uint8_t *buf;
int ndims = schema->ndims;
int npoints = serpatch->npoints;
/* Reference the external data */
patch = pcalloc(sizeof(PCPATCH_DIMENSIONAL));
@ -637,22 +637,22 @@ pc_patch_dimensional_deserialize(const SERIALIZED_PATCH *serpatch, const PCSCHEM
/* Set up dimensions */
patch->bytes = pcalloc(ndims * sizeof(PCBYTES));
buf = serpatch->data;
for ( i = 0; i < ndims; i++ )
{
PCBYTES *pcb = &(patch->bytes[i]);
PCDIMENSION *dim = schema->dims[i];
pc_bytes_deserialize(buf, dim, pcb, true /*readonly*/, false /*flipendian*/);
pcb->npoints = npoints;
buf += pc_bytes_serialized_size(pcb);
buf += pc_bytes_serialized_size(pcb);
}
return (PCPATCH*)patch;
}
PCPATCH *
PCPATCH *
pc_patch_deserialize(const SERIALIZED_PATCH *serpatch, const PCSCHEMA *schema)
{
{
switch(schema->compression)
{
case PC_NONE: