[mapcode] 51/56: Speed up

Stefan Fritsch sf at moszumanska.debian.org
Wed Nov 2 23:27:31 UTC 2016


This is an automated email from the git hooks/post-receive script.

sf pushed a commit to annotated tag v2.0.2
in repository mapcode.

commit cf18424d2e191dbda68c1248888062f47e1a64b7
Author: Rijn Buve <rijn at buve.nl>
Date:   Mon Aug 3 18:16:10 2015 +0200

    Speed up
---
 README.md                               |   8 +
 mapcodelib/basics.h                     |  20 +-
 mapcodelib/dividemaps.h                 | 715 ++++++++++++++++++++++++++++++++
 mapcodelib/mapcode_countrynames.h       | 152 +++++++
 mapcodelib/mapcode_countrynames_short.h | 551 ++++++++++++++++++++++++
 mapcodelib/mapcoder.c                   | 460 ++++++++++----------
 mapcodelib/mapcoder.h                   |   7 +-
 7 files changed, 1665 insertions(+), 248 deletions(-)

diff --git a/README.md b/README.md
index 726fca7..46632fb 100644
--- a/README.md
+++ b/README.md
@@ -50,6 +50,14 @@ decode Mapcodes.
 
 ## Release Notes
 
+* 2.0.2
+
+    Speed-up of encoding (4x times faster than 2.0.1). 
+    
+* 2.0.1
+
+    Removed compiler warnings. 
+    
 * 2.0.0
 
     Support for high-precision mapcodes, with up to 8 character extensions (up to 10 micron accuracy).
diff --git a/mapcodelib/basics.h b/mapcodelib/basics.h
index 63eea62..cddd986 100644
--- a/mapcodelib/basics.h
+++ b/mapcodelib/basics.h
@@ -14,14 +14,10 @@
  * limitations under the License.
  */
 
-#define UWORD unsigned short int // 2-byte unsigned integer
-
-#define mapcode_cversion "2.0.1"
+#define mapcode_dataversion "2.0" // coords 2.0.2
 #define MAXWIDE 10
 #define BASEX 31
 #define MAXFITLONG 6
-#define XSIDE3 168 
-#define YSIDE3 176
 
 #define ALIASES "2UK=2UT,2CG=2CT,1GU=GUM,1UM=UMI,1VI=VIR,1PR=PRI,1AS=ASM,1MP=MNP,4CX=CXR,4CC=CCK,4NF=NFK,4HM=HMD,COL=5CL,5ME=5MX,MEX=5MX,5TM=TAM,5AG=AGU,5BC=BCN,5BS=BCS,5CM=CAM,5CS=CHP,5CH=CHH,5CO=COA,5DF=DIF,5DG=DUR,5GT=GUA,5GR=GRO,5HG=HID,5JA=JAL,5MI=MIC,5MO=MOR,5NA=NAY,5NL=NLE,5OA=OAX,5PB=PUE,5QE=QUE,5QR=ROO,5SL=SLP,5SI=SIN,5SO=SON,5TB=TAB,5TL=TLA,5VE=VER,5YU=YUC,5ZA=ZAC,811=8BJ,812=8TJ,813=8HE,814=8SX,815=8NM,821=8LN,822=8JL,823=8HL,831=8SH,832=8JS,833=8ZJ,834=8AH,835=8FJ,836=8JX,837 [...]
 
@@ -84,37 +80,31 @@ static const char *entity_iso = ""
 
 #define  usa_from    343
 #define  usa_upto    393
-#define  ccode_usa   410
 #define  ind_from    271
 #define  ind_upto    306
 #define  ccode_ind   407
 #define  can_from    394
 #define  can_upto    406
-#define  ccode_can   495
 #define  aus_from    307
 #define  aus_upto    315
-#define  ccode_aus   408
 #define  mex_from    233
 #define  mex_upto    264
 #define  ccode_mex   411
 #define  bra_from    316
 #define  bra_upto    342
-#define  ccode_bra   409
 #define  chn_from    497
 #define  chn_upto    527
-#define  ccode_chn   528
 #define  rus_from    412
 #define  rus_upto    494
-#define  ccode_rus   496
-#define  ccode_ata   531
 #define  ccode_earth 532
 
 #define parents3 "USA,IND,CAN,AUS,MEX,BRA,RUS,CHN,"
 #define parents2 "US,IN,CA,AU,MX,BR,RU,CN,"
+static const int parentnr[9] = {-1,410,407,495,408,411,409,496,528};
 
 
 
-static const UWORD xdivider19[172] = {
+static const long xdivider19[172] = {
 	  360,  360,  360,  360,  360,  360,  361,  361,  361,  361,
 	  362,  362,  362,  363,  363,  363,  364,  364,  365,  366,
 	  366,  367,  367,  368,  369,  370,  370,  371,  372,  373,
@@ -167,7 +157,7 @@ static const char encode_chars[34] = {
 		,'A','E','U'};
 
 
-static const UWORD data_start[MAX_CCODE+1] = {
+static const int data_start[MAX_CCODE+1] = {
 0, 3, 6, 10, 14, 17, 19, 20, 31, 32, 
 34, 36, 38, 43, 45, 48, 52, 59, 63, 65, 
 67, 71, 73, 81, 87, 95, 97, 132, 139, 149, 
@@ -227,7 +217,7 @@ static const UWORD data_start[MAX_CCODE+1] = {
 #define NR_RECS 16344
 #define WORST_RECS_PER_CCODE 195 // 8 Argentina @43
 
-typedef struct { long minx; long miny; long maxx; long maxy; unsigned long flags; } mminforec;
+typedef struct { long minx; long miny; long maxx; long maxy; long flags; } mminforec;
 
 #ifndef MAKE_SOURCE_DIGITAL
 static const mminforec mminfo[NR_RECS+1] = {
diff --git a/mapcodelib/dividemaps.h b/mapcodelib/dividemaps.h
new file mode 100644
index 0000000..2166e84
--- /dev/null
+++ b/mapcodelib/dividemaps.h
@@ -0,0 +1,715 @@
+/*
+ * Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+static int redivar[2924] = {
+ 27984500,1383,
+ 2537718,676,
+ 12842450,332,
+ -55514813,174,
+ -6059000,101,
+ -117350000,46,
+ -15190488,30,
+ -167832984,25,
+ -28175000,21,
+   2,   171,531,
+   3,   30,55,89,
+   4,   12,28,71,531,
+ -171131108,41,
+ -11977500,38,
+   3,   22,69,89,
+   2,   3,58,
+   4,   27,28,58,71,
+ -18715000,75,
+ -64521250,57,
+   6,   209,219,227,270,409,531,
+ -28845346,67,
+   7,   82,155,227,270,334,409,531,
+   7,   186,219,227,270,334,337,409,
+ -59298500,93,
+ -15616000,85,
+   5,   209,219,227,340,409,
+   7,   219,227,327,330,340,342,409,
+   7,   219,227,337,340,341,342,409,
+ -68556225,144,
+ 9859904,130,
+ -74589500,124,
+ 4965000,118,
+ -121020000,114,
+   2,   58,529,
+   3,   168,221,227,
+   5,   117,127,221,227,529,
+   5,   214,221,227,342,409,
+ -82018000,138,
+   5,   117,148,227,529,530,
+   5,   25,45,214,221,227,
+ 9263257,156,
+   9,   154,161,214,221,227,329,341,342,409,
+ -62448678,163,
+   4,   33,214,221,227,
+ 12365000,170,
+   4,   37,73,214,227,
+   3,   37,41,227,
+ -8371850,258,
+ -47007000,205,
+ -19580300,193,
+   12,   155,186,227,270,323,328,331,334,337,339,409,531,
+   11,   186,227,316,333,335,336,337,339,340,341,409,
+ -11963846,239,
+ -42991000,225,
+ -19580300,218,
+   6,   227,319,331,339,409,531,
+   6,   227,333,336,338,339,409,
+ -47050000,231,
+   3,   70,227,531,
+   7,   35,227,319,320,338,339,409,
+ -39287170,250,
+   8,   227,324,332,333,335,338,341,409,
+   7,   35,227,317,318,324,338,409,
+ -23810000,294,
+ -1916920,280,
+ -41616550,272,
+   7,   227,332,333,335,340,341,409,
+   7,   227,321,322,324,326,332,409,
+ -49307328,289,
+   6,   129,154,227,325,341,409,
+   4,   227,335,341,409,
+ 10775000,312,
+ -5530500,305,
+   6,   35,126,142,167,177,223,
+   6,   120,144,164,172,177,223,
+ -6579285,319,
+   4,   108,158,167,223,
+ 11426925,327,
+   5,   120,144,164,172,223,
+   4,   144,172,223,225,
+ -85785000,522,
+ 19815000,418,
+ -95481000,355,
+   16,   233,234,235,237,239,240,244,249,251,254,258,260,351,410,411,529,
+ 17649500,391,
+ -90249500,377,
+ 14015959,364,
+   2,   139,227,
+ -92914500,372,
+   5,   241,254,255,260,411,
+   4,   139,241,255,411,
+ 14491789,385,
+   5,   94,139,143,148,227,
+   5,   95,139,143,148,411,
+ -90690000,402,
+   8,   139,241,248,254,255,260,410,411,
+ 19007500,412,
+   7,   95,139,246,248,255,410,411,
+   5,   245,246,248,410,411,
+ -100679000,473,
+ 23113500,451,
+ -104856000,433,
+   8,   242,247,256,258,261,351,410,411,
+ 20496000,441,
+   5,   243,249,258,410,411,
+   9,   236,242,243,250,257,258,261,410,411,
+ -104856000,463,
+   9,   247,256,261,263,264,351,392,410,411,
+   9,   250,252,257,261,262,264,392,410,411,
+ 22023500,494,
+ -93031500,488,
+   10,   238,239,240,243,244,249,250,254,410,411,
+   5,   245,246,248,410,411,
+ -91965000,512,
+ 24517000,505,
+   6,   250,252,254,259,410,411,
+   6,   252,259,262,392,410,411,
+ 24055000,518,
+   3,   245,410,411,
+   3,   372,410,411,
+ 17731984,599,
+ -61364779,567,
+ 16901800,545,
+ -62626922,536,
+   5,   33,143,148,221,227,
+ 15684879,542,
+   3,   41,56,227,
+   2,   19,64,
+ -66701997,557,
+ 17575000,553,
+   3,   33,115,143,
+   3,   33,79,115,
+ 17551293,563,
+   3,   31,33,44,
+   3,   33,38,44,
+ 14253000,582,
+ -23810000,576,
+   4,   41,43,52,227,
+   5,   80,158,172,223,225,
+ -20139807,593,
+ 15684879,590,
+   3,   56,62,72,
+   2,   64,72,
+   5,   158,172,218,223,225,
+ -63821000,638,
+ 19812550,616,
+ -68135088,611,
+   5,   32,79,99,115,410,
+   4,   23,38,76,410,
+ -72604230,629,
+ 23868000,625,
+   4,   85,99,140,410,
+   3,   85,372,410,
+ 20556500,635,
+   3,   99,115,410,
+   2,   59,410,
+ 18772220,652,
+ -62560260,647,
+   4,   5,9,10,18,
+   4,   44,218,223,225,
+ -422500,667,
+ 27433500,662,
+   5,   169,188,218,223,268,
+   4,   169,188,194,268,
+ 26255000,673,
+   3,   223,225,268,
+   2,   194,268,
+ 10511000,1056,
+ 74615395,878,
+ -5098202,776,
+ 39063250,738,
+ -20098000,705,
+ 29828500,699,
+ -50838844,693,
+   2,   13,531,
+   5,   105,185,200,213,222,
+   5,   87,185,212,222,531,
+ 29790000,725,
+ -14533000,715,
+   5,   185,200,208,213,224,
+ 26708284,721,
+   3,   208,224,267,
+   3,   208,216,267,
+ -14533000,732,
+   4,   146,185,208,212,
+   5,   146,208,212,216,267,
+ -12572492,758,
+ 54723903,749,
+   6,   39,66,75,201,212,531,
+ -51460000,754,
+   2,   42,531,
+   3,   66,67,75,
+ 45312387,766,
+   5,   65,75,201,212,216,
+ -8413797,773,
+   4,   46,66,75,201,
+   2,   15,46,
+ 28158500,820,
+ 4039834,806,
+ 11520181,788,
+   5,   60,101,170,182,192,
+ -4167751,794,
+   3,   182,224,267,
+ 21050000,802,
+   5,   170,182,192,204,267,
+   3,   203,204,267,
+ 6307500,812,
+   3,   144,215,223,
+   7,   192,203,204,215,226,231,267,
+ 1202691,840,
+ 40707790,831,
+   6,   98,100,165,199,216,267,
+ -2685000,836,
+   2,   46,199,
+   3,   34,199,205,
+ 39800000,859,
+ 7371000,855,
+ 32140000,850,
+   3,   165,203,267,
+   4,   165,199,203,220,
+   3,   203,220,231,
+ 7876932,870,
+ 59255071,867,
+   3,   199,205,220,
+   2,   34,407,
+ 59255071,875,
+   2,   205,220,
+   2,   275,407,
+ -3000000,985,
+ 150294500,942,
+ -19119804,908,
+ 139475000,894,
+   7,   75,310,311,314,315,408,531,
+ -38750000,901,
+   4,   312,313,408,531,
+   6,   307,308,311,313,315,408,
+ 109235707,918,
+ -11244050,915,
+   2,   4,75,
+   2,   21,232,
+ -11930000,930,
+ 133495000,926,
+   3,   310,314,408,
+   3,   310,315,408,
+ 128179500,936,
+   3,   86,232,408,
+   5,   191,232,310,315,408,
+ -25602173,957,
+ 159633500,953,
+   6,   307,309,313,315,408,531,
+   3,   11,171,531,
+ 162917500,971,
+ -15102950,965,
+   3,   90,315,408,
+   5,   58,103,191,315,408,
+ -12405450,977,
+   3,   83,89,90,
+ 172466750,982,
+   2,   58,103,
+   2,   7,58,
+ 111780000,1032,
+ 7762500,1018,
+ 94680338,996,
+   4,   34,123,274,407,
+ 3547250,1002,
+   3,   54,179,232,
+ 98518000,1008,
+   3,   195,232,407,
+ 6703442,1014,
+   3,   179,195,232,
+   3,   179,180,195,
+ 87010150,1025,
+   4,   123,290,291,407,
+   6,   156,180,195,207,274,407,
+ 179200,1043,
+ 163201780,1040,
+   3,   58,191,232,
+   2,   6,58,
+ 135909365,1051,
+   5,   47,74,173,179,232,
+   4,   26,53,58,232,
+ 83124000,1224,
+ 19960000,1149,
+ 51682074,1098,
+ 15484010,1084,
+ 30218500,1076,
+   9,   144,192,203,204,215,223,225,226,231,
+   7,   96,145,196,203,205,220,231,
+ 29805981,1093,
+   6,   223,225,226,230,231,268,
+   4,   145,196,231,266,
+ 15937400,1133,
+ 74615395,1116,
+ 13175797,1109,
+   4,   196,275,296,407,
+   6,   196,289,296,304,407,528,
+ 13727500,1125,
+   6,   290,291,296,303,306,407,
+   7,   296,302,303,304,306,407,528,
+ 63445071,1139,
+   3,   175,196,266,
+   9,   294,296,298,302,303,304,306,407,528,
+ 65200071,1186,
+ 23600000,1169,
+ 24345005,1162,
+   6,   223,225,226,230,231,268,
+   6,   130,175,217,230,231,266,
+ 40464250,1178,
+   6,   194,217,223,230,266,268,
+   7,   57,81,130,175,211,229,266,
+ 22733000,1204,
+ 73363500,1196,
+   5,   271,272,299,304,407,
+   7,   294,298,299,301,304,407,528,
+ 78350000,1215,
+   8,   211,284,297,299,301,305,407,528,
+   8,   152,211,294,301,305,407,524,528,
+ 23445000,1313,
+ 101655895,1264,
+ 20519475,1245,
+ 89826650,1238,
+   5,   294,298,303,407,528,
+   6,   162,195,207,274,407,528,
+ 90515000,1255,
+   7,   151,294,295,298,300,407,528,
+   8,   151,162,207,280,281,407,523,528,
+ 20722500,1286,
+ 139657216,1277,
+   8,   156,162,173,180,195,500,513,528,
+ 13893260,1282,
+   2,   26,50,
+   3,   26,48,410,
+ 113717500,1296,
+   7,   8,162,180,513,521,523,528,
+ 21446500,1303,
+   4,   173,410,513,528,
+ 117661250,1309,
+   3,   61,513,528,
+   3,   109,410,528,
+ 96665000,1365,
+ 26270000,1341,
+ 90515000,1330,
+   10,   151,277,286,287,294,295,300,305,407,528,
+   10,   151,207,277,278,279,280,281,286,407,528,
+ 89297000,1354,
+   10,   110,151,152,282,287,300,305,407,524,528,
+   10,   110,151,207,278,285,286,300,407,524,528,
+   17,   109,184,207,285,407,410,503,505,510,512,513,520,521,522,523,524,528,
+ 34765500,2088,
+ 43871750,1765,
+ -77419467,1641,
+ 37102872,1538,
+ -97787350,1449,
+ 33167350,1426,
+ -109250000,1417,
+ 29917500,1410,
+ -136451930,1404,
+   2,   351,410,
+   5,   253,256,263,410,411,
+   6,   253,263,388,391,410,411,
+   8,   262,263,264,388,389,392,410,411,
+ -107843500,1436,
+   7,   381,386,387,388,389,391,410,
+ 36745500,1443,
+   4,   374,389,392,410,
+   5,   374,379,386,389,410,
+ 35605750,1496,
+ -87869000,1463,
+   9,   358,362,363,364,365,374,392,410,411,
+ 33235750,1483,
+ -84127000,1473,
+   5,   364,370,372,410,411,
+ 31517000,1479,
+   3,   370,372,410,
+   3,   354,370,410,
+ -84605000,1490,
+   4,   358,364,370,410,
+   5,   354,358,366,370,410,
+ -92511000,1511,
+ 36745500,1506,
+   5,   365,373,374,392,410,
+   4,   373,374,379,410,
+ 36828750,1527,
+ -86711000,1521,
+   5,   357,358,365,373,410,
+   5,   357,358,359,366,410,
+ -85550145,1534,
+   4,   357,369,373,410,
+   3,   357,359,410,
+ -93735000,1580,
+ 41027722,1559,
+ -103035000,1552,
+   7,   378,381,384,386,387,391,410,
+   6,   368,373,378,379,386,410,
+ -106550500,1571,
+   9,   380,381,384,385,387,391,410,495,496,
+   8,   368,377,378,382,384,396,410,495,
+ 41152000,1620,
+ -84227645,1592,
+   7,   356,357,360,368,369,373,410,
+ 39583250,1607,
+ -79998825,1602,
+   5,   353,357,359,360,410,
+   4,   352,353,359,410,
+ -80136500,1614,
+   4,   353,360,361,410,
+   5,   352,353,361,367,410,
+ -85763500,1632,
+   9,   356,368,369,371,382,383,396,410,495,
+   8,   356,360,361,367,383,396,410,495,
+ 40158500,1711,
+ 5450000,1677,
+ 37488303,1664,
+ -48023000,1658,
+ 33142708,1654,
+   2,   14,410,
+   3,   359,366,410,
+   5,   2,135,188,194,268,
+ -48023000,1674,
+   7,   343,345,347,352,359,361,410,
+   2,   135,194,
+ 33983000,1691,
+ 29679481,1686,
+   4,   153,217,230,268,
+   4,   92,93,217,266,
+ 18880000,1698,
+   4,   36,153,174,268,
+ 35765800,1703,
+   2,   77,149,
+ 23381000,1708,
+   2,   102,149,
+   2,   149,210,
+ 5450000,1749,
+ 42383793,1731,
+ -42050000,1727,
+   9,   344,346,347,350,361,367,396,410,495,
+   3,   135,194,197,
+ -66673537,1742,
+   8,   348,349,350,355,367,396,410,495,
+   6,   49,194,197,402,410,495,
+   15,   0,1,84,97,102,118,119,133,141,149,163,174,197,210,496,
+ 2192324,1875,
+ 49062290,1805,
+ -81486250,1790,
+   18,   371,375,376,377,380,382,383,384,385,390,394,395,396,398,399,410,495,496,
+   14,   29,197,348,349,355,367,396,397,400,401,402,403,410,495,
+ -73790750,1823,
+   15,   382,393,394,395,396,397,398,399,404,405,406,410,487,495,496,
+ 56700000,1847,
+ -31650000,1832,
+   4,   397,400,410,495,
+ 51255000,1839,
+   4,   17,20,166,197,
+ -5155300,1844,
+   2,   125,166,
+   2,   51,166,
+ -38967380,1856,
+   6,   265,397,400,406,410,495,
+ 69452955,1871,
+ -10127000,1863,
+   2,   138,265,
+ 61087500,1868,
+   2,   166,178,
+   2,   63,178,
+   3,   40,178,265,
+ 52859250,1992,
+ 18692500,1939,
+ 47498500,1917,
+ 12946250,1900,
+ 44896100,1893,
+ 11001170,1890,
+   2,   174,197,
+   2,   16,174,
+   6,   24,111,131,174,183,197,
+ 47177500,1909,
+   6,   91,118,119,131,136,174,
+ 15602500,1914,
+   2,   131,183,
+   2,   131,136,
+ 11292500,1932,
+ 49234990,1926,
+   4,   111,131,183,197,
+   5,   68,106,112,183,197,
+   6,   116,128,131,136,176,183,
+ 48523000,1976,
+ 19937265,1955,
+ 47139000,1951,
+   5,   118,119,133,136,496,
+   3,   116,136,496,
+ 44323191,1962,
+   4,   133,141,163,496,
+ 24795000,1971,
+   6,   116,133,136,163,202,496,
+   4,   107,163,202,496,
+ 23039608,1985,
+   6,   116,128,136,176,202,496,
+   6,   160,176,202,428,431,496,
+ 28339500,2045,
+ 56976000,2033,
+ 17383500,2012,
+ 55200000,2009,
+ 7618000,2005,
+   2,   112,183,
+   3,   113,176,183,
+   2,   113,190,
+ 55308000,2020,
+   5,   122,160,176,414,496,
+ 27083500,2028,
+   5,   121,122,160,190,496,
+   4,   121,160,440,496,
+   11,   40,113,114,121,178,181,190,198,440,446,496,
+ 59533150,2059,
+   11,   160,178,429,431,436,439,440,445,446,449,496,
+ 34171500,2077,
+ 63834000,2070,
+   6,   178,181,413,446,451,496,
+   6,   40,178,181,450,451,496,
+ 63834000,2084,
+   4,   446,449,451,496,
+   3,   450,451,496,
+ 45775000,2509,
+ 87550000,2293,
+ 37135000,2159,
+ 66867226,2141,
+ 32796250,2115,
+ 43200000,2108,
+   7,   92,93,134,157,187,217,266,
+   6,   88,187,206,211,229,266,
+ 43200000,2134,
+ 35253300,2130,
+ 37709800,2126,
+   4,   78,92,134,157,
+   3,   134,157,187,
+   3,   157,187,210,
+   6,   187,193,206,210,211,229,
+   17,   150,152,206,211,273,276,283,284,288,292,293,297,305,407,524,527,528,
+ 46099000,2246,
+ 42291500,2190,
+ 42910000,2175,
+ 39220000,2171,
+   3,   157,187,210,
+   3,   124,210,496,
+ 40420000,2183,
+   5,   104,132,187,210,229,
+   6,   104,124,132,210,437,496,
+ 44476450,2230,
+ 44203226,2216,
+ 42073685,2209,
+ 43622500,2203,
+   4,   124,419,443,496,
+   5,   416,419,442,443,496,
+   6,   124,417,418,419,442,496,
+ 40808500,2224,
+   5,   202,416,419,443,496,
+   5,   419,442,443,444,496,
+ 44337000,2240,
+   7,   124,415,417,420,437,442,496,
+   5,   434,437,442,444,496,
+ 40175000,2266,
+ 66867226,2258,
+   7,   104,132,187,189,193,206,229,
+   7,   150,159,189,206,407,527,528,
+ 51615000,2284,
+ 44337000,2278,
+   7,   104,124,132,269,420,437,496,
+   5,   269,434,437,444,496,
+   8,   150,159,189,193,269,496,527,528,
+ 34345000,2377,
+ 108695500,2337,
+ 30992500,2320,
+ 97458000,2311,
+   9,   110,152,207,282,285,407,522,524,528,
+   8,   207,502,512,514,522,523,524,528,
+ 104198500,2330,
+   7,   407,522,524,525,526,527,528,
+   6,   502,514,517,522,525,528,
+ 30428000,2357,
+ 114600000,2348,
+   6,   502,510,512,514,520,528,
+   8,   184,410,503,505,506,510,514,528,
+ 117345000,2368,
+   8,   502,504,506,511,514,517,525,528,
+   8,   137,184,410,497,503,504,506,528,
+ 118437543,2456,
+ 37349928,2401,
+ 109480000,2392,
+   8,   407,501,517,524,525,526,527,528,
+   8,   504,506,508,509,511,516,517,528,
+ 112356000,2427,
+ 40901000,2420,
+ 103695000,2413,
+   5,   518,525,526,527,528,
+   6,   501,509,517,518,525,528,
+   6,   228,496,518,525,527,528,
+ 40901000,2449,
+ 114672500,2436,
+   4,   509,516,518,528,
+ 38485000,2443,
+   4,   508,516,518,528,
+   5,   498,499,516,518,528,
+   6,   228,496,499,516,518,528,
+ 38662500,2486,
+ 123555000,2479,
+ 35585500,2473,
+ 122563000,2469,
+   4,   504,506,508,528,
+   3,   184,508,528,
+   5,   184,508,516,518,528,
+   6,   137,147,184,410,518,528,
+ 128256500,2499,
+   10,   147,184,228,496,507,515,516,518,519,528,
+   9,   147,184,410,489,490,496,515,519,528,
+ 50981650,2748,
+ 54414000,2613,
+ 40807800,2559,
+ 52698500,2529,
+   11,   202,423,424,426,428,430,431,438,443,447,496,
+ 37499000,2539,
+   7,   424,425,429,431,435,436,496,
+ 54038750,2554,
+ 39434000,2549,
+   5,   423,424,425,433,496,
+   4,   423,430,433,496,
+   4,   425,433,435,496,
+ 51418000,2593,
+ 44647865,2578,
+ 48918000,2572,
+   6,   442,443,444,447,448,496,
+   5,   438,447,448,467,496,
+ 49334500,2587,
+   6,   269,434,442,444,448,496,
+   5,   269,448,460,467,496,
+ 47108750,2605,
+   9,   269,430,433,438,455,457,461,467,496,
+   7,   269,460,461,465,466,467,496,
+ 41592250,2687,
+ 57125500,2650,
+ 38123500,2635,
+ 56301000,2629,
+   7,   412,425,429,435,436,445,496,
+   5,   432,435,439,445,496,
+ 55500500,2643,
+   5,   425,427,433,435,496,
+   6,   422,427,432,435,445,496,
+ 38853500,2674,
+ 60039500,2667,
+ 36659000,2662,
+   5,   439,445,446,449,496,
+   4,   432,445,449,496,
+   6,   446,449,450,451,454,496,
+ 60132500,2682,
+   5,   422,432,441,449,496,
+   4,   449,450,454,496,
+ 56340000,2715,
+ 44301100,2697,
+   5,   427,433,455,456,496,
+ 55638350,2708,
+   8,   269,421,455,456,461,465,466,496,
+   6,   421,456,458,459,465,496,
+ 44353250,2731,
+ 58284000,2725,
+   5,   422,427,441,456,496,
+   5,   441,449,452,454,496,
+ 58284000,2740,
+   6,   441,456,458,459,465,496,
+   7,   441,449,452,453,454,458,496,
+ 54913550,2793,
+ 96800500,2773,
+   20,   228,269,460,463,465,466,472,473,476,477,479,480,481,482,483,484,485,496,527,528,
+   19,   228,393,410,474,475,476,484,485,488,489,490,491,492,493,496,515,518,519,528,
+ 80381500,2880,
+ 58577500,2840,
+ 64084850,2830,
+ 55653700,2814,
+ 60983000,2809,
+   5,   269,463,465,473,496,
+   4,   269,472,473,496,
+ 55784200,2823,
+   6,   458,462,463,464,465,496,
+   6,   462,463,470,472,473,496,
+   9,   269,470,471,472,477,478,479,485,496,
+ 72088350,2867,
+ 62076000,2860,
+ 55581500,2852,
+   5,   453,454,458,462,496,
+   7,   453,454,462,469,470,471,496,
+   6,   452,453,454,468,469,496,
+ 61617000,2875,
+   5,   469,471,478,485,496,
+   4,   468,469,485,496,
+ 58509500,2904,
+ 93798000,2892,
+   7,   269,477,478,480,481,485,496,
+   11,   393,410,474,475,476,485,488,492,493,494,496,
+ 125763055,2914,
+   7,   468,469,476,478,485,494,496,
+   8,   393,410,486,487,488,492,494,496,
+0}; //2924
diff --git a/mapcodelib/mapcode_countrynames.h b/mapcodelib/mapcode_countrynames.h
new file mode 100644
index 0000000..1a15e10
--- /dev/null
+++ b/mapcodelib/mapcode_countrynames.h
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+const char *isofullname[] = {
+
+    "Vatican City State (Holy See)", "Monaco (Principality of _)", "Gibraltar", "Tokelau", 
+    "Cocos Islands (Keeling Islands)", "Saint-Barthelemy (Collectivity of _)", "Nauru (Republic of _)", "Tuvalu", 
+    "Macau (Aomen)", "Sint Maarten", "Saint Martin (Collectivity of _)", "Norfolk and Philip Island (Philip Island)", 
+    "Pitcairn Group of Islands", "Bouvet Island", "Bermuda (Somers Isles)", "British Indian Ocean Territory", 
+    "San Marino (Republic of _)", "Guernsey (Bailiwick of _)", "Anguilla", "Montserrat", 
+    "Jersey (Bailiwick of _)", "Christmas Island", "Wallis and Futuna (Futuna) (Collectivity of the _ Islands)", "British Virgin Islands (Virgin Islands, British)", 
+    "Liechtenstein (Principality of _)", "Aruba", "Marshall Islands (Republic of the _)", "American Samoa (Samoa, American)", 
+    "Cook Islands", "Saint Pierre and Miquelon (Miquelon) (Collectivity of _)", "Niue", "Saint Kitts and Nevis (Nevis) (Federation of _)", 
+    "Cayman islands", "Bonaire, St Eustasuis and Saba (Saba) (St Eustasius)", "Maldives (Republic of _)", "Saint Helena, Ascension and Tristan da Cunha (Ascension) (Tristan da Cunha)", 
+    "Malta (Republic of _)", "Grenada", "Virgin Islands of the United States (US Virgin Islands) (American Virgin Islands)", "Mayotte (Maore)", 
+    "Svalbard and Jan Mayen (Jan Mayen) (Spitsbergen)", "Saint Vincent and the Grenadines (Grenadines)", "Heard Island and McDonald Islands (McDonald Islands)", "Barbados", 
+    "Antigua and Barbuda (Barbuda)", "Curacao", "Seychelles (Republic of _)", "Palau (Republic of _)", 
+    "Northern Mariana Islands (Commonwealth of the _)", "Andorra (Principality of _) (Principality of the Valleys of _)", "Guam", "Isle of Mann (Mann)", 
+    "Saint Lucia", "Micronesia (Federated States of Micronesia)", "Singapore (Republic of _)", "Tonga (Kingdom of _)", 
+    "Dominica (Commonwealth of _)", "Bahrain (Kingdom of _)", "Kiribati (Republic of _)", "Turks and Caicos Islands (Caicos Islands)", 
+    "Sao Tome and Principe (Principe) (Democratic Republic of _)", "Hong Kong (Xianggang)", "Martinique", "Faroe Islands", 
+    "Guadeloupe", "Comoros (Union of the _)", "Mauritius (Republic of _)", "Reunion", 
+    "Luxembourg (Grand Duchy of _)", "Samoa (Independent State of _)", "South Georgia and the South Sandwich Islands (South Sandwich Islands)", "French Polynesia (Collectivity of _)", 
+    "Cape Verde (Cabo Verde) (Republic of Cabo Verde)", "Trinidad and Tobago (Republic of _) (Tobago)", "Brunei (Nation of _, the Abode of Peace)", "French Southern and Antarctic Lands", 
+    "Puerto Rico (Commonwealth of _)", "Cyprus (Republic of _)", "Lebanon (Lebanese Republic)", "Jamaica", 
+    "Gambia (The Gambia) (Republic of the _)", "Qatar (State of _)", "Falkland Islands", "Vanuatu (Republic of _)", 
+    "Montenegro", "Bahamas (Commonwealth of the _)", "Timor-Leste (Democratic Republic of _) (East Timor)", "Swaziland (Kingdom of _)", 
+    "Kuwait (State of _)", "Fiji (Republic of _)", "New Caledonia", "Slovenia (Republic of _)", 
+    "Israel (State of _)", "Palestinian territories (State of Palestine)", "El Salvador (Republic of _)", "Belize", 
+    "Djibouti (Republic of _)", "Macedonia (Republic of _) (FYROM) (Former Yugoslav Republic of Macedonia)", "Rwanda (Republic of _)", "Haiti (Republic of _)", 
+    "Burundi (Republic of _)", "Equatorial Guinea (Republic of _)", "Albania (Republic of _)", "Solomon Islands", 
+    "Armenia (Republic of _)", "Lesotho (Kingdom of _)", "Belgium (Kingdom of _)", "Moldova (Republic of _)", 
+    "Guinea-Bissau (Republic of _)", "Taiwan (Republic of China)", "Bhutan (Kingdom of _)", "Switzerland (Swiss Confederation)", 
+    "Netherlands (The Netherlands) (Kingdom of the _)", "Denmark (Kingdom of _)", "Estonia (Republic of _)", "Dominican Republic", 
+    "Slovakia (Slovak Republic)", "Costa Rica (Republic of _)", "Bosnia and Herzegovina", "Croatia (Republic of _)", 
+    "Togo (Togolese Republic)", "Latvia (Republic of _)", "Lithuania (Republic of _)", "Sri Lanka (Democratic Socialist Republic of _)", 
+    "Georgia", "Ireland (Republic of _)", "Sierra Leone (Republic of _)", "Panama (Republic of _)", 
+    "Czech Republic", "French Guiana (Guiana)", "United Arab Emirates (Emirates)", "Austria (Republic of _)", 
+    "Azerbaijan (Republic of _)", "Serbia (Republic of _)", "Jordan (Hashemite Kingdom of _) (Kingdom of _)", "Portugal (Portuguese Republic)", 
+    "Hungary (Republic of _)", "South Korea (Republic of Korea)", "Iceland", "Guatemala (Republic of _)", 
+    "Cuba (Republic of _)", "Bulgaria (Republic of _)", "Liberia (Republic of _)", "Honduras (Republic of _)", 
+    "Benin (Republic of _)", "Eritrea (State of _)", "Malawi (Republic of _)", "North Korea (Democratic People's Republic of Korea)", 
+    "Nicaragua (Republic of _)", "Greece (Hellenic Republic)", "Tajikistan (Republic of _)", "Bangladesh (People's Republic of _)", 
+    "Nepal (Federal Democratic Republic of _)", "Tunisia (Tunisian Republic) (Republic of _)", "Suriname (Republic of _)", "Uruguay (Eastern Republic of _)", 
+    "Cambodia (Kingdom of _)", "Syria (Syrian Arab Republic)", "Senegal (Republic of _)", "Kyrgyzstan (Kyrgyz Republic)", 
+    "Belarus (Republic of _)", "Guyana (Co-operative Republic of _)", "Laos (Lao People's Democratic Republic)", "Romania", 
+    "Ghana (Republic of _)", "Uganda (Republic of _)", "United Kingdom (Scotland) (Great Britain) (Northern Ireland) (Ireland, Northern) (Britain) (United Kingdom of Great Britain and Northern Ireland)", "Guinea (Republic of _) (Guinea-Conakry)", 
+    "Ecuador (Republic of _)", "Western Sahara (Sahrawi Arab Democratic Republic)", "Gabon (Gabonese Republic)", "New Zealand", 
+    "Burkina Faso", "Philippines (Republic of the _)", "Italy (Italian Republic)", "Oman (Sultanate of _)", 
+    "Poland (Republic of _)", "Ivory Coast (Cote d'Ivoire) (Republic of Cote d'Ivoire)", "Norway (Kingdom of _)", "Malaysia", 
+    "Vietnam (Socialist Republic of _)", "Finland (Republic of _)", "Congo-Brazzaville (West Congo) (Republic of the Congo)", "Germany (Federal Republic of _)", 
+    "Japan", "Zimbabwe (Republic of _)", "Paraguay (Republic of _)", "Iraq (Republic of _)", 
+    "Morocco (Kingdom of _)", "Uzbekistan (Republic of _)", "Sweden (Kingdom of _)", "Papua New Guinea (Independent State of _)", 
+    "Cameroon (Republic of _)", "Turkmenistan", "Spain (Kingdom of _)", "Thailand (Kingdom of _)", 
+    "Yemen (Republic of _)", "France (French Republic)", "Aaland Islands", "Kenya (Republic of _)", 
+    "Botswana (Republic of _)", "Madagascar (Republic of _)", "Ukraine", "South Sudan (Republic of _)", 
+    "Central African Republic", "Somalia (Federal Republic of _)", "Afghanistan (Islamic Republic of _)", "Myanmar (Republic of the Union of _) (Burma)", 
+    "Zambia (Republic of _)", "Chile (Republic of _)", "Turkey (Republic of _)", "Pakistan (Islamic Republic of _)", 
+    "Mozambique (Republic of _)", "Namibia (Republic of _)", "Venezuela (Bolivarian Republic of _)", "Nigeria (Federal Republic of _)", 
+    "Tanzania (United Republic of _)", "Egypt (Arab Republic of _)", "Mauritania (Islamic Republic of _)", "Bolivia (Plurinational State of _)", 
+    "Ethiopia (Federal Democratic Republic of _)", "Colombia (Republic of _)", "South Africa (Republic of _)", "Mali (Republic of _)", 
+    "Angola (Republic of _)", "Niger (Republic of _)", "Chad (Republic of _)", "Peru (Republic of _)", 
+    "Mongolia", "Iran (Persia) (Islamic Republic of _)", "Libya", "Sudan (Republic of the _)", 
+    "Indonesia (Republic of _)", "Federal District", "Tlaxcala", "Morelos", 
+    "Aguascalientes", "Colima", "Queretaro", "Hidalgo", 
+    "Mexico State", "Tabasco", "Nayarit", "Guanajuato", 
+    "Puebla", "Yucatan", "Quintana Roo", "Sinaloa", 
+    "Campeche", "Michoacan", "San Luis Potosi", "Guerrero", 
+    "Nuevo Leon (New Leon)", "Baja California", "Veracruz", "Chiapas", 
+    "Baja California Sur", "Zacatecas", "Jalisco", "Tamaulipas", 
+    "Oaxaca", "Durango", "Coahuila", "Sonora", 
+    "Chihuahua", "Greenland", "Saudi Arabia (Kingdom of _)", "Congo-Kinshasa (Democratic Republic of the Congo) (East Congo)", 
+    "Algeria (People's Democratic Republic of _)", "Kazakhstan (Republic of _)", "Argentina (Argentine Republic)", "Daman and Diu", 
+    "Dadra and Nagar Haveli", "Chandigarh", "Andaman and Nicobar", "Lakshadweep", 
+    "Delhi (National Capital Territory of _)", "Meghalaya", "Nagaland", "Manipur", 
+    "Tripura", "Mizoram", "Sikkim", "Punjab", 
+    "Haryana", "Arunachal Pradesh", "Assam", "Bihar", 
+    "Uttarakhand", "Goa", "Kerala", "Tamil Nadu", 
+    "Himachal Pradesh", "Jammu and Kashmir", "Chhattisgarh", "Jharkhand", 
+    "Karnataka", "Rajasthan", "Odisha (Orissa)", "Gujarat", 
+    "West Bengal", "Madhya Pradesh", "Telangana", "Andhra Pradesh", 
+    "Maharashtra", "Uttar Pradesh", "Puducherry", "New South Wales", 
+    "Australian Capital Territory", "Jervis Bay Territory", "Northern Territory", "South Australia", 
+    "Tasmania", "Victoria", "Western Australia", "Queensland", 
+    "Distrito Federal", "Sergipe", "Alagoas", "Rio de Janeiro", 
+    "Espirito Santo", "Rio Grande do Norte", "Paraiba", "Santa Catarina", 
+    "Pernambuco", "Amapa", "Ceara", "Acre", 
+    "Parana", "Roraima", "Rondonia", "Sao Paulo", 
+    "Piaui", "Tocantins", "Rio Grande do Sul", "Maranhao", 
+    "Goias", "Mato Grosso do Sul", "Bahia", "Minas Gerais", 
+    "Mato Grosso", "Para", "Amazonas", "District of Columbia (Washington, D.C.)", 
+    "Rhode Island", "Delaware", "Connecticut", "New Jersey", 
+    "New Hampshire", "Vermont", "Massachusetts (Commonwealth of _)", "Hawaii", 
+    "Maryland", "West Virginia", "South Carolina", "Maine", 
+    "Indiana", "Kentucky (Commonwealth of _)", "Tennessee", "Virginia (Commonwealth of _)", 
+    "Ohio", "Pennsylvania (Commonwealth of _)", "Mississippi", "Louisiana", 
+    "Alabama", "Arkansas", "North Carolina", "New York", 
+    "Iowa", "Illinois", "Georgia", "Wisconsin", 
+    "Florida", "Missouri", "Oklahoma", "North Dakota", 
+    "Washington", "South Dakota", "Nebraska", "Kansas", 
+    "Idaho", "Utah", "Minnesota", "Michigan", 
+    "Wyoming", "Oregon", "Colorado", "Nevada", 
+    "Arizona", "New Mexico", "Montana", "California", 
+    "Texas", "Alaska", "British Columbia", "Alberta", 
+    "Ontario", "Quebec", "Saskatchewan", "Manitoba", 
+    "Newfoundland and Labrador (Labrador)", "New Brunswick", "Nova Scotia", "Prince Edward Island", 
+    "Yukon", "Northwest Territories", "Nunavut", "India (Republic of _)", 
+    "Australia (Commonwealth of _)", "Brazil (Federative Republic of _)", "USA (United States of America) (America)", "Mexico (United Mexican States)", 
+    "Moscow", "Saint Petersburg", "Kaliningrad Oblast", "Ingushetia", 
+    "Adygea Republic", "North Ossetia-Alania Republic", "Kabardino-Balkar Republic", "Karachay-Cherkess Republic", 
+    "Chechen Republic (Chechnya) (Ichkeria)", "Chuvash Republic", "Ivanovo Oblast", "Lipetsk Oblast", 
+    "Oryol Oblast", "Tula Oblast", "Belgorod Oblast", "Vladimir Oblast", 
+    "Kursk Oblast", "Kaluga Oblast", "Tambov Oblast", "Bryansk Oblast", 
+    "Yaroslavl Oblast", "Ryazan Oblast", "Astrakhan Oblast", "Moscow Oblast", 
+    "Smolensk Oblast", "Dagestan Republic", "Voronezh Oblast", "Novgorod Oblast", 
+    "Pskov Oblast", "Kostroma Oblast", "Stavropol Krai", "Krasnodar Krai", 
+    "Kalmykia Republic", "Tver Oblast", "Leningrad Oblast", "Rostov Oblast", 
+    "Volgograd Oblast", "Vologda Oblast", "Murmansk Oblast", "Karelia Republic", 
+    "Nenets Autonomous Okrug", "Komi Republic", "Arkhangelsk Oblast", "Mordovia Republic", 
+    "Nizhny Novgorod Oblast", "Penza Oblast", "Kirov Oblast", "Mari El Republic", 
+    "Orenburg Oblast", "Ulyanovsk Oblast", "Perm Krai", "Bashkortostan Republic", 
+    "Udmurt Republic", "Tatarstan Republic", "Samara Oblast", "Saratov Oblast", 
+    "Yamalo-Nenets", "Khanty-Mansi", "Sverdlovsk Oblast", "Tyumen Oblast", 
+    "Kurgan Oblast", "Chelyabinsk Oblast", "Buryatia Republic", "Zabaykalsky Krai", 
+    "Irkutsk Oblast", "Novosibirsk Oblast", "Tomsk Oblast", "Omsk Oblast", 
+    "Khakassia Republic", "Kemerovo Oblast", "Altai Republic", "Altai Krai", 
+    "Tuva Republic", "Krasnoyarsk Krai", "Magadan Oblast", "Chukotka Okrug", 
+    "Kamchatka Krai", "Sakhalin Oblast", "Primorsky Krai", "Jewish Autonomous Oblast", 
+    "Khabarovsk Krai", "Amur Oblast", "Sakha Republic (Yakutia Republic)", "Canada", 
+    "Russia (Russian Federation)", "Shanghai Municipality", "Tianjin Municipality", "Beijing Municipality", 
+    "Hainan Province", "Ningxia Hui Autonomous Region", "Chongqing Municipality", "Zhejiang Province", 
+    "Jiangsu Province", "Fujian Province", "Anhui Province", "Liaoning Province", 
+    "Shandong Province", "Shanxi Province", "Jiangxi Province", "Henan Province", 
+    "Guizhou Province", "Guangdong Province", "Hubei Province", "Jilin Province", 
+    "Hebei Province (Yanzhao Province)", "Shaanxi Province", "Nei Mongol Autonomous Region (Inner Mongolia)", "Heilongjiang Province", 
+    "Hunan Province", "Guangxi Zhuang Autonomous Region", "Sichuan Province", "Yunnan Province", 
+    "Xizang Autonomous Region (Tibet)", "Gansu Province", "Qinghai Province (Tsinghai Province)", "Xinjiang Uyghur Autonomous Region", 
+    "China (People's Republic of _)", "United States Minor Outlying Islands", "Clipperton Island", "Antarctica", 
+    "International (Worldwide) (Earth)", "?"};
+
diff --git a/mapcodelib/mapcode_countrynames_short.h b/mapcodelib/mapcode_countrynames_short.h
new file mode 100644
index 0000000..954f738
--- /dev/null
+++ b/mapcodelib/mapcode_countrynames_short.h
@@ -0,0 +1,551 @@
+/*
+ * Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+const char *isofullname[] = {
+"Vatican City State (Holy See)",
+"Monaco",
+"Gibraltar",
+"Tokelau",
+"Cocos Islands (Keeling Islands)",
+"Saint-Barthelemy",
+"Nauru",
+"Tuvalu",
+"Macau (Aomen)",
+"Sint Maarten",
+"Saint Martin",
+"Norfolk and Philip Island (Philip Island)",
+"Pitcairn Group of Islands",
+"Bouvet Island",
+"Bermuda (Somers Isles)",
+"British Indian Ocean Territory",
+"San Marino",
+"Guernsey",
+"Anguilla",
+"Montserrat",
+"Jersey",
+"Christmas Island",
+"Wallis and Futuna (Futuna)",
+"British Virgin Islands (Virgin Islands, British)",
+"Liechtenstein",
+"Aruba",
+"Marshall Islands",
+"American Samoa (Samoa, American)",
+"Cook Islands",
+"Saint Pierre and Miquelon (Miquelon)",
+"Niue",
+"Saint Kitts and Nevis (Nevis)",
+"Cayman islands",
+"Bonaire, St Eustasuis and Saba (Saba) (St Eustasius)",
+"Maldives",
+"Saint Helena, Ascension and Tristan da Cunha (Ascension) (Tristan da Cunha)",
+"Malta",
+"Grenada",
+"Virgin Islands of the United States (US Virgin Islands) (American Virgin Islands)",
+"Mayotte (Maore)",
+"Svalbard and Jan Mayen (Jan Mayen) (Spitsbergen)",
+"Saint Vincent and the Grenadines (Grenadines)",
+"Heard Island and McDonald Islands (McDonald Islands)",
+"Barbados",
+"Antigua and Barbuda (Barbuda)",
+"Curacao",
+"Seychelles",
+"Palau",
+"Northern Mariana Islands",
+"Andorra",
+"Guam",
+"Isle of Mann (Mann)",
+"Saint Lucia",
+"Micronesia (Federated States of Micronesia)",
+"Singapore",
+"Tonga",
+"Dominica",
+"Bahrain",
+"Kiribati",
+"Turks and Caicos Islands (Caicos Islands)",
+"Sao Tome and Principe (Principe)",
+"Hong Kong (Xianggang)",
+"Martinique",
+"Faroe Islands",
+"Guadeloupe",
+"Comoros",
+"Mauritius",
+"Reunion",
+"Luxembourg",
+"Samoa",
+"South Georgia and the South Sandwich Islands (South Sandwich Islands)",
+"French Polynesia",
+"Cape Verde (Cabo Verde) (Republic of Cabo Verde)",
+"Trinidad and Tobago (Tobago)",
+"Brunei",
+"French Southern and Antarctic Lands",
+"Puerto Rico",
+"Cyprus",
+"Lebanon (Lebanese Republic)",
+"Jamaica",
+"Gambia (The Gambia)",
+"Qatar",
+"Falkland Islands",
+"Vanuatu",
+"Montenegro",
+"Bahamas",
+"Timor-Leste (East Timor)",
+"Swaziland",
+"Kuwait",
+"Fiji",
+"New Caledonia",
+"Slovenia",
+"Israel",
+"Palestinian territories (State of Palestine)",
+"El Salvador",
+"Belize",
+"Djibouti",
+"Macedonia (FYROM) (Former Yugoslav Republic of Macedonia)",
+"Rwanda",
+"Haiti",
+"Burundi",
+"Equatorial Guinea",
+"Albania",
+"Solomon Islands",
+"Armenia",
+"Lesotho",
+"Belgium",
+"Moldova",
+"Guinea-Bissau",
+"Taiwan (Republic of China)",
+"Bhutan",
+"Switzerland (Swiss Confederation)",
+"Netherlands (The Netherlands)",
+"Denmark",
+"Estonia",
+"Dominican Republic",
+"Slovakia (Slovak Republic)",
+"Costa Rica",
+"Bosnia and Herzegovina",
+"Croatia",
+"Togo (Togolese Republic)",
+"Latvia",
+"Lithuania",
+"Sri Lanka",
+"Georgia",
+"Ireland",
+"Sierra Leone",
+"Panama",
+"Czech Republic",
+"French Guiana (Guiana)",
+"United Arab Emirates (Emirates)",
+"Austria",
+"Azerbaijan",
+"Serbia",
+"Jordan",
+"Portugal (Portuguese Republic)",
+"Hungary",
+"South Korea (Republic of Korea)",
+"Iceland",
+"Guatemala",
+"Cuba",
+"Bulgaria",
+"Liberia",
+"Honduras",
+"Benin",
+"Eritrea",
+"Malawi",
+"North Korea (Democratic People's Republic of Korea)",
+"Nicaragua",
+"Greece (Hellenic Republic)",
+"Tajikistan",
+"Bangladesh",
+"Nepal",
+"Tunisia (Tunisian Republic)",
+"Suriname",
+"Uruguay",
+"Cambodia",
+"Syria (Syrian Arab Republic)",
+"Senegal",
+"Kyrgyzstan (Kyrgyz Republic)",
+"Belarus",
+"Guyana",
+"Laos (Lao People's Democratic Republic)",
+"Romania",
+"Ghana",
+"Uganda",
+"United Kingdom (Scotland) (Great Britain) (Northern Ireland) (Ireland, Northern) (Britain) (United Kingdom of Great Britain and Northern Ireland)",
+"Guinea (Guinea-Conakry)",
+"Ecuador",
+"Western Sahara (Sahrawi Arab Democratic Republic)",
+"Gabon (Gabonese Republic)",
+"New Zealand",
+"Burkina Faso",
+"Philippines",
+"Italy (Italian Republic)",
+"Oman",
+"Poland",
+"Ivory Coast (Cote d'Ivoire) (Republic of Cote d'Ivoire)",
+"Norway",
+"Malaysia",
+"Vietnam",
+"Finland",
+"Congo-Brazzaville (West Congo) (Republic of the Congo)",
+"Germany",
+"Japan",
+"Zimbabwe",
+"Paraguay",
+"Iraq",
+"Morocco",
+"Uzbekistan",
+"Sweden",
+"Papua New Guinea",
+"Cameroon",
+"Turkmenistan",
+"Spain",
+"Thailand",
+"Yemen",
+"France (French Republic)",
+"Aaland Islands",
+"Kenya",
+"Botswana",
+"Madagascar",
+"Ukraine",
+"South Sudan",
+"Central African Republic",
+"Somalia",
+"Afghanistan",
+"Myanmar (Burma)",
+"Zambia",
+"Chile",
+"Turkey",
+"Pakistan",
+"Mozambique",
+"Namibia",
+"Venezuela",
+"Nigeria",
+"Tanzania",
+"Egypt",
+"Mauritania",
+"Bolivia",
+"Ethiopia",
+"Colombia",
+"South Africa",
+"Mali",
+"Angola",
+"Niger",
+"Chad",
+"Peru",
+"Mongolia",
+"Iran (Persia)",
+"Libya",
+"Sudan",
+"Indonesia",
+"Federal District",
+"Tlaxcala",
+"Morelos",
+"Aguascalientes",
+"Colima",
+"Queretaro",
+"Hidalgo",
+"Mexico State",
+"Tabasco",
+"Nayarit",
+"Guanajuato",
+"Puebla",
+"Yucatan",
+"Quintana Roo",
+"Sinaloa",
+"Campeche",
+"Michoacan",
+"San Luis Potosi",
+"Guerrero",
+"Nuevo Leon (New Leon)",
+"Baja California",
+"Veracruz",
+"Chiapas",
+"Baja California Sur",
+"Zacatecas",
+"Jalisco",
+"Tamaulipas",
+"Oaxaca",
+"Durango",
+"Coahuila",
+"Sonora",
+"Chihuahua",
+"Greenland",
+"Saudi Arabia",
+"Congo-Kinshasa (Democratic Republic of the Congo) (East Congo)",
+"Algeria",
+"Kazakhstan",
+"Argentina (Argentine Republic)",
+"Daman and Diu",
+"Dadra and Nagar Haveli",
+"Chandigarh",
+"Andaman and Nicobar",
+"Lakshadweep",
+"Delhi",
+"Meghalaya",
+"Nagaland",
+"Manipur",
+"Tripura",
+"Mizoram",
+"Sikkim",
+"Punjab",
+"Haryana",
+"Arunachal Pradesh",
+"Assam",
+"Bihar",
+"Uttarakhand",
+"Goa",
+"Kerala",
+"Tamil Nadu",
+"Himachal Pradesh",
+"Jammu and Kashmir",
+"Chhattisgarh",
+"Jharkhand",
+"Karnataka",
+"Rajasthan",
+"Odisha (Orissa)",
+"Gujarat",
+"West Bengal",
+"Madhya Pradesh",
+"Telangana",
+"Andhra Pradesh",
+"Maharashtra",
+"Uttar Pradesh",
+"Puducherry",
+"New South Wales",
+"Australian Capital Territory",
+"Jervis Bay Territory",
+"Northern Territory",
+"South Australia",
+"Tasmania",
+"Victoria",
+"Western Australia",
+"Queensland",
+"Distrito Federal",
+"Sergipe",
+"Alagoas",
+"Rio de Janeiro",
+"Espirito Santo",
+"Rio Grande do Norte",
+"Paraiba",
+"Santa Catarina",
+"Pernambuco",
+"Amapa",
+"Ceara",
+"Acre",
+"Parana",
+"Roraima",
+"Rondonia",
+"Sao Paulo",
+"Piaui",
+"Tocantins",
+"Rio Grande do Sul",
+"Maranhao",
+"Goias",
+"Mato Grosso do Sul",
+"Bahia",
+"Minas Gerais",
+"Mato Grosso",
+"Para",
+"Amazonas",
+"District of Columbia (Washington, D.C.)",
+"Rhode Island",
+"Delaware",
+"Connecticut",
+"New Jersey",
+"New Hampshire",
+"Vermont",
+"Massachusetts",
+"Hawaii",
+"Maryland",
+"West Virginia",
+"South Carolina",
+"Maine",
+"Indiana",
+"Kentucky",
+"Tennessee",
+"Virginia",
+"Ohio",
+"Pennsylvania",
+"Mississippi",
+"Louisiana",
+"Alabama",
+"Arkansas",
+"North Carolina",
+"New York",
+"Iowa",
+"Illinois",
+"Georgia",
+"Wisconsin",
+"Florida",
+"Missouri",
+"Oklahoma",
+"North Dakota",
+"Washington",
+"South Dakota",
+"Nebraska",
+"Kansas",
+"Idaho",
+"Utah",
+"Minnesota",
+"Michigan",
+"Wyoming",
+"Oregon",
+"Colorado",
+"Nevada",
+"Arizona",
+"New Mexico",
+"Montana",
+"California",
+"Texas",
+"Alaska",
+"British Columbia",
+"Alberta",
+"Ontario",
+"Quebec",
+"Saskatchewan",
+"Manitoba",
+"Newfoundland and Labrador (Labrador)",
+"New Brunswick",
+"Nova Scotia",
+"Prince Edward Island",
+"Yukon",
+"Northwest Territories",
+"Nunavut",
+"India",
+"Australia",
+"Brazil",
+"USA (United States of America) (America)",
+"Mexico (United Mexican States)",
+"Moscow",
+"Saint Petersburg",
+"Kaliningrad Oblast",
+"Ingushetia",
+"Adygea Republic",
+"North Ossetia-Alania Republic",
+"Kabardino-Balkar Republic",
+"Karachay-Cherkess Republic",
+"Chechen Republic (Chechnya) (Ichkeria)",
+"Chuvash Republic",
+"Ivanovo Oblast",
+"Lipetsk Oblast",
+"Oryol Oblast",
+"Tula Oblast",
+"Belgorod Oblast",
+"Vladimir Oblast",
+"Kursk Oblast",
+"Kaluga Oblast",
+"Tambov Oblast",
+"Bryansk Oblast",
+"Yaroslavl Oblast",
+"Ryazan Oblast",
+"Astrakhan Oblast",
+"Moscow Oblast",
+"Smolensk Oblast",
+"Dagestan Republic",
+"Voronezh Oblast",
+"Novgorod Oblast",
+"Pskov Oblast",
+"Kostroma Oblast",
+"Stavropol Krai",
+"Krasnodar Krai",
+"Kalmykia Republic",
+"Tver Oblast",
+"Leningrad Oblast",
+"Rostov Oblast",
+"Volgograd Oblast",
+"Vologda Oblast",
+"Murmansk Oblast",
+"Karelia Republic",
+"Nenets Autonomous Okrug",
+"Komi Republic",
+"Arkhangelsk Oblast",
+"Mordovia Republic",
+"Nizhny Novgorod Oblast",
+"Penza Oblast",
+"Kirov Oblast",
+"Mari El Republic",
+"Orenburg Oblast",
+"Ulyanovsk Oblast",
+"Perm Krai",
+"Bashkortostan Republic",
+"Udmurt Republic",
+"Tatarstan Republic",
+"Samara Oblast",
+"Saratov Oblast",
+"Yamalo-Nenets",
+"Khanty-Mansi",
+"Sverdlovsk Oblast",
+"Tyumen Oblast",
+"Kurgan Oblast",
+"Chelyabinsk Oblast",
+"Buryatia Republic",
+"Zabaykalsky Krai",
+"Irkutsk Oblast",
+"Novosibirsk Oblast",
+"Tomsk Oblast",
+"Omsk Oblast",
+"Khakassia Republic",
+"Kemerovo Oblast",
+"Altai Republic",
+"Altai Krai",
+"Tuva Republic",
+"Krasnoyarsk Krai",
+"Magadan Oblast",
+"Chukotka Okrug",
+"Kamchatka Krai",
+"Sakhalin Oblast",
+"Primorsky Krai",
+"Jewish Autonomous Oblast",
+"Khabarovsk Krai",
+"Amur Oblast",
+"Sakha Republic (Yakutia Republic)",
+"Canada",
+"Russia (Russian Federation)",
+"Shanghai",
+"Tianjin",
+"Beijing",
+"Hainan",
+"Ningxia Hui",
+"Chongqing",
+"Zhejiang",
+"Jiangsu",
+"Fujian",
+"Anhui",
+"Liaoning",
+"Shandong",
+"Shanxi",
+"Jiangxi",
+"Henan",
+"Guizhou",
+"Guangdong",
+"Hubei",
+"Jilin",
+"Hebei (Yanzhao)",
+"Shaanxi",
+"Nei Mongol (Inner Mongolia)",
+"Heilongjiang",
+"Hunan",
+"Guangxi Zhuang",
+"Sichuan",
+"Yunnan",
+"Xizang (Tibet)",
+"Gansu",
+"Qinghai (Tsinghai)",
+"Xinjiang Uyghur",
+"China",
+"United States Minor Outlying Islands",
+"Clipperton Island",
+"Antarctica",
+"International (Worldwide) (Earth)",
+"?"};
+
diff --git a/mapcodelib/mapcoder.c b/mapcodelib/mapcoder.c
index 80ede41..ed5166e 100644
--- a/mapcodelib/mapcoder.c
+++ b/mapcodelib/mapcoder.c
@@ -20,6 +20,11 @@
 #include "mapcoder.h"
 #include "basics.h"
 
+#define FAST_ENCODE
+#ifdef FAST_ENCODE
+#include "dividemaps.h"
+#endif
+
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //  Structures
@@ -57,32 +62,37 @@ typedef struct {
 static int firstrec(int ccode) { return data_start[ccode]; }
 static int lastrec(int ccode)  { return data_start[ccode+1]-1; }
 
+static int ParentLetter(int ccode) // returns parent index (>0), or 0
+{
+  if (ccode>=usa_from && ccode<=usa_upto) return 1;
+  if (ccode>=ind_from && ccode<=ind_upto) return 2;
+  if (ccode>=can_from && ccode<=can_upto) return 3;
+  if (ccode>=aus_from && ccode<=aus_upto) return 4;
+  if (ccode>=mex_from && ccode<=mex_upto) return 5;
+  if (ccode>=bra_from && ccode<=bra_upto) return 6;
+  if (ccode>=rus_from && ccode<=rus_upto) return 7;
+  if (ccode>=chn_from && ccode<=chn_upto) return 8;
+  return 0;
+}
+
 static int ParentTerritoryOf(int ccode) // returns parent, or -1
 {
-  if (ccode>=usa_from && ccode<=usa_upto) return ccode_usa;
-  if (ccode>=ind_from && ccode<=ind_upto) return ccode_ind;
-  if (ccode>=can_from && ccode<=can_upto) return ccode_can;
-  if (ccode>=aus_from && ccode<=aus_upto) return ccode_aus;
-  if (ccode>=mex_from && ccode<=mex_upto) return ccode_mex;
-  if (ccode>=bra_from && ccode<=bra_upto) return ccode_bra;
-  if (ccode>=rus_from && ccode<=rus_upto) return ccode_rus;
-  if (ccode>=chn_from && ccode<=chn_upto) return ccode_chn;
-  return -1;
+  return parentnr[ParentLetter(ccode)];
 }
 
 static int isSubdivision( int ccode )  { return (ParentTerritoryOf(ccode)>=0); }
 
-static int coDex(int m)             { int c=mminfo[m].flags & 31; return 10*(c/5) + ((c%5)+1); }
-static int prefixLength(int m)      { int c=mminfo[m].flags & 31; return (c/5); }
-static int postfixLength(int m)     { int c=mminfo[m].flags & 31; return ((c%5)+1); }
-static int isNameless(int m)        { return mminfo[m].flags & 64; }
-static int recType(int m)           { return (mminfo[m].flags>>7) & 3; }
-static int isRestricted(int m)      { return mminfo[m].flags & 512; }
-static int isSpecialShape22(int m)  { return mminfo[m].flags & 1024; }
-static char headerLetter(int m)     { return encode_chars[ (mminfo[m].flags>>11)&31 ]; }
-static long smartDiv(int m)         { return (mminfo[m].flags>>16); }
-
-#define getboundaries(m,minx,miny,maxx,maxy) get_boundaries(m,&(minx),&(miny),&(maxx),&(maxy))
+static int coDex(int m)      { int c=mminfo[m].flags & 31; return 10*(c/5) + ((c%5)+1); }
+#define prefixLength(m)      ((int)((mminfo[m].flags & 31)/5))
+#define postfixLength(m)     ((int)(((mminfo[m].flags & 31)%5)+1))
+#define isNameless(m)        (mminfo[m].flags & 64)
+#define recType(m)           ((mminfo[m].flags>>7) & 3)
+#define isRestricted(m)      (mminfo[m].flags & 512)
+#define isSpecialShape22(m)  (mminfo[m].flags & 1024)
+#define headerLetter(m)      (encode_chars[(mminfo[m].flags>>11)&31])
+#define smartDiv(m)          (mminfo[m].flags>>16)
+#define boundaries(m)        (&mminfo[m])
+
 static void get_boundaries(int m,long *minx, long *miny, long *maxx, long *maxy )
 {
   const mminforec *mm = &mminfo[m];
@@ -102,8 +112,8 @@ static int isInRange(long x,long minx,long maxx) // returns nonzero if x in the
 
 static int fitsInside( long x, long y, int m )
 {
-  const mminforec *mm = &mminfo[m];
-  return ( mm->miny <= y && y < mm->maxy && isInRange(x,mm->minx,mm->maxx) );
+  const mminforec *b = boundaries(m);
+  return ( b->miny <= y && y < b->maxy && isInRange(x,b->minx,b->maxx) );
 }
 
 static long xDivider4( long miny, long maxy )
@@ -117,9 +127,9 @@ static long xDivider4( long miny, long maxy )
 
 static int fitsInsideWithRoom( long x, long y, int m )
 {
-  const mminforec *mm = &mminfo[m];
-  long xdiv8 = xDivider4(mm->miny,mm->maxy)/4; // should be /8 but there's some extra margin
-  return ( mm->miny-60 <= y && y < mm->maxy+60 && isInRange(x,mm->minx - xdiv8, mm->maxx + xdiv8) );
+  const mminforec *b = boundaries(m);
+  long xdiv8 = xDivider4(b->miny,b->maxy)/4; // should be /8 but there's some extra margin
+  return ( b->miny-60 <= y && y < b->maxy+60 && isInRange(x,b->minx - xdiv8, b->maxx + xdiv8) );
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -138,7 +148,6 @@ static const char *get_entity_iso3(char *entity_iso3_result,int ccode)
 
 static int disambiguate_str( const char *s, int len ) // returns disambiguation >=1, or negative if error
 {
-  int res;
   const char *p=(len==2 ? parents2 : parents3);
   const char *f;
   char country[4];
@@ -153,8 +162,7 @@ static int disambiguate_str( const char *s, int len ) // returns disambiguation
   f=strstr(p,country);
   if (f==NULL)
     return -23; // unknown country
-  res = 1 + (int)((f-p)/(len+1));
-  return res;
+  return 1 + (int)((f-p)/(len+1));
 }
 
 
@@ -326,7 +334,7 @@ static void encodeExtension(char *result,long extrax4,long extray,long dividerx4
 #define decodeChar(c) decode_chars[(unsigned char)c] // force c to be in range of the index, between 0 and 255
 
 // this routine takes the integer-arithmeteic decoding results (in millionths of degrees), adds any floating-point precision digits, and returns the result (still in millionths)
-static void decodeExtension(decodeRec *dec, long dividerx4,long dividery,int ydirection)
+static int decodeExtension(decodeRec *dec, long dividerx4,long dividery,int ydirection)
 {
   const char *extrapostfix = dec->extension;
 #ifndef SUPPORT_HIGH_PRECISION // old integer-arithmetic version
@@ -361,11 +369,11 @@ static void decodeExtension(decodeRec *dec, long dividerx4,long dividery,int ydi
     double halfcolumn=0;
     int c1 = *extrapostfix++;
     c1 = decodeChar(c1);
-    if (c1<0) c1=0; else if (c1>29) c1=29;
+    if (c1<0 || c1==30) return -1; // illegal extension character
     row1 =(c1/5); column1 = (c1%5);
     if (*extrapostfix) {
       int c2 = decodeChar(*extrapostfix++);
-      if (c2<0) c2=0; else if (c2>29) c2=29;
+      if (c2<0 || c2==30) return -1; // illegal extension character
       row2 =(c2/6); column2 = (c2%6);
     }
     else {
@@ -392,6 +400,7 @@ static void decodeExtension(decodeRec *dec, long dividerx4,long dividery,int ydi
   dec->lon32 = (long)dec->lon;
   dec->lat32 = (long)dec->lat;
 #endif
+  return 0;
 }
 
 
@@ -526,7 +535,7 @@ static int decodeGrid(decodeRec *dec, int m, int hasHeaderLetter )
 
   {
     long postlen = codexlen-prelen;
-    long codex = 10*prelen + postlen;
+
     long divx,divy;
 
     divy = smartDiv(m);
@@ -548,41 +557,41 @@ static int decodeGrid(decodeRec *dec, int m, int hasHeaderLetter )
     }
 
     {
-      long relx=-1,rely=-1,v=0;
-      long minx,maxx,miny,maxy;
-      getboundaries(m,minx,miny,maxx,maxy);
+      long relx=0,rely=0,v=0;
 
       if ( prelen <= MAXFITLONG )
       {
         v = decodeBase31(result);
 
-        if ( divx!=divy && codex>24 ) // D==6 special grid, useful when prefix is 3 or more, and not a nice 961x961
+        if ( divx!=divy && prelen>2 ) // D==6 special grid, useful when prefix is 3 or more, and not a nice 961x961
         { // DECODE
           decodeSixWide( v,divx,divy, &relx,&rely );
         }
         else
         {
           relx = (v/divy);
-          rely = (v%divy);
-          rely = divy-1-rely;
+          rely = divy - 1 - (v%divy);
         }
 
       }
 
       {
-        long ygridsize = (maxy-miny+divy-1)/divy; // lonlat per cell
-        long xgridsize = (maxx-minx+divx-1)/divx; // lonlat per cell
+        const mminforec *b=boundaries(m);
+        long ygridsize = (b->maxy - b->miny + divy - 1)/divy; // lonlat per cell
+        long xgridsize = (b->maxx - b->minx + divx - 1)/divx; // lonlat per cell
 
         if (relx<0 || rely<0 || relx>=divx || rely>=divy)
           return -111;
 
         // and then encodde relative to THE CORNER of this cell
-        rely = miny + (rely*ygridsize);
-        relx = minx + (relx*xgridsize);
+        rely = b->miny + (rely*ygridsize);
+        relx = b->minx + (relx*xgridsize);
 
         {
-          long dividery = ( (((ygridsize))+yside[postlen]-1)/yside[postlen] );
-          long dividerx = ( (((xgridsize))+xside[postlen]-1)/xside[postlen] );
+          long xp = xside[postlen];
+          long dividerx = ( (((xgridsize))+xp-1)/xp );
+          long yp = yside[postlen];
+          long dividery = ( (((ygridsize))+yp-1)/yp );
           // decoderelative
 
           {
@@ -598,24 +607,23 @@ static int decodeGrid(decodeRec *dec, int m, int hasHeaderLetter )
               long v;
               if ( postlen==4 ) { char t = r[1]; r[1]=r[2]; r[2]=t; } // swap
               v = decodeBase31(r);
-              difx = ( v/yside[postlen] );
-              dify = ( v%yside[postlen] );
+              difx = ( v/yp );
+              dify = ( v%yp );
               if ( postlen==4 ) { char t = r[1]; r[1]=r[2]; r[2]=t; } // swap back
             }
 
             // reverse y-direction
-            dify = yside[postlen]-1-dify;
+            dify = yp-1-dify;
 
             dec->lon32 = relx+(difx * dividerx);
             dec->lat32 = rely+(dify * dividery);
-            decodeExtension(dec,  dividerx<<2,dividery,1); // grid
+            return decodeExtension(dec,  dividerx<<2,dividery,1); // grid
           } // decoderelative
 
         }
       }
     }
   }
-  return 0;
 }
 
 
@@ -624,21 +632,21 @@ static int decodeGrid(decodeRec *dec, int m, int hasHeaderLetter )
 
 static void encodeGrid( char* result, const encodeRec *enc, int const m, int extraDigits, char headerLetter )
 {
-  long minx,miny,maxx,maxy;
   long y= enc->lat32,x= enc->lon32;
+  const mminforec *b=boundaries(m);
+
   int orgcodex=coDex(m);
-  int codex=orgcodex;
-  if (codex==21) codex=22;
-  if (codex==14) codex=23;
-  getboundaries(m,minx,miny,maxx,maxy);
+  int codexm=orgcodex;
+  if (codexm==21) codexm=22;
+  if (codexm==14) codexm=23;
 
   *result=0;
   if (headerLetter) result++;
 
   { // encode
     long divx,divy;
-    long prelen = codex/10;
-    long postlen = codex%10;
+    int prelen = codexm/10;
+    int postlen = codexm%10;
 
     divy = smartDiv(m);
     if (divy==1)
@@ -654,10 +662,10 @@ static void encodeGrid( char* result, const encodeRec *enc, int const m, int ext
     }
 
     { // grid
-      long ygridsize = (maxy-miny+divy-1)/divy;
-      long xgridsize = (maxx-minx+divx-1)/divx;
-      long rely = y-miny;
-      long relx = x-minx;
+      long ygridsize = (b->maxy-b->miny+divy-1)/divy;
+      long xgridsize = (b->maxx-b->minx+divx-1)/divx;
+      long rely = y-b->miny;
+      long relx = x-b->minx;
 
       if ( relx<0 )
       {
@@ -675,11 +683,11 @@ static void encodeGrid( char* result, const encodeRec *enc, int const m, int ext
 
       { // prefix
         long v;
-        if ( divx!=divy && codex>24 )
+        if ( divx!=divy && prelen>2 )
           v = encodeSixWide( relx,rely, divx,divy );
         else
           v = relx*divy + (divy-1-rely);
-        encodeBase31( result, v, (int)prelen);
+        encodeBase31( result, v, prelen);
       } // prefix
 
       if ( prelen==4 && divx==xside[4] && divy==yside[4] )
@@ -687,8 +695,8 @@ static void encodeGrid( char* result, const encodeRec *enc, int const m, int ext
         char t = result[1]; result[1]=result[2]; result[2]=t;
       }
 
-      rely = miny + (rely*ygridsize);
-      relx = minx + (relx*xgridsize);
+      rely = b->miny + (rely*ygridsize);
+      relx = b->minx + (relx*xgridsize);
 
       { // postfix
         long dividery = ( (((ygridsize))+yside[postlen]-1)/yside[postlen] );
@@ -719,7 +727,7 @@ static void encodeGrid( char* result, const encodeRec *enc, int const m, int ext
           }
           else
           {
-            encodeBase31(resultptr, (difx)*yside[postlen]+dify, (int)postlen);
+            encodeBase31(resultptr,       (difx)*yside[postlen]+dify, postlen   );
             // swap 4-long codes for readability
             if ( postlen==4 )
             {
@@ -745,26 +753,27 @@ static void encodeGrid( char* result, const encodeRec *enc, int const m, int ext
 
 
 // find first territory rectangle of the same type as m
-static int firstNamelessRecord(int codex, int m, int firstcode) {
+static int firstNamelessRecord(int m, int firstcode) {
     int i = m;
-    while (i >= firstcode && coDex(i) == codex && isNameless(i)) i--;
+    int codexm = coDex(m);
+    while (i >= firstcode && coDex(i) == codexm && isNameless(i)) i--;
     return (i+1);
 }
 
 // count all territory rectangles of the same type as m
-static int countNamelessRecords(int codex, int m, int firstcode) {
-    int i = firstNamelessRecord(codex, m, firstcode);
-    int e = m;
-    while (coDex(e) == codex) e++;
-    return (e-i);
+static int countNamelessRecords(int m, int firstcode) {
+    int i = firstNamelessRecord(m, firstcode);
+    int codexm = coDex(m);
+    while (coDex(m) == codexm) m++;
+    return (m-i);
 }
 
 
 
 
 // decodes dec->mapcode in context of territory rectangle m, territory dec->context
-// Returns x<0 in case of error, or record#
-static int decodeNameless(decodeRec *dec, int m )
+// Returns negative in case of error
+static int decodeNameless(decodeRec *dec, int m)
 {
   int A,F;
   char input[8];
@@ -780,21 +789,18 @@ static int decodeNameless(decodeRec *dec, int m )
   strcpy(input+dc,dec->mapcode+dc+1);
 
 
-  A = countNamelessRecords(codexm,m,firstrec(dec->context));
-  F = firstNamelessRecord( codexm,m,firstrec(dec->context));
+  A = countNamelessRecords(m,firstrec(dec->context));
+  F = firstNamelessRecord(m,firstrec(dec->context));
 
-  if ( (A<2 && codexm!=21) || A<1 )
-    return -3;
-
-  { // check just in case
+  {
     int p = 31/A;
     int r = 31%A;
-    long v=0;
+    long v;
     long SIDE;
     int swapletters=0;
     long xSIDE;
-    long X=-1;
-    long miny,maxy,minx,maxx;
+    int X=-1;
+    const mminforec *b;
 
     // make copy of input, so we can swap around letters during the decoding
     char result[32];
@@ -836,58 +842,44 @@ static int decodeNameless(decodeRec *dec, int m )
       if (A==62) BASEPOWERA++; else BASEPOWERA = 961*(BASEPOWERA/961);
 
       v = decodeBase31(result);
-      X  = (long)(v/BASEPOWERA);
+      X  = (int)(v/BASEPOWERA);
       v %= BASEPOWERA;
     }
 
 
 
-    if (swapletters)
-    {
-      m = (int)(F + X);
-      if ( ! isSpecialShape22(m) )
-      {
+    if (swapletters) {
+      if ( ! isSpecialShape22(F+X) ) {
         char t = result[codexlen-3]; result[codexlen-3]=result[codexlen-2]; result[codexlen-2]=t;
       }
     }
 
-    // adjust v and X
-    if ( codexm!=21 && A<=31 )
-    {
-
+    if ( codexm!=21 && A<=31 ) {
       v = decodeBase31(result);
-      if (X>0)
-      {
+      if (X>0) {
         v -= (X*p + (X<r ? X : r)) * (961*961);
       }
-
     }
-    else if ( codexm!=21 && A<62 )
-    {
-
+    else if ( codexm!=21 && A<62 ) {
       v = decodeBase31(result+1);
-      if ( X >= (62-A) )
-        if ( v >= (16*961*31) )
-        {
+      if ( X >= (62-A) ) {
+        if ( v >= (16*961*31) ) {
           v -= (16*961*31);
           X++;
         }
+      }
     }
 
     m = (int)(F + X);
-    SIDE = smartDiv(m);
 
-    getboundaries(m,minx,miny,maxx,maxy);
-    if ( isSpecialShape22(m) )
-    {
-      xSIDE = SIDE*SIDE;
-      SIDE = 1+((maxy-miny)/90); // side purely on y range
+    xSIDE = SIDE = smartDiv(m);
+
+    b=boundaries(m);
+    if ( isSpecialShape22(m) ) {
+      xSIDE *= SIDE;
+      SIDE = 1+((b->maxy-b->miny)/90); // side purely on y range
       xSIDE = xSIDE / SIDE;
     }
-    else
-    {
-      xSIDE=SIDE;
-    }
 
     // decode
     {
@@ -912,18 +904,18 @@ static int decodeNameless(decodeRec *dec, int m )
       }
 
       {
-        long dividerx4 = xDivider4(miny,maxy); // *** note: dividerx4 is 4 times too large!
-        long dividery = 90;
+        long dividerx4 = xDivider4(b->miny,b->maxy); // *** note: dividerx4 is 4 times too large!
+        long dividery = 90; int err;
 
-        dec->lon32 = minx + ((dx * dividerx4)/4); // *** note: FIRST multiply, then divide... more precise, larger rects
-        dec->lat32 = maxy - (dy*dividery);
-        decodeExtension(dec, dividerx4,dividery,-1); // nameless
+        dec->lon32 = b->minx + ((dx * dividerx4)/4); // *** note: FIRST multiply, then divide... more precise, larger rects
+        dec->lat32 = b->maxy - (dy*dividery);
+        err = decodeExtension(dec, dividerx4,dividery,-1); // nameless
 
-#ifdef SUPPORT_HIGH_PRECISION // BUGFIX!
+#ifdef SUPPORT_HIGH_PRECISION
         dec->lon += ((dx * dividerx4)%4)/4.0;
 #endif
 
-        return m;
+        return err;
       }
     }
   }
@@ -1012,40 +1004,31 @@ static int unpack_if_alldigits(char *input) // returns 1 if unpacked, 0 if left
 }
 
 
-static int stateletter(int ccode) // parent
+/*
 {
-  if (ccode>=usa_from && ccode<=usa_upto) return 1; //ccode_usa
-  if (ccode>=ind_from && ccode<=ind_upto) return 2; //ccode_ind
-  if (ccode>=can_from && ccode<=can_upto) return 3; //ccode_can
-  if (ccode>=aus_from && ccode<=aus_upto) return 4; //ccode_aus
-  if (ccode>=mex_from && ccode<=mex_upto) return 5; //ccode_mex
-  if (ccode>=bra_from && ccode<=bra_upto) return 6; //ccode_bra
-  if (ccode>=rus_from && ccode<=rus_upto) return 7; //ccode_rus
-  if (ccode>=chn_from && ccode<=chn_upto) return 8; //ccode_chn
-  return 0;
 }
-
+*/
 
 // returns -1 (error), or m (also returns *result!=0 in case of success)
-static int encodeNameless( char *result, const encodeRec* enc, int input_ctry, int codexm, int extraDigits, int m )
+static int encodeNameless( char *result, const encodeRec* enc, int input_ctry, int extraDigits, int m )
 {
   // determine how many nameless records there are (A), and which one is this (X)...
   long y= enc->lat32,x= enc->lon32;
-  int  A = countNamelessRecords(codexm, m, firstrec(input_ctry));
-  long X = m - firstNamelessRecord( codexm, m, firstrec(input_ctry));
+  int  A = countNamelessRecords(m, firstrec(input_ctry));
+  long X = m - firstNamelessRecord(m, firstrec(input_ctry));
 
   *result=0;
 
   {
     int p = 31/A;
     int r = 31%A; // the first r items are p+1
-    long codexlen = (codexm/10)+(codexm%10);
+    int codexm = coDex(m);
+    int codexlen = (codexm/10)+(codexm%10);
     // determine side of square around centre
     long SIDE;
 
     long storage_offset;
-    long miny,maxy;
-    long minx,maxx;
+    const mminforec *b;
 
     long xSIDE,orgSIDE;
 
@@ -1083,11 +1066,12 @@ static int encodeNameless( char *result, const encodeRec* enc, int input_ctry, i
     }
     SIDE = smartDiv(m);
 
-    getboundaries(m,minx,miny,maxx,maxy);
+
+    b=boundaries(m);
     orgSIDE=xSIDE=SIDE;
     if ( isSpecialShape22(m) ) //  - keep the existing rectangle!
     {
-        SIDE = 1+((maxy-miny)/90); // new side, based purely on y-distance
+        SIDE = 1+((b->maxy-b->miny)/90); // new side, based purely on y-distance
         xSIDE = (orgSIDE*orgSIDE) / SIDE;
     }
 
@@ -1095,18 +1079,18 @@ static int encodeNameless( char *result, const encodeRec* enc, int input_ctry, i
     {
       long v = storage_offset;
 
-      long dividerx4 = xDivider4(miny,maxy); // *** note: dividerx4 is 4 times too large!
+      long dividerx4 = xDivider4(b->miny,b->maxy); // *** note: dividerx4 is 4 times too large!
 #ifdef SUPPORT_HIGH_PRECISION // precise encoding: take fraction into account!
       long xFracture = (long)(4* enc->fraclon);
 #else
       long xFracture = 0;
 #endif
-      long dx = (4*(x-minx)+xFracture)/dividerx4; // like div, but with floating point value
-      long extrax4 = (x-minx)*4 - dx*dividerx4; // like modulus, but with floating point value
+      long dx = (4*(x-b->minx)+xFracture)/dividerx4; // like div, but with floating point value
+      long extrax4 = (x-b->minx)*4 - dx*dividerx4; // like modulus, but with floating point value
 
       long dividery = 90;
-      long dy     = (maxy-y)/dividery;  // between 0 and SIDE-1
-      long extray = (maxy-y)%dividery;
+      long dy     = (b->maxy-y)/dividery;  // between 0 and SIDE-1
+      long extray = (b->maxy-y)%dividery;
 
 #ifdef SUPPORT_HIGH_PRECISION // precise encoding: check if fraction takes this out of range
       if (extray==0 &&  enc->fraclat>0) {
@@ -1120,16 +1104,16 @@ static int encodeNameless( char *result, const encodeRec* enc, int input_ctry, i
 
       if ( isSpecialShape22(m) )
       {
-        v += encodeSixWide(dx,SIDE-1-dy,xSIDE,SIDE);
+        v += encodeSixWide(dx, SIDE-1-dy, xSIDE, SIDE);
       }
       else
       {
         v +=  (dx*SIDE + dy);
       }
 
-      encodeBase31( result, v, (int)(codexlen+1) ); // nameless
+      encodeBase31(result, v, codexlen + 1); // nameless
       {
-        int dotp=(int)codexlen;
+        int dotp=codexlen;
         if (codexm==13)
           dotp--;
         memmove(result+dotp,result+dotp-1,4); result[dotp-1]='.';
@@ -1157,7 +1141,7 @@ static int encodeNameless( char *result, const encodeRec* enc, int input_ctry, i
 static int decodeAutoHeader(decodeRec *dec,  int m )
 {
   const char *input = dec->mapcode;
-  int firstcodex = coDex(m);
+  int codexm = coDex(m);
   char *dot = strchr(input,'.');
 
   long STORAGE_START=0;
@@ -1169,64 +1153,54 @@ static int decodeAutoHeader(decodeRec *dec,  int m )
   value = decodeBase31(input); // decode top
   value *= (961*31);
 
-  for ( ; coDex(m)==firstcodex && recType(m)>1; m++ )
+  for ( ; coDex(m)==codexm && recType(m)>1; m++ )
   {
-    long minx,miny,maxx,maxy;
-    getboundaries(m,minx,miny,maxx,maxy);
-
-    {
+      const mminforec *b=boundaries(m);
       // determine how many cells
-      long H = (maxy-miny+89)/90; // multiple of 10m
-      long xdiv = xDivider4(miny,maxy);
-      long W = ( (maxx-minx)*4 + (xdiv-1) ) / xdiv;
+      long H = (b->maxy - b->miny + 89)/90; // multiple of 10m
+      long xdiv = xDivider4(b->miny,b->maxy);
+      long W = ( (b->maxx-b->minx)*4 + (xdiv-1) ) / xdiv;
       long product;
 
       // decode
-      // round up to multiples of YSIDE3*XSIDE3...
-      H = YSIDE3*( (H+YSIDE3-1)/YSIDE3 );
-      W = XSIDE3*( (W+XSIDE3-1)/XSIDE3 );
-      product = (W/XSIDE3)*(H/YSIDE3)*961*31;
-      {
+      H = 176*( (H+176-1)/176 );
+      W = 168*( (W+168-1)/168 );
+      product = (W/168) * (H/176) * 961 * 31;
+
+      if (recType(m) == 2) {
         long GOODROUNDER = coDex(m)>=23 ? (961*961*31) : (961*961);
-        if ( recType(m)==2 ) // *+ pipe!
-          product = ((STORAGE_START+product+GOODROUNDER-1)/GOODROUNDER)*GOODROUNDER - STORAGE_START;
+        product = ((STORAGE_START+product+GOODROUNDER-1)/GOODROUNDER)*GOODROUNDER - STORAGE_START;
       }
 
-
       if ( value >= STORAGE_START && value < STORAGE_START + product )
       {
-        // decode
-        long dividerx = (maxx-minx+W-1)/W;
-        long dividery = (maxy-miny+H-1)/H;
+        long dividerx = (b->maxx-b->minx+W-1)/W;
+        long dividery = (b->maxy-b->miny+H-1)/H;
 
         value -= STORAGE_START;
         value /= (961*31);
 
-        // PIPELETTER DECODE
         {
           long difx,dify;
           decode_triple(dot+1,&difx,&dify); // decode bottom 3 chars
           {
-            long vx = (value / (H/YSIDE3))*XSIDE3 + difx; // is vx/168
-            long vy = (value % (H/YSIDE3))*YSIDE3 + dify; // is vy/176
+            long vx = (value / (H/176))*168 + difx; // is vx/168
+            long vy = (value % (H/176))*176 + dify; // is vy/176
 
-            dec->lat32 = maxy - vy*dividery;
-            dec->lon32 = minx + vx*dividerx;
-            if ( dec->lon32<minx || dec->lon32>=maxx || dec->lat32<miny || dec->lat32>maxy ) // *** CAREFUL! do this test BEFORE adding remainder...
+            dec->lat32 = b->maxy - vy * dividery;
+            dec->lon32 = b->minx + vx * dividerx;
+            if (dec->lon32 < b->minx || dec->lon32 >= b->maxx || dec->lat32 < b->miny || dec->lat32 > b->maxy) // *** CAREFUL! do this test BEFORE adding remainder...
             {
               return -122; // invalid code
             }
-            decodeExtension(dec,  dividerx<<2,dividery,-1); // autoheader decode
-
           }
         }
 
-        break;
+        return decodeExtension(dec,  dividerx<<2,dividery,-1); // autoheader decode
       }
       STORAGE_START += product;
-    }
   } // for j
-  return 0;
+  return -1;
 }
 
 // encode in m (know to fit)
@@ -1238,44 +1212,43 @@ static int encodeAutoHeader( char *result, const encodeRec *enc, int m, int extr
 
   // search back to first of the group
   int firstindex = m;
-  int codex = coDex(m);
-  while ( recType(firstindex - 1) > 1 && coDex(firstindex - 1) == codex)
+  int codexm = coDex(m);
+  while ( recType(firstindex - 1) > 1 && coDex(firstindex - 1) == codexm) {
       firstindex--;
+  }
 
-  for (i = firstindex; coDex(i) == codex; i++)
+  for (i = firstindex; coDex(i) == codexm; i++)
   {
     long W,H,xdiv,product;
-    long minx,miny,maxx,maxy;
-
-    getboundaries(i,minx,miny,maxx,maxy);
+    const mminforec *b=boundaries(i);
     // determine how many cells
-    H = (maxy-miny+89)/90; // multiple of 10m
-    xdiv = xDivider4(miny,maxy);
-    W = ( (maxx-minx)*4 + (xdiv-1) ) / xdiv;
+    H = (b->maxy-b->miny+89)/90; // multiple of 10m
+    xdiv = xDivider4(b->miny,b->maxy);
+    W = ( (b->maxx-b->minx)*4 + (xdiv-1) ) / xdiv;
 
     // encodee
-    // round up to multiples of YSIDE3*XSIDE3...
-    H = YSIDE3*( (H+YSIDE3-1)/YSIDE3 );
-    W = XSIDE3*( (W+XSIDE3-1)/XSIDE3 );
-    product = (W/XSIDE3)*(H/YSIDE3)*961*31;
+    // round up to multiples of 176*168...
+    H = 176*( (H+176-1)/176 );
+    W = 168*( (W+168-1)/168 );
+    product = (W/168)*(H/176)*961*31;
     if ( recType(i)==2 ) { // plus pipe
-      long GOODROUNDER = codex>=23 ? (961*961*31) : (961*961);
+      long GOODROUNDER = codexm>=23 ? (961*961*31) : (961*961);
       product = ((STORAGE_START+product+GOODROUNDER-1)/GOODROUNDER)*GOODROUNDER - STORAGE_START;
     }
 
     if ( i==m )
     {
       // encode
-      long dividerx = (maxx-minx+W-1)/W;
-      long vx =     (x-minx)/dividerx;
-      long extrax = (x-minx)%dividerx;
+      long dividerx = (b->maxx-b->minx+W-1)/W;
+      long vx =     (x-b->minx)/dividerx;
+      long extrax = (x-b->minx)%dividerx;
 
-      long dividery = (maxy-miny+H-1)/H;
-      long vy =     (maxy-y)/dividery;
-      long extray = (maxy-y)%dividery;
+      long dividery = (b->maxy-b->miny+H-1)/H;
+      long vy =     (b->maxy-y)/dividery;
+      long extray = (b->maxy-y)%dividery;
 
-      long codexlen = (codex/10)+(codex%10);
-      long value = (vx/XSIDE3) * (H/YSIDE3);
+      long codexlen = (codexm/10)+(codexm%10);
+      long value = (vx/168) * (H/176);
 
 #ifdef SUPPORT_HIGH_PRECISION // precise encoding: check if fraction takes this out of range
       if ( extray==0 &&  enc->fraclat>0 ) {
@@ -1288,12 +1261,12 @@ static int encodeAutoHeader( char *result, const encodeRec *enc, int m, int extr
       }
 #endif
 
-      value += (vy/YSIDE3);
+      value += (vy/176);
 
       // PIPELETTER ENCODE
-      encodeBase31( result, (STORAGE_START/(961*31)) + value, (int)(codexlen-2));
+      encodeBase31( result, (STORAGE_START/(961*31)) + value, (int)codexlen - 2);
       result[codexlen-2]='.';
-      encode_triple( result+codexlen-1, vx%XSIDE3, vy%YSIDE3 );
+      encode_triple( result+codexlen-1, vx%168, vy%176 );
 
       encodeExtension( result,extrax<<2,extray,dividerx<<2,dividery,extraDigits,-1,enc); // autoheader
       return m;
@@ -1342,7 +1315,7 @@ static void encoderEngine( int ccode, const encodeRec *enc, int stop_with_one_re
         {
           if ( isNameless(i) )
           {
-            int ret = encodeNameless( result, enc, ccode, codex, extraDigits, i );
+            int ret = encodeNameless( result, enc, ccode, extraDigits, i );
             if (ret>=0)
             {
               i=ret;
@@ -1555,9 +1528,9 @@ static int decoderEngine( decodeRec *dec )
   {
     // long mapcodes must be interpreted in the parent of a subdivision
 
-	  int parent = ParentTerritoryOf(ccode);
-	  if (len==9 || (len==8 && (parent==ccode_ind || parent==ccode_mex )))
-		  ccode = parent;
+    int parent = ParentTerritoryOf(ccode);
+    if (len==9 || (len==8 && (parent==ccode_ind || parent==ccode_mex )))
+      ccode = parent;
   }
 
   // remember final territory context
@@ -1572,8 +1545,8 @@ static int decoderEngine( decodeRec *dec )
    for ( i = from; i <= upto; i++ )
    {
     int codexi = coDex(i);
-	  if ( recType(i)==0 && !isNameless(i) && (codexi==codex || (codex==22 && codexi==21) ) )
-	  {
+    if ( recType(i)==0 && !isNameless(i) && (codexi==codex || (codex==22 && codexi==21) ) )
+    {
       err = decodeGrid( dec, i, 0 );
 
       if (isRestricted(i)) {
@@ -1592,27 +1565,26 @@ static int decoderEngine( decodeRec *dec )
         }
       }
 
-		  break;
-	  }
-	  else if ( recType(i)==1 && prefixLength(i)+1==prelen && postfixLength(i)==postlen && headerLetter(i)==*s )
-	  {
+      break;
+    }
+    else if ( recType(i)==1 && prefixLength(i)+1==prelen && postfixLength(i)==postlen && headerLetter(i)==*s )
+    {
       err = decodeGrid( dec, i, 1 );
-		  break;
-	  }
-	  else if (isNameless(i) &&
-	   (	(codexi==21 && codex==22)
-	   ||	(codexi==22 && codex==32)
-	   ||	(codexi==13 && codex==23) ) )
-	  {
-      i = decodeNameless( dec, i);
-      if (i<0) err=i; else err=0;
-		  break;
-	  }
-	  else if ( recType(i)>=2 && postlen==3 && prefixLength(i)+postfixLength(i)==prelen+2 )
+      break;
+    }
+    else if (isNameless(i) &&
+     (  (codexi==21 && codex==22)
+     ||  (codexi==22 && codex==32)
+     ||  (codexi==13 && codex==23) ) )
+    {
+      err = decodeNameless( dec, i);
+      break;
+    }
+    else if ( recType(i)>=2 && postlen==3 && prefixLength(i)+postfixLength(i)==prelen+2 )
     {
-		  err = decodeAutoHeader( dec, i );
-		  break;
-	  }
+      err = decodeAutoHeader( dec, i );
+      break;
+    }
    } // for
   }
 
@@ -1834,7 +1806,7 @@ static UWORD* encode_utf16(UWORD* unibuf,int maxlen,const char *mapcode,int lang
       else {
         signed char c = decode_chars[(unsigned char)*s];
         if (c<0) { // vowel or illegal?
-          token=TOKENVOWEL; vowels++;
+          token=TOKENVOWEL; vowels++; // assume vowel (-2,-3,-4)
           if (c==-1) // illegal?
             return -4;
         } else if (c<10) { // digit
@@ -1899,13 +1871,41 @@ static int encodeLatLonToMapcodes_internal( char **v, Mapcodes *mapcodes, double
   enc.lon32-=180000000;
 #endif
 
-  if (tc==0) // ALL results?
+  if (tc<=0) // ALL results?
   {
+#ifdef FAST_ENCODE
+    int HOR=1;
+    int i=0; // pointer into redivar
+    for(;;)
+    {
+      long v = redivar[i++];
+      HOR=1-HOR;
+      if ( v>=0 && v<1024 ) { // leaf?
+        int j,nr = (int)v;
+        for (j=0;j<=nr;j++) {
+          int ctry = (j==nr ? ccode_earth : redivar[i+j]);
+          encoderEngine( ctry,&enc,stop_with_one_result,extraDigits,-1);
+          if ((stop_with_one_result||debugStopAt>=0) && enc.mapcodes->count>0) break;
+        }
+        break;
+      }
+      else {
+        long coord = (HOR ? enc.lon32 : enc.lat32);
+        if ( coord > v ) {
+          i = redivar[i];
+        }
+        else {
+          i++;
+        }
+      }
+    }
+#else
     int i;
     for(i=0;i<MAX_MAPCODE_TERRITORY_CODE;i++) {
       encoderEngine(i,&enc,stop_with_one_result,extraDigits,-1);
       if ((stop_with_one_result||debugStopAt>=0) && enc.mapcodes->count>0) break;
     }
+#endif
   }
   else
   {
@@ -1940,7 +1940,7 @@ char* getTerritoryIsoName(char *result, int territoryCode, int format) // format
   if (territoryCode<1 || territoryCode>MAX_MAPCODE_TERRITORY_CODE)
     *result=0;
   else {
-    int p=stateletter(territoryCode-1);
+    int p=ParentLetter(territoryCode-1);
     char iso3[4];
     const char *ei = get_entity_iso3(iso3,territoryCode-1);
     if (*ei>='0' && *ei<='9') ei++;
diff --git a/mapcodelib/mapcoder.h b/mapcodelib/mapcoder.h
index 5cf603c..9abf06d 100644
--- a/mapcodelib/mapcoder.h
+++ b/mapcodelib/mapcoder.h
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#define mapcode_cversion "2.0.2"
 
 #define UWORD                               unsigned short int  // 2-byte unsigned integer.
 
@@ -162,11 +163,11 @@ int compareWithMapcodeFormat(
  * Convert a territory name to a territory code.
  *
  * Arguments:
- *      isoNam           - Territory name to convert.
- *      parentTerritory  - Parent territory code, or 0 if not available.
+ *      isoNam               - Territory name to convert.
+ *      parentTerritoryCode  - Parent territory code, or 0 if not available.
  *
  * Returns:
- *      Territory code >= 0 if succeeded, or <0 if failed.
+ *      Territory code >0 if succeeded, or <0 if failed.
  */
 int convertTerritoryIsoNameToCode(
     const char* isoName,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/mapcode.git



More information about the Pkg-grass-devel mailing list