Clang-format 1

This commit is contained in:
Blottiere Paul 2022-02-07 17:10:10 +01:00
parent 796ead9044
commit b505e04aa7
3 changed files with 391 additions and 386 deletions

View File

@ -1,276 +1,244 @@
/***********************************************************************
* pc_api.h
*
* Structures and function signatures for point clouds
*
* PgSQL Pointcloud is free and open source software provided
* by the Government of Canada
* Copyright (c) 2013 Natural Resources Canada
*
***********************************************************************/
* pc_api.h
*
* Structures and function signatures for point clouds
*
* PgSQL Pointcloud is free and open source software provided
* by the Government of Canada
* Copyright (c) 2013 Natural Resources Canada
*
***********************************************************************/
#ifndef _PC_API_H
#define _PC_API_H
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "pc_config.h"
#include "hashtable.h"
#include "pc_config.h"
#ifndef __GNUC__
#define __attribute__ (x)
#endif
/**********************************************************************
* DATA STRUCTURES
*/
* DATA STRUCTURES
*/
/**
* Compression types for PCPOINTS in a PCPATCH
*/
enum COMPRESSIONS
{
PC_NONE = 0,
PC_DIMENSIONAL = 1,
PC_LAZPERF = 2
* Compression types for PCPOINTS in a PCPATCH
*/
enum COMPRESSIONS { PC_NONE = 0, PC_DIMENSIONAL = 1, PC_LAZPERF = 2 };
/**
* Flags of endianness for inter-architecture
* data transfers.
*/
enum ENDIANS {
PC_XDR = 0, /* Big */
PC_NDR = 1 /* Little */
};
/**
* Flags of endianness for inter-architecture
* data transfers.
*/
enum ENDIANS
{
PC_XDR = 0, /* Big */
PC_NDR = 1 /* Little */
};
typedef enum
{
PC_GT,
PC_LT,
PC_EQUAL,
PC_BETWEEN
} PC_FILTERTYPE;
typedef enum { PC_GT, PC_LT, PC_EQUAL, PC_BETWEEN } PC_FILTERTYPE;
/**
* We need to hold a cached in-memory version of the format's
* XML structure for speed, and this is it.
*/
typedef struct
{
char *name;
char *description;
uint32_t position;
uint32_t size;
uint32_t byteoffset;
uint32_t interpretation;
double scale;
double offset;
uint8_t active;
* We need to hold a cached in-memory version of the format's
* XML structure for speed, and this is it.
*/
typedef struct {
char *name;
char *description;
uint32_t position;
uint32_t size;
uint32_t byteoffset;
uint32_t interpretation;
double scale;
double offset;
uint8_t active;
} PCDIMENSION;
typedef struct
{
uint32_t pcid; /* Unique ID for schema */
uint32_t ndims; /* How many dimensions does this schema have? */
size_t size; /* How wide (bytes) is a point with this schema? */
PCDIMENSION **dims; /* Array of dimension pointers */
uint32_t srid; /* Foreign key reference to SPATIAL_REF_SYS */
PCDIMENSION *xdim; /* pointer to the x dimension within dims */
PCDIMENSION *ydim; /* pointer to the y dimension within dims */
PCDIMENSION *zdim; /* pointer to the z dimension within dims */
PCDIMENSION *mdim; /* pointer to the m dimension within dims */
uint32_t compression; /* Compression type applied to the data */
hashtable *namehash; /* Look-up from dimension name to pointer */
typedef struct {
uint32_t pcid; /* Unique ID for schema */
uint32_t ndims; /* How many dimensions does this schema have? */
size_t size; /* How wide (bytes) is a point with this schema? */
PCDIMENSION **dims; /* Array of dimension pointers */
uint32_t srid; /* Foreign key reference to SPATIAL_REF_SYS */
PCDIMENSION *xdim; /* pointer to the x dimension within dims */
PCDIMENSION *ydim; /* pointer to the y dimension within dims */
PCDIMENSION *zdim; /* pointer to the z dimension within dims */
PCDIMENSION *mdim; /* pointer to the m dimension within dims */
uint32_t compression; /* Compression type applied to the data */
hashtable *namehash; /* Look-up from dimension name to pointer */
} PCSCHEMA;
/* Used for dimensional patch statistics */
typedef struct
{
uint32_t total_runs;
uint32_t total_commonbits;
uint32_t recommended_compression;
typedef struct {
uint32_t total_runs;
uint32_t total_commonbits;
uint32_t recommended_compression;
} PCDIMSTAT;
typedef struct
{
int32_t ndims;
uint32_t total_points;
uint32_t total_patches;
PCDIMSTAT *stats;
typedef struct {
int32_t ndims;
uint32_t total_points;
uint32_t total_patches;
PCDIMSTAT *stats;
} PCDIMSTATS;
/**
* Uncompressed structure for in-memory handling
* of points. A read-only PgSQL point can be wrapped in
* one of these by pointing the data element at the
* PgSQL memory and setting the capacity to 0
* to indicate it is read-only.
*/
typedef struct
{
int8_t readonly;
const PCSCHEMA *schema;
uint8_t *data; /* A serialized version of the data */
* Uncompressed structure for in-memory handling
* of points. A read-only PgSQL point can be wrapped in
* one of these by pointing the data element at the
* PgSQL memory and setting the capacity to 0
* to indicate it is read-only.
*/
typedef struct {
int8_t readonly;
const PCSCHEMA *schema;
uint8_t *data; /* A serialized version of the data */
} PCPOINT;
typedef struct
{
void *mem; /* An opaque memory buffer to be freed on destruction if not NULL */
uint32_t npoints;
uint32_t maxpoints;
PCPOINT **points;
typedef struct {
void
*mem; /* An opaque memory buffer to be freed on destruction if not NULL */
uint32_t npoints;
uint32_t maxpoints;
PCPOINT **points;
} PCPOINTLIST;
typedef struct
{
size_t size;
uint32_t npoints;
uint32_t interpretation;
uint32_t compression;
uint32_t readonly;
uint8_t *bytes;
typedef struct {
size_t size;
uint32_t npoints;
uint32_t interpretation;
uint32_t compression;
uint32_t readonly;
uint8_t *bytes;
} PCBYTES;
typedef struct
{
double xmin;
double xmax;
double ymin;
double ymax;
typedef struct {
double xmin;
double xmax;
double ymin;
double ymax;
} PCBOUNDS;
/* Used for generic patch statistics */
typedef struct
{
PCPOINT min;
PCPOINT max;
PCPOINT avg;
}
PCSTATS;
typedef struct {
PCPOINT min;
PCPOINT max;
PCPOINT avg;
} PCSTATS;
/**
* Uncompressed Structure for in-memory handling
* of patches. A read-only PgSQL patch can be wrapped in
* one of these by pointing the data element at the
* PgSQL memory and setting the capacity to 0
* to indicate it is read-only.
*/
* Uncompressed Structure for in-memory handling
* of patches. A read-only PgSQL patch can be wrapped in
* one of these by pointing the data element at the
* PgSQL memory and setting the capacity to 0
* to indicate it is read-only.
*/
#define PCPATCH_COMMON \
int type; \
int8_t readonly; \
const PCSCHEMA *schema; \
uint32_t npoints; \
PCBOUNDS bounds; \
PCSTATS *stats;
#define PCPATCH_COMMON \
int type; \
int8_t readonly; \
const PCSCHEMA *schema; \
uint32_t npoints; \
PCBOUNDS bounds; \
PCSTATS *stats;
typedef struct
{
PCPATCH_COMMON
typedef struct {
PCPATCH_COMMON
} PCPATCH;
typedef struct
{
PCPATCH_COMMON
uint32_t maxpoints; /* How many points we can hold (or 0 for read-only) */
size_t datasize;
uint8_t *data; /* A serialized version of the data */
typedef struct {
PCPATCH_COMMON
uint32_t maxpoints; /* How many points we can hold (or 0 for read-only) */
size_t datasize;
uint8_t *data; /* A serialized version of the data */
} PCPATCH_UNCOMPRESSED;
typedef struct
{
PCPATCH_COMMON
PCBYTES *bytes;
typedef struct {
PCPATCH_COMMON
PCBYTES *bytes;
} PCPATCH_DIMENSIONAL;
typedef struct
{
PCPATCH_COMMON
size_t lazperfsize;
uint8_t *lazperf;
typedef struct {
PCPATCH_COMMON
size_t lazperfsize;
uint8_t *lazperf;
} PCPATCH_LAZPERF;
/* Global function signatures for memory/logging handlers. */
typedef void* (*pc_allocator)(size_t size);
typedef void* (*pc_reallocator)(void *mem, size_t size);
typedef void (*pc_deallocator)(void *mem);
typedef void (*pc_message_handler)(const char *string, va_list ap)
__attribute__ (( format (printf, 1, 0) ));
typedef void *(*pc_allocator)(size_t size);
typedef void *(*pc_reallocator)(void *mem, size_t size);
typedef void (*pc_deallocator)(void *mem);
typedef void (*pc_message_handler)(const char *string, va_list ap)
__attribute__((format(printf, 1, 0)));
/**********************************************************************
* MEMORY MANAGEMENT
*/
* MEMORY MANAGEMENT
*/
/** Allocate memory using the appropriate means (system/db) */
void* pcalloc(size_t size);
void *pcalloc(size_t size);
/** Reallocate memory using the appropriate means (system/db) */
void* pcrealloc(void* mem, size_t size);
void *pcrealloc(void *mem, size_t size);
/** Free memory using the appropriate means (system/db) */
void pcfree(void* mem);
void pcfree(void *mem);
/** Emit an error message using the appropriate means (system/db) */
void pcerror(const char *fmt, ...);
void pcerror(const char *fmt, ...);
/** Emit an info message using the appropriate means (system/db) */
void pcinfo(const char *fmt, ...);
void pcinfo(const char *fmt, ...);
/** Emit a warning message using the appropriate means (system/db) */
void pcwarn(const char *fmt, ...);
void pcwarn(const char *fmt, ...);
/** Set custom memory allocators and messaging (used by PgSQL module) */
void pc_set_handlers(
pc_allocator allocator, pc_reallocator reallocator,
pc_deallocator deallocator, pc_message_handler error_handler,
pc_message_handler info_handler, pc_message_handler warning_handler
);
void pc_set_handlers(pc_allocator allocator, pc_reallocator reallocator,
pc_deallocator deallocator,
pc_message_handler error_handler,
pc_message_handler info_handler,
pc_message_handler warning_handler);
/** Set program to use system memory allocators and messaging */
void pc_install_default_handlers(void);
/**********************************************************************
* UTILITY
*/
* UTILITY
*/
/** Convert binary to hex */
uint8_t* pc_bytes_from_hexbytes(const char *hexbuf, size_t hexsize);
uint8_t *pc_bytes_from_hexbytes(const char *hexbuf, size_t hexsize);
/** Convert hex to binary */
char* pc_hexbytes_from_bytes(const uint8_t *bytebuf, size_t bytesize);
char *pc_hexbytes_from_bytes(const uint8_t *bytebuf, size_t bytesize);
/** Read the the PCID from WKB form of a POINT/PATCH */
uint32_t pc_wkb_get_pcid(const uint8_t *wkb);
/** Build an empty #PCDIMSTATS based on the schema */
PCDIMSTATS* pc_dimstats_make(const PCSCHEMA *schema);
PCDIMSTATS *pc_dimstats_make(const PCSCHEMA *schema);
/** Get compression name from enum */
const char* pc_compression_name(int num);
const char *pc_compression_name(int num);
/**********************************************************************
* SCHEMAS
*/
* SCHEMAS
*/
/** Release the memory in a schema structure */
void pc_schema_free(PCSCHEMA *pcs);
/** Build a schema structure from the XML serialisation */
PCSCHEMA *pc_schema_from_xml(const char *xmlstr);
/** Print out JSON readable format of schema */
char* pc_schema_to_json(const PCSCHEMA *pcs);
char *pc_schema_to_json(const PCSCHEMA *pcs);
/** Extract dimension information by position */
PCDIMENSION* pc_schema_get_dimension(const PCSCHEMA *s, uint32_t dim);
PCDIMENSION *pc_schema_get_dimension(const PCSCHEMA *s, uint32_t dim);
/** Extract dimension information by name */
PCDIMENSION* pc_schema_get_dimension_by_name(const PCSCHEMA *s, const char *name);
PCDIMENSION *pc_schema_get_dimension_by_name(const PCSCHEMA *s,
const char *name);
/** Check if the schema has all the information we need to work with data */
uint32_t pc_schema_is_valid(const PCSCHEMA *s);
/** Create a full copy of the schema and dimensions it contains */
PCSCHEMA* pc_schema_clone(const PCSCHEMA *s);
PCSCHEMA *pc_schema_clone(const PCSCHEMA *s);
/** Add/overwrite a dimension in a schema */
void pc_schema_set_dimension(PCSCHEMA *s, PCDIMENSION *d);
/** Check/set the xyzm positions in the dimension list */
@ -282,13 +250,12 @@ uint32_t pc_schema_same_dimensions(const PCSCHEMA *s1, const PCSCHEMA *s2);
/** Check whether the schemas have compatible dimension interpretations */
uint32_t pc_schema_same_interpretations(const PCSCHEMA *s1, const PCSCHEMA *s2);
/**********************************************************************
* PCPOINTLIST
*/
* PCPOINTLIST
*/
/** Allocate a pointlist */
PCPOINTLIST* pc_pointlist_make(uint32_t npoints);
PCPOINTLIST *pc_pointlist_make(uint32_t npoints);
/** Free a pointlist, including the points contained therein */
void pc_pointlist_free(PCPOINTLIST *pl);
@ -297,34 +264,36 @@ void pc_pointlist_free(PCPOINTLIST *pl);
void pc_pointlist_add_point(PCPOINTLIST *pl, PCPOINT *pt);
/** Get a point from the list */
PCPOINT* pc_pointlist_get_point(const PCPOINTLIST *pl, int i);
PCPOINT *pc_pointlist_get_point(const PCPOINTLIST *pl, int i);
/**********************************************************************
* PCPOINT
*/
* PCPOINT
*/
/** Create a new PCPOINT */
PCPOINT* pc_point_make(const PCSCHEMA *s);
PCPOINT *pc_point_make(const PCSCHEMA *s);
/** Create a new readonly PCPOINT on top of a data buffer */
PCPOINT* pc_point_from_data(const PCSCHEMA *s, const uint8_t *data);
PCPOINT *pc_point_from_data(const PCSCHEMA *s, const uint8_t *data);
/** Create a new read/write PCPOINT from a double array with an offset */
PCPOINT* pc_point_from_double_array(const PCSCHEMA *s, double *array, uint32_t offset, uint32_t stride);
PCPOINT *pc_point_from_double_array(const PCSCHEMA *s, double *array,
uint32_t offset, uint32_t stride);
/**
* Return an allocated double array of doubles representing point values
*
* The number of elements in the array is equal to pt->schema->n_dims
*/
double* pc_point_to_double_array(const PCPOINT *pt);
* Return an allocated double array of doubles representing point values
*
* The number of elements in the array is equal to pt->schema->n_dims
*/
double *pc_point_to_double_array(const PCPOINT *pt);
/** Frees the PTPOINT and data (if not readonly). Does not free referenced schema */
/** Frees the PTPOINT and data (if not readonly). Does not free referenced
* schema */
void pc_point_free(PCPOINT *pt);
/** Get dimension value by dimension name */
int pc_point_get_double_by_name(const PCPOINT *pt, const char *name, double *val);
int pc_point_get_double_by_name(const PCPOINT *pt, const char *name,
double *val);
/** Get dimension value by dimension index */
int pc_point_get_double_by_index(const PCPOINT *pt, uint32_t idx, double *val);
@ -366,47 +335,50 @@ int pc_point_set_z(PCPOINT *pt, double val);
int pc_point_set_m(PCPOINT *pt, double val);
/** Create a new readwrite PCPOINT from a hex byte array */
PCPOINT* pc_point_from_wkb(const PCSCHEMA *s, uint8_t *wkb, size_t wkbsize);
PCPOINT *pc_point_from_wkb(const PCSCHEMA *s, uint8_t *wkb, size_t wkbsize);
/** Returns serialized form of point */
uint8_t* pc_point_to_wkb(const PCPOINT *pt, size_t *wkbsize);
uint8_t *pc_point_to_wkb(const PCPOINT *pt, size_t *wkbsize);
/** Returns text form of point */
char* pc_point_to_string(const PCPOINT *pt);
char *pc_point_to_string(const PCPOINT *pt);
/** Return the OGC WKB version of the point */
uint8_t* pc_point_to_geometry_wkb(const PCPOINT *pt, size_t *wkbsize);
uint8_t *pc_point_to_geometry_wkb(const PCPOINT *pt, size_t *wkbsize);
/**********************************************************************
* PCPATCH
*/
* PCPATCH
*/
/** Create new PCPATCH from a PCPOINT set. Copies data, doesn't take ownership of points */
PCPATCH* pc_patch_from_pointlist(const PCPOINTLIST *ptl);
/** Create new PCPATCH from a PCPOINT set. Copies data, doesn't take ownership
* of points */
PCPATCH *pc_patch_from_pointlist(const PCPOINTLIST *ptl);
/** Returns a list of points extracted from patch */
PCPOINTLIST* pc_pointlist_from_patch(const PCPATCH *patch);
PCPOINTLIST *pc_pointlist_from_patch(const PCPATCH *patch);
/** Merge a set of patches into a single patch */
PCPATCH* pc_patch_from_patchlist(PCPATCH **palist, int numpatches);
PCPATCH *pc_patch_from_patchlist(PCPATCH **palist, int numpatches);
/** Free patch memory, respecting read-only status. Does not free referenced schema */
/** Free patch memory, respecting read-only status. Does not free referenced
* schema */
void pc_patch_free(PCPATCH *patch);
/** Create a compressed copy, using the compression schema referenced in the PCSCHEMA */
PCPATCH* pc_patch_compress(const PCPATCH *patch, void *userdata);
/** Create a compressed copy, using the compression schema referenced in the
* PCSCHEMA */
PCPATCH *pc_patch_compress(const PCPATCH *patch, void *userdata);
/** Create an uncompressed copy */
PCPATCH * pc_patch_uncompress(const PCPATCH *patch);
PCPATCH *pc_patch_uncompress(const PCPATCH *patch);
/** Create a new readwrite PCPOINT from a byte array */
PCPATCH* pc_patch_from_wkb(const PCSCHEMA *s, uint8_t *wkb, size_t wkbsize);
PCPATCH *pc_patch_from_wkb(const PCSCHEMA *s, uint8_t *wkb, size_t wkbsize);
/** Returns serialized form of point */
uint8_t* pc_patch_to_wkb(const PCPATCH *patch, size_t *wkbsize);
uint8_t *pc_patch_to_wkb(const PCPATCH *patch, size_t *wkbsize);
/** Returns text form of patch */
char* pc_patch_to_string(const PCPATCH *patch);
char *pc_patch_to_string(const PCPATCH *patch);
/** Return byte buffer size of serialization */
size_t pc_patch_dimensional_serialized_size(const PCPATCH_DIMENSIONAL *patch);
@ -418,13 +390,15 @@ size_t pc_bytes_serialized_size(const PCBYTES *pcb);
int pc_bytes_serialize(const PCBYTES *pcb, uint8_t *buf, size_t *size);
/** Read a buffer up into a bytes structure */
int pc_bytes_deserialize(const uint8_t *buf, const PCDIMENSION *dim, PCBYTES *pcb, int readonly, int flip_endian);
int pc_bytes_deserialize(const uint8_t *buf, const PCDIMENSION *dim,
PCBYTES *pcb, int readonly, int flip_endian);
/** Wrap serialized stats in a new stats objects */
PCSTATS* pc_stats_new_from_data(const PCSCHEMA *schema, const uint8_t *mindata, const uint8_t *maxdata, const uint8_t *avgdata);
PCSTATS *pc_stats_new_from_data(const PCSCHEMA *schema, const uint8_t *mindata,
const uint8_t *maxdata, const uint8_t *avgdata);
/** Allocate a stats object */
PCSTATS* pc_stats_new(const PCSCHEMA *schema);
PCSTATS *pc_stats_new(const PCSCHEMA *schema);
/** Free a stats object */
void pc_stats_free(PCSTATS *stats);
@ -442,22 +416,29 @@ int pc_patch_compute_extent(PCPATCH *patch);
int pc_bounds_intersects(const PCBOUNDS *b1, const PCBOUNDS *b2);
/** Returns OGC WKB of the bounding diagonal of XY bounds */
uint8_t* pc_bounding_diagonal_wkb_from_bounds(const PCBOUNDS *bounds, const PCSCHEMA *schema, size_t *wkbsize);
uint8_t *pc_bounding_diagonal_wkb_from_bounds(const PCBOUNDS *bounds,
const PCSCHEMA *schema,
size_t *wkbsize);
/** Returns OGC WKB of the bounding diagonal of XY, XYZ, XYM or XYZM bounds */
uint8_t* pc_bounding_diagonal_wkb_from_stats(const PCSTATS *stats, size_t *wkbsize);
uint8_t *pc_bounding_diagonal_wkb_from_stats(const PCSTATS *stats,
size_t *wkbsize);
/** Subset batch based on less-than condition on dimension */
PCPATCH* pc_patch_filter_lt_by_name(const PCPATCH *pa, const char *name, double val);
PCPATCH *pc_patch_filter_lt_by_name(const PCPATCH *pa, const char *name,
double val);
/** Subset batch based on greater-than condition on dimension */
PCPATCH* pc_patch_filter_gt_by_name(const PCPATCH *pa, const char *name, double val);
PCPATCH *pc_patch_filter_gt_by_name(const PCPATCH *pa, const char *name,
double val);
/** Subset batch based on equality condition on dimension */
PCPATCH* pc_patch_filter_equal_by_name(const PCPATCH *pa, const char *name, double val);
PCPATCH *pc_patch_filter_equal_by_name(const PCPATCH *pa, const char *name,
double val);
/** Subset batch based on range condition on dimension */
PCPATCH* pc_patch_filter_between_by_name(const PCPATCH *pa, const char *name, double val1, double val2);
PCPATCH *pc_patch_filter_between_by_name(const PCPATCH *pa, const char *name,
double val1, double val2);
/** get point n */
PCPOINT *pc_patch_pointn(const PCPATCH *patch, int n);
@ -466,15 +447,18 @@ PCPOINT *pc_patch_pointn(const PCPATCH *patch, int n);
PCPATCH *pc_patch_sort(const PCPATCH *pa, const char **name, int ndims);
/** True/false if the patch is sorted on dimension */
uint32_t pc_patch_is_sorted(const PCPATCH *pa, const char **name, int ndims, char strict);
uint32_t pc_patch_is_sorted(const PCPATCH *pa, const char **name, int ndims,
char strict);
/** Subset batch based on index */
PCPATCH* pc_patch_range(const PCPATCH *pa, int first, int count);
PCPATCH *pc_patch_range(const PCPATCH *pa, int first, int count);
/** assign a schema to the patch */
PCPATCH *pc_patch_set_schema(PCPATCH *patch, const PCSCHEMA *schema, double def);
PCPATCH *pc_patch_set_schema(PCPATCH *patch, const PCSCHEMA *schema,
double def);
/** transform the patch based on the passed schema */
PCPATCH *pc_patch_transform(const PCPATCH *patch, const PCSCHEMA *schema, double def);
PCPATCH *pc_patch_transform(const PCPATCH *patch, const PCSCHEMA *schema,
double def);
#endif /* _PC_API_H */

View File

@ -1,16 +1,16 @@
/***********************************************************************
* pc_api_internal.h
*
* Signatures we need to share within the library, but not for
* use outside it.
*
* PgSQL Pointcloud is free and open source software provided
* by the Government of Canada
*
* Copyright (c) 2013 Natural Resources Canada
* Copyright (c) 2013 OpenGeo
*
***********************************************************************/
* pc_api_internal.h
*
* Signatures we need to share within the library, but not for
* use outside it.
*
* PgSQL Pointcloud is free and open source software provided
* by the Government of Canada
*
* Copyright (c) 2013 Natural Resources Canada
* Copyright (c) 2013 OpenGeo
*
***********************************************************************/
#ifndef _PC_API_INTERNAL_H
#define _PC_API_INTERNAL_H
@ -18,76 +18,74 @@
#include "pc_api.h"
/**
* Utility defines
*/
* Utility defines
*/
#define PC_TRUE 1
#define PC_FALSE 0
#define PC_SUCCESS 1
#define PC_FAILURE 0
/**
* How many compression types do we support?
*/
* How many compression types do we support?
*/
#define PCCOMPRESSIONTYPES 2
/**
* Memory allocation for patch starts at 64 points
*/
* Memory allocation for patch starts at 64 points
*/
#define PCPATCH_DEFAULT_MAXPOINTS 64
/**
* How many points to sample before considering
* a PCDIMSTATS done?
*/
* How many points to sample before considering
* a PCDIMSTATS done?
*/
#define PCDIMSTATS_MIN_SAMPLE 10000
/**
* Interpretation types for our dimension descriptions
*/
* Interpretation types for our dimension descriptions
*/
#define NUM_INTERPRETATIONS 11
enum INTERPRETATIONS
{
PC_UNKNOWN = 0,
PC_INT8 = 1, PC_UINT8 = 2,
PC_INT16 = 3, PC_UINT16 = 4,
PC_INT32 = 5, PC_UINT32 = 6,
PC_INT64 = 7, PC_UINT64 = 8,
PC_DOUBLE = 9, PC_FLOAT = 10
enum INTERPRETATIONS {
PC_UNKNOWN = 0,
PC_INT8 = 1,
PC_UINT8 = 2,
PC_INT16 = 3,
PC_UINT16 = 4,
PC_INT32 = 5,
PC_UINT32 = 6,
PC_INT64 = 7,
PC_UINT64 = 8,
PC_DOUBLE = 9,
PC_FLOAT = 10
};
enum DIMCOMPRESSIONS
{
PC_DIM_NONE = 0,
PC_DIM_RLE = 1,
PC_DIM_SIGBITS = 2,
PC_DIM_ZLIB = 3
enum DIMCOMPRESSIONS {
PC_DIM_NONE = 0,
PC_DIM_RLE = 1,
PC_DIM_SIGBITS = 2,
PC_DIM_ZLIB = 3
};
/* PCDOUBLESTAT are members of PCDOUBLESTATS */
typedef struct
{
double min;
double max;
double sum;
typedef struct {
double min;
double max;
double sum;
} PCDOUBLESTAT;
/* PCDOUBLESTATS are internal to calculating stats in this module */
typedef struct
{
uint32_t npoints;
PCDOUBLESTAT *dims;
typedef struct {
uint32_t npoints;
PCDOUBLESTAT *dims;
} PCDOUBLESTATS;
typedef struct
{
uint32_t nset;
uint32_t npoints;
uint8_t *map;
typedef struct {
uint32_t nset;
uint32_t npoints;
uint8_t *map;
} PCBITMAP;
/** What is the endianness of this system? */
char machine_endian(void);
@ -116,7 +114,9 @@ uint8_t *wkb_set_uint32(uint8_t *wkb, uint32_t i);
uint8_t *wkb_set_char(uint8_t *wkb, char c);
/** Force a byte array into the machine endianness */
uint8_t* uncompressed_bytes_flip_endian(const uint8_t *bytebuf, const PCSCHEMA *schema, uint32_t npoints);
uint8_t *uncompressed_bytes_flip_endian(const uint8_t *bytebuf,
const PCSCHEMA *schema,
uint32_t npoints);
/** Update a value using the scale/offset info from a dimension */
double pc_value_scale_offset(double val, const PCDIMENSION *dim);
@ -134,90 +134,109 @@ int pc_double_to_ptr(uint8_t *ptr, uint32_t interpretation, double val);
size_t pc_interpretation_size(uint32_t interp);
/** Convert XML string token to type interpretation number */
const char * pc_interpretation_string(uint32_t interp);
const char *pc_interpretation_string(uint32_t interp);
/** Copy a string within the global memory management context */
char* pcstrdup(const char *str);
char *pcstrdup(const char *str);
/** Scales/offsets double, casts to appropriate dimension type, and writes into point */
/** Scales/offsets double, casts to appropriate dimension type, and writes into
* point */
int pc_point_set_double_by_index(PCPOINT *pt, uint32_t idx, double val);
/** Scales/offsets double, casts to appropriate dimension type, and writes into point */
/** Scales/offsets double, casts to appropriate dimension type, and writes into
* point */
int pc_point_set_double_by_name(PCPOINT *pt, const char *name, double val);
/** Scales/offsets double, casts to appropriate dimension type, and writes into point */
/** Scales/offsets double, casts to appropriate dimension type, and writes into
* point */
int pc_point_set_double(PCPOINT *pt, const PCDIMENSION *dim, double val);
/****************************************************************************
* DIMENSION STATISTICS
*/
* DIMENSION STATISTICS
*/
/** Analyze the bytes in the #PCPATCH_DIMENSIONAL and update the #PCDIMSTATS */
int pc_dimstats_update(PCDIMSTATS *pds, const PCPATCH_DIMENSIONAL *pdl);
/** Free the PCDIMSTATS memory */
void pc_dimstats_free(PCDIMSTATS *pds);
char* pc_dimstats_to_string(const PCDIMSTATS *pds);
char *pc_dimstats_to_string(const PCDIMSTATS *pds);
/****************************************************************************
* PATCHES
*/
* PATCHES
*/
/** Returns newly allocated patch that only contains the points fitting the filter condition */
PCPATCH* pc_patch_filter(const PCPATCH *pa, uint32_t dimnum, PC_FILTERTYPE filter, double val1, double val2);
/** Returns newly allocated patch that only contains the points fitting the
* filter condition */
PCPATCH *pc_patch_filter(const PCPATCH *pa, uint32_t dimnum,
PC_FILTERTYPE filter, double val1, double val2);
void pc_patch_free_stats(PCPATCH *pa);
/* DIMENSIONAL PATCHES */
char* pc_patch_dimensional_to_string(const PCPATCH_DIMENSIONAL *pa);
PCPATCH_DIMENSIONAL* pc_patch_dimensional_from_uncompressed(const PCPATCH_UNCOMPRESSED *pa);
PCPATCH_DIMENSIONAL* pc_patch_dimensional_compress(const PCPATCH_DIMENSIONAL *pdl, PCDIMSTATS *pds);
PCPATCH_DIMENSIONAL* pc_patch_dimensional_decompress(const PCPATCH_DIMENSIONAL *pdl);
char *pc_patch_dimensional_to_string(const PCPATCH_DIMENSIONAL *pa);
PCPATCH_DIMENSIONAL *
pc_patch_dimensional_from_uncompressed(const PCPATCH_UNCOMPRESSED *pa);
PCPATCH_DIMENSIONAL *
pc_patch_dimensional_compress(const PCPATCH_DIMENSIONAL *pdl, PCDIMSTATS *pds);
PCPATCH_DIMENSIONAL *
pc_patch_dimensional_decompress(const PCPATCH_DIMENSIONAL *pdl);
void pc_patch_dimensional_free(PCPATCH_DIMENSIONAL *pdl);
int pc_patch_dimensional_compute_extent(PCPATCH_DIMENSIONAL *pdl);
uint8_t* pc_patch_dimensional_to_wkb(const PCPATCH_DIMENSIONAL *patch, size_t *wkbsize);
PCPATCH* pc_patch_dimensional_from_wkb(const PCSCHEMA *schema, const uint8_t *wkb, size_t wkbsize);
PCPATCH_DIMENSIONAL* pc_patch_dimensional_from_pointlist(const PCPOINTLIST *pdl);
PCPOINTLIST* pc_pointlist_from_dimensional(const PCPATCH_DIMENSIONAL *pdl);
PCPATCH_DIMENSIONAL* pc_patch_dimensional_clone(const PCPATCH_DIMENSIONAL *patch);
uint8_t *pc_patch_dimensional_to_wkb(const PCPATCH_DIMENSIONAL *patch,
size_t *wkbsize);
PCPATCH *pc_patch_dimensional_from_wkb(const PCSCHEMA *schema,
const uint8_t *wkb, size_t wkbsize);
PCPATCH_DIMENSIONAL *
pc_patch_dimensional_from_pointlist(const PCPOINTLIST *pdl);
PCPOINTLIST *pc_pointlist_from_dimensional(const PCPATCH_DIMENSIONAL *pdl);
PCPATCH_DIMENSIONAL *
pc_patch_dimensional_clone(const PCPATCH_DIMENSIONAL *patch);
PCPOINT *pc_patch_dimensional_pointn(const PCPATCH_DIMENSIONAL *pdl, int n);
/* UNCOMPRESSED PATCHES */
char* pc_patch_uncompressed_to_string(const PCPATCH_UNCOMPRESSED *patch);
uint8_t* pc_patch_uncompressed_to_wkb(const PCPATCH_UNCOMPRESSED *patch, size_t *wkbsize);
PCPATCH* pc_patch_uncompressed_from_wkb(const PCSCHEMA *s, const uint8_t *wkb, size_t wkbsize);
PCPATCH_UNCOMPRESSED* pc_patch_uncompressed_make(const PCSCHEMA *s, uint32_t maxpoints);
char *pc_patch_uncompressed_to_string(const PCPATCH_UNCOMPRESSED *patch);
uint8_t *pc_patch_uncompressed_to_wkb(const PCPATCH_UNCOMPRESSED *patch,
size_t *wkbsize);
PCPATCH *pc_patch_uncompressed_from_wkb(const PCSCHEMA *s, const uint8_t *wkb,
size_t wkbsize);
PCPATCH_UNCOMPRESSED *pc_patch_uncompressed_make(const PCSCHEMA *s,
uint32_t maxpoints);
int pc_patch_uncompressed_compute_extent(PCPATCH_UNCOMPRESSED *patch);
int pc_patch_uncompressed_compute_stats(PCPATCH_UNCOMPRESSED *patch);
void pc_patch_uncompressed_free(PCPATCH_UNCOMPRESSED *patch);
uint8_t *pc_patch_uncompressed_readonly(PCPATCH_UNCOMPRESSED *patch);
PCPOINTLIST* pc_pointlist_from_uncompressed(const PCPATCH_UNCOMPRESSED *patch);
PCPATCH_UNCOMPRESSED* pc_patch_uncompressed_from_pointlist(const PCPOINTLIST *pl);
PCPATCH_UNCOMPRESSED* pc_patch_uncompressed_from_dimensional(const PCPATCH_DIMENSIONAL *pdl);
PCPOINTLIST *pc_pointlist_from_uncompressed(const PCPATCH_UNCOMPRESSED *patch);
PCPATCH_UNCOMPRESSED *
pc_patch_uncompressed_from_pointlist(const PCPOINTLIST *pl);
PCPATCH_UNCOMPRESSED *
pc_patch_uncompressed_from_dimensional(const PCPATCH_DIMENSIONAL *pdl);
int pc_patch_uncompressed_add_point(PCPATCH_UNCOMPRESSED *c, const PCPOINT *p);
PCPOINT *pc_patch_uncompressed_pointn(const PCPATCH_UNCOMPRESSED *patch, int n);
/* LAZPERF PATCHES */
PCPATCH_LAZPERF* pc_patch_lazperf_from_pointlist(const PCPOINTLIST *pl);
PCPATCH_LAZPERF* pc_patch_lazperf_from_uncompressed(const PCPATCH_UNCOMPRESSED *pa);
PCPOINTLIST* pc_pointlist_from_lazperf(const PCPATCH_LAZPERF *palaz);
PCPATCH_UNCOMPRESSED* pc_patch_uncompressed_from_lazperf(const PCPATCH_LAZPERF *palaz);
PCPATCH_LAZPERF *pc_patch_lazperf_from_pointlist(const PCPOINTLIST *pl);
PCPATCH_LAZPERF *
pc_patch_lazperf_from_uncompressed(const PCPATCH_UNCOMPRESSED *pa);
PCPOINTLIST *pc_pointlist_from_lazperf(const PCPATCH_LAZPERF *palaz);
PCPATCH_UNCOMPRESSED *
pc_patch_uncompressed_from_lazperf(const PCPATCH_LAZPERF *palaz);
int pc_patch_lazperf_compute_extent(PCPATCH_LAZPERF *patch);
char* pc_patch_lazperf_to_string(const PCPATCH_LAZPERF *pa);
char *pc_patch_lazperf_to_string(const PCPATCH_LAZPERF *pa);
void pc_patch_lazperf_free(PCPATCH_LAZPERF *palaz);
uint8_t* pc_patch_lazperf_to_wkb(const PCPATCH_LAZPERF *patch, size_t *wkbsize);
PCPATCH* pc_patch_lazperf_from_wkb(const PCSCHEMA *schema, const uint8_t *wkb, size_t wkbsize);
uint8_t *pc_patch_lazperf_to_wkb(const PCPATCH_LAZPERF *patch, size_t *wkbsize);
PCPATCH *pc_patch_lazperf_from_wkb(const PCSCHEMA *schema, const uint8_t *wkb,
size_t wkbsize);
PCPOINT *pc_patch_lazperf_pointn(const PCPATCH_LAZPERF *patch, int n);
/****************************************************************************
* BYTES
*/
* BYTES
*/
/** Construct empty byte array (zero out attribute and allocate byte buffer) */
PCBYTES pc_bytes_make(const PCDIMENSION *dim, uint32_t npoints);
/** Empty the byte array (free the byte buffer) */
void pc_bytes_free(PCBYTES bytes);
/** Apply the compresstion to the byte array in place, freeing the original byte buffer */
/** Apply the compresstion to the byte array in place, freeing the original byte
* buffer */
PCBYTES pc_bytes_encode(PCBYTES pcb, int compression);
/** Convert the bytes in #PCBYTES to PC_DIM_NONE compression */
PCBYTES pc_bytes_decode(PCBYTES epcb);
@ -239,19 +258,25 @@ PCBYTES pc_bytes_zlib_decode(const PCBYTES pcb);
uint32_t pc_bytes_run_count(const PCBYTES *pcb);
/** How many bits are shared by all elements of this array? */
uint32_t pc_bytes_sigbits_count(const PCBYTES *pcb);
/** Using an 8-bit word, what is the common word and number of bits in common? */
uint8_t pc_bytes_sigbits_count_8 (const PCBYTES *pcb, uint32_t *nsigbits);
/** Using an 16-bit word, what is the common word and number of bits in common? */
/** Using an 8-bit word, what is the common word and number of bits in common?
*/
uint8_t pc_bytes_sigbits_count_8(const PCBYTES *pcb, uint32_t *nsigbits);
/** Using an 16-bit word, what is the common word and number of bits in common?
*/
uint16_t pc_bytes_sigbits_count_16(const PCBYTES *pcb, uint32_t *nsigbits);
/** Using an 32-bit word, what is the common word and number of bits in common? */
/** Using an 32-bit word, what is the common word and number of bits in common?
*/
uint32_t pc_bytes_sigbits_count_32(const PCBYTES *pcb, uint32_t *nsigbits);
/** Using an 64-bit word, what is the common word and number of bits in common? */
/** Using an 64-bit word, what is the common word and number of bits in common?
*/
uint64_t pc_bytes_sigbits_count_64(const PCBYTES *pcb, uint32_t *nsigbits);
/* NOTE: stats are gathered without applying scale and offset */
PCBYTES pc_bytes_filter(const PCBYTES *pcb, const PCBITMAP *map, PCDOUBLESTAT *stats);
PCBYTES pc_bytes_filter(const PCBYTES *pcb, const PCBITMAP *map,
PCDOUBLESTAT *stats);
PCBITMAP* pc_bytes_bitmap(const PCBYTES *pcb, PC_FILTERTYPE filter, double val1, double val2);
PCBITMAP *pc_bytes_bitmap(const PCBYTES *pcb, PC_FILTERTYPE filter, double val1,
double val2);
int pc_bytes_minmax(const PCBYTES *pcb, double *min, double *max, double *avg);
/** getting the n-th point out of a PCBYTE into a buffer */
@ -263,30 +288,29 @@ void pc_bytes_zlib_to_ptr(uint8_t *buf, PCBYTES pcb, int n);
void pc_bytes_to_ptr(uint8_t *buf, PCBYTES pcb, int n);
/****************************************************************************
* BOUNDS
*/
* BOUNDS
*/
/** Initialize with very large mins and very small maxes */
void pc_bounds_init(PCBOUNDS *b);
/** Copy a bounds */
PCSTATS* pc_stats_clone(const PCSTATS *stats);
PCSTATS *pc_stats_clone(const PCSTATS *stats);
/** Expand extents of b1 to encompass b2 */
void pc_bounds_merge(PCBOUNDS *b1, const PCBOUNDS *b2);
/****************************************************************************
* BITMAPS
*/
* BITMAPS
*/
/** Allocate new unset bitmap */
PCBITMAP* pc_bitmap_new(uint32_t npoints);
PCBITMAP *pc_bitmap_new(uint32_t npoints);
/** Deallocate bitmap */
void pc_bitmap_free(PCBITMAP *map);
/** Set indicated bit on bitmap if filter and value are consistent */
void pc_bitmap_filter(PCBITMAP *map, PC_FILTERTYPE filter, int i, double d, double val1, double val2);
void pc_bitmap_filter(PCBITMAP *map, PC_FILTERTYPE filter, int i, double d,
double val1, double val2);
/** Read indicated bit of bitmap */
#define pc_bitmap_get(map, i) ((map)->map[(i)])
#endif /* _PC_API_INTERNAL_H */

View File

@ -1,48 +1,48 @@
/**********************************************************************
* stringbuffer.h
*
* Copyright 2002 Thamer Alharbash
* Copyright 2009 Paul Ramsey <pramsey@cleverelephant.ca>
* Copyright 2015 Sandro Santilli <strk@keybit.net>
*
* 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.
*
* The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
**********************************************************************/
* stringbuffer.h
*
* Copyright 2002 Thamer Alharbash
* Copyright 2009 Paul Ramsey <pramsey@cleverelephant.ca>
* Copyright 2015 Sandro Santilli <strk@keybit.net>
*
* 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.
*
* The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
**********************************************************************/
#ifndef _STRINGBUFFER_H
#define _STRINGBUFFER_H 1
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Use appropriate allocators for this deployment */
#define malloc pcalloc
@ -53,13 +53,11 @@
#define STRINGBUFFER_STARTSIZE 128
typedef struct
{
size_t capacity;
char *str_end;
char *str_start;
}
stringbuffer_t;
typedef struct {
size_t capacity;
char *str_end;
char *str_start;
} stringbuffer_t;
extern stringbuffer_t *stringbuffer_create_with_size(size_t size);
extern stringbuffer_t *stringbuffer_create(void);
@ -78,4 +76,3 @@ extern int stringbuffer_trim_trailing_white(stringbuffer_t *s);
extern int stringbuffer_trim_trailing_zeroes(stringbuffer_t *s);
#endif /* _STRINGBUFFER_H */