[postgis-tickets] r16684 - MVT: Uniformize style and rename mvt_agg_context 'c'

Raul raul at rmr.ninja
Fri Aug 10 04:33:37 PDT 2018


Author: algunenano
Date: 2018-08-10 04:33:36 -0700 (Fri, 10 Aug 2018)
New Revision: 16684

Modified:
   trunk/postgis/mvt.c
   trunk/postgis/mvt.h
Log:
MVT: Uniformize style and rename mvt_agg_context 'c'

References #4145
Closes https://github.com/postgis/postgis/pull/285


Modified: trunk/postgis/mvt.c
===================================================================
--- trunk/postgis/mvt.c	2018-08-08 00:57:31 UTC (rev 16683)
+++ trunk/postgis/mvt.c	2018-08-10 11:33:36 UTC (rev 16684)
@@ -39,55 +39,64 @@
 
 #define FEATURES_CAPACITY_INITIAL 50
 
-enum mvt_cmd_id {
+enum mvt_cmd_id
+{
 	CMD_MOVE_TO = 1,
 	CMD_LINE_TO = 2,
 	CMD_CLOSE_PATH = 7
 };
 
-enum mvt_type {
+enum mvt_type
+{
 	MVT_POINT = 1,
 	MVT_LINE = 2,
 	MVT_RING = 3
 };
 
-struct mvt_kv_key {
+struct mvt_kv_key
+{
 	char *name;
 	uint32_t id;
 	UT_hash_handle hh;
 };
 
-struct mvt_kv_string_value {
+struct mvt_kv_string_value
+{
 	char *string_value;
 	uint32_t id;
 	UT_hash_handle hh;
 };
 
-struct mvt_kv_float_value {
+struct mvt_kv_float_value
+{
 	float float_value;
 	uint32_t id;
 	UT_hash_handle hh;
 };
 
-struct mvt_kv_double_value {
+struct mvt_kv_double_value
+{
 	double double_value;
 	uint32_t id;
 	UT_hash_handle hh;
 };
 
-struct mvt_kv_uint_value {
+struct mvt_kv_uint_value
+{
 	uint64_t uint_value;
 	uint32_t id;
 	UT_hash_handle hh;
 };
 
-struct mvt_kv_sint_value {
+struct mvt_kv_sint_value
+{
 	int64_t sint_value;
 	uint32_t id;
 	UT_hash_handle hh;
 };
 
-struct mvt_kv_bool_value {
+struct mvt_kv_bool_value
+{
 	protobuf_c_boolean bool_value;
 	uint32_t id;
 	UT_hash_handle hh;
@@ -113,7 +122,8 @@
 	const POINT2D *p;
 
 	/* loop points and add to buffer */
-	for (i = 0; i < pa->npoints; i++) {
+	for (i = 0; i < pa->npoints; i++)
+	{
 		/* move offset for command */
 		if (i == 0 || (i == 1 && type > MVT_POINT))
 			offset++;
@@ -133,10 +143,13 @@
 	}
 
 	/* determine initial move and eventual line command */
-	if (type == MVT_POINT) {
+	if (type == MVT_POINT)
+	{
 		/* point or multipoint, use actual number of point count */
 		buffer[0] = c_int(CMD_MOVE_TO, c);
-	} else {
+	}
+	else
+	{
 		/* line or polygon, assume count 1 */
 		buffer[0] = c_int(CMD_MOVE_TO, 1);
 		/* line command with move point subtracted from count */
@@ -255,7 +268,8 @@
 {
 	int type = lwgeom->type;
 
-	switch (type) {
+	switch (type)
+	{
 	case POINTTYPE:
 		return encode_point(ctx, (LWPOINT*)lwgeom);
 	case LINETYPE:
@@ -311,7 +325,8 @@
 	char *key;
 	POSTGIS_DEBUG(2, "parse_column_keys called");
 
-	for (i = 0; i < natts; i++) {
+	for (i = 0; i < natts; i++)
+	{
 #if POSTGIS_PGSQL_VERSION < 110
 		Oid typoid = getBaseType(tupdesc->attrs[i]->atttypid);
 		char *tkey = tupdesc->attrs[i]->attname.data;
@@ -324,14 +339,19 @@
 			continue;
 #endif
 		key = pstrdup(tkey);
-		if (ctx->geom_name == NULL) {
-			if (!geom_found && typoid == TypenameGetTypid("geometry")) {
+		if (ctx->geom_name == NULL)
+		{
+			if (!geom_found && typoid == TypenameGetTypid("geometry"))
+			{
 				ctx->geom_index = i;
 				geom_found = true;
 				continue;
 			}
-		} else {
-			if (!geom_found && strcmp(key, ctx->geom_name) == 0) {
+		}
+		else
+		{
+			if (!geom_found && strcmp(key, ctx->geom_name) == 0)
+			{
 				ctx->geom_index = i;
 				geom_found = true;
 				continue;
@@ -386,7 +406,8 @@
 	POSTGIS_DEBUG(2, "encode_values called");
 
 	values = palloc(ctx->values_hash_i * sizeof(*values));
-	for (kv = ctx->string_values_hash; kv != NULL; kv=kv->hh.next) {
+	for (kv = ctx->string_values_hash; kv != NULL; kv=kv->hh.next)
+	{
 		VectorTile__Tile__Value *value = create_value();
 		value->string_value = kv->string_value;
 		values[kv->id] = value;
@@ -420,7 +441,8 @@
 	{ \
 		struct kvtype *kv; \
 		HASH_FIND(hh, ctx->hash, &value, size, kv); \
-		if (!kv) { \
+		if (!kv) \
+		{ \
 			POSTGIS_DEBUG(4, "MVT_PARSE_VALUE value not found"); \
 			kv = palloc(sizeof(*kv)); \
 			POSTGIS_DEBUGF(4, "MVT_PARSE_VALUE new hash key: %d", \
@@ -429,19 +451,22 @@
 			kv->valuefield = value; \
 			HASH_ADD(hh, ctx->hash, valuefield, size, kv); \
 		} \
-		tags[ctx->c*2] = k; \
-		tags[ctx->c*2+1] = kv->id; \
+		tags[ctx->row_columns*2] = k; \
+		tags[ctx->row_columns*2+1] = kv->id; \
 	} \
 }
 
 #define MVT_PARSE_INT_VALUE(value) \
 { \
-	if (value >= 0) { \
+	if (value >= 0) \
+	{ \
 		uint64_t cvalue = value; \
 		MVT_PARSE_VALUE(cvalue, mvt_kv_uint_value, \
 				uint_values_hash, uint_value, \
 				sizeof(uint64_t)) \
-	} else { \
+	} \
+	else \
+	{ \
 		int64_t cvalue = value; \
 		MVT_PARSE_VALUE(cvalue, mvt_kv_sint_value, \
 				sint_values_hash, sint_value, \
@@ -468,7 +493,8 @@
 	size_t size = strlen(value);
 	POSTGIS_DEBUG(2, "add_value_as_string called");
 	HASH_FIND(hh, ctx->string_values_hash, value, size, kv);
-	if (!kv) {
+	if (!kv)
+	{
 		POSTGIS_DEBUG(4, "add_value_as_string value not found");
 		kv = palloc(sizeof(*kv));
 		POSTGIS_DEBUGF(4, "add_value_as_string new hash key: %d",
@@ -478,8 +504,8 @@
 		HASH_ADD_KEYPTR(hh, ctx->string_values_hash, kv->string_value,
 			size, kv);
 	}
-	tags[ctx->c*2] = k;
-	tags[ctx->c*2+1] = kv->id;
+	tags[ctx->row_columns*2] = k;
+	tags[ctx->row_columns*2+1] = kv->id;
 }
 
 static void parse_datum_as_string(mvt_agg_context *ctx, Oid typoid,
@@ -510,10 +536,12 @@
 
 	it = JsonbIteratorInit(&jb->root);
 
-	while ((r = JsonbIteratorNext(&it, &v, skipNested)) != WJB_DONE) {
+	while ((r = JsonbIteratorNext(&it, &v, skipNested)) != WJB_DONE)
+	{
 		skipNested = true;
 
-		if (r == WJB_KEY && v.type != jbvNull) {
+		if (r == WJB_KEY && v.type != jbvNull)
+		{
 			char *key;
 			key = palloc(v.val.string.len + 1 * sizeof(char));
 			memcpy(key, v.val.string.val, v.val.string.len);
@@ -520,7 +548,8 @@
 			key[v.val.string.len] = '\0';
 
 			k = get_key_index(ctx, key);
-			if (k == UINT32_MAX) {
+			if (k == UINT32_MAX)
+			{
 				uint32_t newSize = ctx->keys_hash_i + 1;
 				tags = repalloc(tags, newSize * 2 * sizeof(*tags));
 				k = add_key(ctx, key);
@@ -528,18 +557,23 @@
 
 			r = JsonbIteratorNext(&it, &v, skipNested);
 
-			if (v.type == jbvString) {
+			if (v.type == jbvString)
+			{
 				char *value;
 				value = palloc(v.val.string.len + 1 * sizeof(char));
 				memcpy(value, v.val.string.val, v.val.string.len);
 				value[v.val.string.len] = '\0';
 				add_value_as_string(ctx, value, tags, k);
-				ctx->c++;
-			} else if (v.type == jbvBool) {
+				ctx->row_columns++;
+			}
+			else if (v.type == jbvBool)
+			{
 				MVT_PARSE_VALUE(v.val.boolean, mvt_kv_bool_value,
 					bool_values_hash, bool_value, sizeof(protobuf_c_boolean));
-				ctx->c++;
-			} else if (v.type == jbvNumeric) {
+				ctx->row_columns++;
+			}
+			else if (v.type == jbvNumeric)
+			{
 				char *str;
 				double d;
 				long l;
@@ -547,13 +581,16 @@
 					PointerGetDatum(v.val.numeric)));
 				d = strtod(str, NULL);
 				l = strtol(str, NULL, 10);
-				if ((long) d != l) {
+				if ((long) d != l)
+				{
 					MVT_PARSE_VALUE(d, mvt_kv_double_value, double_values_hash,
 						double_value, sizeof(double));
-				} else {
+				}
+				else
+				{
 					MVT_PARSE_INT_VALUE(l);
 				}
-				ctx->c++;
+				ctx->row_columns++;
 			}
 		}
 	}
@@ -570,12 +607,13 @@
 	uint32_t i, k;
 	TupleDesc tupdesc = get_tuple_desc(ctx);
 	uint32_t natts = (uint32_t) tupdesc->natts;
-	ctx->c = 0;
+	ctx->row_columns = 0;
 	POSTGIS_DEBUG(2, "parse_values called");
 
 	POSTGIS_DEBUGF(3, "parse_values natts: %d", natts);
 
-	for (i = 0; i < natts; i++) {
+	for (i = 0; i < natts; i++)
+	{
 		char *key;
 		Oid typoid;
 		Datum datum;
@@ -592,7 +630,8 @@
 #endif
 		datum = GetAttributeByNum(ctx->row, i+1, &isnull);
 		k = get_key_index(ctx, key);
-		if (isnull) {
+		if (isnull)
+		{
 			POSTGIS_DEBUG(3, "parse_values isnull detected");
 			continue;
 		}
@@ -599,7 +638,8 @@
 #if POSTGIS_PGSQL_VERSION >= 94
 		if (k == UINT32_MAX && typoid != JSONBOID)
 			elog(ERROR, "parse_values: unexpectedly could not find parsed key name '%s'", key);
-		if (typoid == JSONBOID) {
+		if (typoid == JSONBOID)
+		{
 			tags = parse_jsonb(ctx, DatumGetJsonbP(datum), tags);
 			continue;
 		}
@@ -608,7 +648,8 @@
 			elog(ERROR, "parse_values: unexpectedly could not find parsed key name '%s'", key);
 #endif
 
-		switch (typoid) {
+		switch (typoid)
+		{
 		case BOOLOID:
 			MVT_PARSE_DATUM(protobuf_c_boolean, mvt_kv_bool_value,
 				bool_values_hash, bool_value,
@@ -637,12 +678,12 @@
 			parse_datum_as_string(ctx, typoid, datum, tags, k);
 			break;
 		}
-		ctx->c++;
+		ctx->row_columns++;
 	}
 
 	ReleaseTupleDesc(tupdesc);
 
-	ctx->feature->n_tags = ctx->c * 2;
+	ctx->feature->n_tags = ctx->row_columns * 2;
 	ctx->feature->tags = tags;
 
 	POSTGIS_DEBUGF(3, "parse_values n_tags %zd", ctx->feature->n_tags);
@@ -678,7 +719,6 @@
 		gc = lwcollection_extract(g, maxtype);
 		*g = *gc;
 	}
-	return;
 }
 
 /**
@@ -847,7 +887,8 @@
 /*	VectorTile__Tile__Feature **features = layer->features; */
 	POSTGIS_DEBUG(2, "mvt_agg_transfn called");
 
-	if (layer->n_features >= ctx->features_capacity) {
+	if (layer->n_features >= ctx->features_capacity)
+	{
 		size_t new_capacity = ctx->features_capacity * 2;
 		layer->features = repalloc(layer->features, new_capacity *
 			sizeof(*layer->features));
@@ -948,7 +989,8 @@
 
 mvt_agg_context * mvt_ctx_deserialize(const bytea *ba)
 {
-	ProtobufCAllocator allocator = {
+	ProtobufCAllocator allocator =
+	{
 		mvt_allocator,
 		mvt_deallocator,
 		NULL

Modified: trunk/postgis/mvt.h
===================================================================
--- trunk/postgis/mvt.h	2018-08-08 00:57:31 UTC (rev 16683)
+++ trunk/postgis/mvt.h	2018-08-10 11:33:36 UTC (rev 16684)
@@ -46,7 +46,8 @@
 
 #include "vector_tile.pb-c.h"
 
-typedef struct mvt_agg_context {
+typedef struct mvt_agg_context
+{
 	char *name;
 	uint32_t extent;
 	char *geom_name;
@@ -65,7 +66,7 @@
 	struct mvt_kv_bool_value *bool_values_hash;
 	uint32_t values_hash_i;
 	uint32_t keys_hash_i;
-	uint32_t c;
+	uint32_t row_columns;
 } mvt_agg_context;
 
 /* Prototypes */



More information about the postgis-tickets mailing list