From 566adbbe860b98d09d3612661084cae5918ffc2f Mon Sep 17 00:00:00 2001 From: David Ellis Date: Tue, 4 Jun 2024 17:28:33 -0500 Subject: [PATCH 01/12] H3 CLI Hierarchical Subcommands --- src/apps/filters/h3.c | 561 +++++++++++++++++++++++++++ tests/cli/cellToCenterChild.txt | 1 + tests/cli/cellToChildPos.txt | 1 + tests/cli/cellToChildren.txt | 1 + tests/cli/cellToChildrenSize.txt | 1 + tests/cli/cellToParent.txt | 1 + tests/cli/childPosToCell.txt | 1 + tests/cli/compactCells.txt | 9 + tests/cli/uncompactCells.txt | 9 + tests/inputfiles/compact_test1.txt | 19 + tests/inputfiles/compact_test2.txt | 1 + tests/inputfiles/compact_test3.txt | 1 + tests/inputfiles/uncompact_test1.txt | 15 + tests/inputfiles/uncompact_test2.txt | 13 + tests/inputfiles/uncompact_test3.txt | 1 + 15 files changed, 635 insertions(+) create mode 100644 tests/cli/cellToCenterChild.txt create mode 100644 tests/cli/cellToChildPos.txt create mode 100644 tests/cli/cellToChildren.txt create mode 100644 tests/cli/cellToChildrenSize.txt create mode 100644 tests/cli/cellToParent.txt create mode 100644 tests/cli/childPosToCell.txt create mode 100644 tests/cli/compactCells.txt create mode 100644 tests/cli/uncompactCells.txt create mode 100644 tests/inputfiles/compact_test1.txt create mode 100644 tests/inputfiles/compact_test2.txt create mode 100644 tests/inputfiles/compact_test3.txt create mode 100644 tests/inputfiles/uncompact_test1.txt create mode 100644 tests/inputfiles/uncompact_test2.txt create mode 100644 tests/inputfiles/uncompact_test3.txt diff --git a/src/apps/filters/h3.c b/src/apps/filters/h3.c index e11c002b3..6a247658b 100644 --- a/src/apps/filters/h3.c +++ b/src/apps/filters/h3.c @@ -727,6 +727,557 @@ SUBCOMMAND(localIjToCell, return E_SUCCESS; } +/// Hierarchical subcommands + +SUBCOMMAND(cellToParent, + "Returns the H3 index that is the parent (or higher) of the " + "provided cell") { + DEFINE_CELL_ARG(cell, cellArg); + int res = 0; + Arg resArg = {.names = {"-r", "--resolution"}, + .required = true, + .scanFormat = "%d", + .valueName = "res", + .value = &res, + .helpText = + "Resolution, 0-14 inclusive, excluding 15 as it can " + "never be a parent"}; + Arg *args[] = {&cellToParentArg, &helpArg, &cellArg, &resArg}; + PARSE_SUBCOMMAND(argc, argv, args); + H3Index parent; + int valid = H3_EXPORT(isValidCell)(cell); + if (valid == 0) { + return E_CELL_INVALID; + } + H3Error err = H3_EXPORT(cellToParent)(cell, res, &parent); + if (err) { + return err; + } + h3Println(parent); + return E_SUCCESS; +} + +SUBCOMMAND(cellToChildren, + "Returns a JSON array of H3 indexes that are the children (or " + "lower) of the provided cell") { + // TODO: This function contains a lot of code that is very similar to + // `gridDisk`. If this happens again we should DRY them. + DEFINE_CELL_ARG(cell, cellArg); + int res = 0; + Arg resArg = {.names = {"-r", "--resolution"}, + .required = true, + .scanFormat = "%d", + .valueName = "res", + .value = &res, + .helpText = + "Resolution, 1-15 inclusive, excluding 0 as it can " + "never be a child"}; + Arg *args[] = {&cellToChildrenArg, &helpArg, &cellArg, &resArg}; + PARSE_SUBCOMMAND(argc, argv, args); + int64_t len = 0; + H3Error err = H3_EXPORT(cellToChildrenSize)(cell, res, &len); + if (err) { + return err; + } + H3Index *out = calloc(len, sizeof(H3Index)); + if (out == NULL) { + fprintf(stderr, "Failed to allocate memory for the output H3 cells"); + exit(1); + } + err = H3_EXPORT(cellToChildren)(cell, res, out); + if (err) { + free(out); + return err; + } + // Since we don't know *actually* how many cells are in the output (usually + // the max, but sometimes not), we need to do a quick scan to figure out the + // true length in order to properly serialize to a JSON array + int64_t trueLen = 0; + for (int64_t i = 0; i < len; i++) { + if (out[i] != 0) { + trueLen++; + } + } + printf("[ "); + for (int64_t i = 0, j = 0; i < len; i++) { + if (out[i] != 0) { + j++; + printf("\"%" PRIx64 "\"%s", out[i], j == trueLen ? "" : ", "); + } + } + free(out); + printf(" ]\n"); + return E_SUCCESS; +} + +SUBCOMMAND(cellToChildrenSize, + "Returns the maximum number of children for a given cell at the " + "specified child resolution") { + // TODO: Do we want to include this subcommand or no? It can be useful to + // let someone decide for themselves if they really want to run the command + // and get a potentially massive number of cells as the output, but is that + // a concern a CLI user would have? They'd probably just ^C it. + DEFINE_CELL_ARG(cell, cellArg); + int res = 0; + Arg resArg = {.names = {"-r", "--resolution"}, + .required = true, + .scanFormat = "%d", + .valueName = "res", + .value = &res, + .helpText = + "Resolution, 1-15 inclusive, excluding 0 as it can " + "never be a child"}; + Arg *args[] = {&cellToChildrenSizeArg, &helpArg, &cellArg, &resArg}; + PARSE_SUBCOMMAND(argc, argv, args); + int64_t len = 0; + H3Error err = H3_EXPORT(cellToChildrenSize)(cell, res, &len); + if (err) { + return err; + } + printf("%" PRId64, len); + return E_SUCCESS; +} + +SUBCOMMAND( + cellToCenterChild, + "Returns the H3 index that is the centrally-placed child (or lower) of the " + "provided cell") { + DEFINE_CELL_ARG(cell, cellArg); + int res = 0; + Arg resArg = {.names = {"-r", "--resolution"}, + .required = true, + .scanFormat = "%d", + .valueName = "res", + .value = &res, + .helpText = + "Resolution, 1-15 inclusive, excluding 0 as it can " + "never be a child"}; + Arg *args[] = {&cellToCenterChildArg, &helpArg, &cellArg, &resArg}; + PARSE_SUBCOMMAND(argc, argv, args); + H3Index centerChild; + int valid = H3_EXPORT(isValidCell)(cell); + if (valid == 0) { + return E_CELL_INVALID; + } + H3Error err = H3_EXPORT(cellToCenterChild)(cell, res, ¢erChild); + if (err) { + return err; + } + h3Println(centerChild); + return E_SUCCESS; +} + +SUBCOMMAND( + cellToChildPos, + "Returns the position of the child cell within an ordered list of all " + "children of the cell's parent at the specified child resolution") { + DEFINE_CELL_ARG(cell, cellArg); + int res = 0; + Arg resArg = {.names = {"-r", "--resolution"}, + .required = true, + .scanFormat = "%d", + .valueName = "res", + .value = &res, + .helpText = + "Resolution, 1-15 inclusive, excluding 0 as it can " + "never be a child"}; + Arg *args[] = {&cellToChildPosArg, &helpArg, &cellArg, &resArg}; + PARSE_SUBCOMMAND(argc, argv, args); + int64_t len = 0; + H3Error err = H3_EXPORT(cellToChildPos)(cell, res, &len); + if (err) { + return err; + } + printf("%" PRId64, len); + return E_SUCCESS; +} + +SUBCOMMAND(childPosToCell, + "Returns the child cell at a given position and resolution within " + "an ordered list of all children of the parent cell") { + DEFINE_CELL_ARG(cell, cellArg); + int res = 0; + Arg resArg = {.names = {"-r", "--resolution"}, + .required = true, + .scanFormat = "%d", + .valueName = "res", + .value = &res, + .helpText = + "Resolution, 1-15 inclusive, excluding 0 as it can " + "never be a child"}; + int64_t pos; + Arg posArg = { + .names = {"-p", "--position"}, + .required = true, + .scanFormat = "%d", + .valueName = "pos", + .value = &pos, + .helpText = + "The child position within the set of children of the parent cell"}; + Arg *args[] = {&childPosToCellArg, &helpArg, &cellArg, &resArg, &posArg}; + PARSE_SUBCOMMAND(argc, argv, args); + H3Index child; + int valid = H3_EXPORT(isValidCell)(cell); + if (valid == 0) { + return E_CELL_INVALID; + } + H3Error err = H3_EXPORT(childPosToCell)(pos, cell, res, &child); + if (err) { + return err; + } + h3Println(child); + return E_SUCCESS; +} + +SUBCOMMAND(compactCells, + "Compacts the provided set of cells as best as possible. The set of " + "input cells must all share the same resolution. The compacted " + "cells will be printed one per line to stdout.") { + char filename[1024] = {0}; // More than Windows, lol + Arg filenameArg = { + .names = {"-f", "--file"}, + .scanFormat = "%1023c", + .valueName = "FILENAME", + .value = &filename, + .helpText = + "The file to load the cells from. Use -- to read from stdin."}; + char cellStrs[1501] = { + 0}; // Supports up to 100 cells at a time with zero padding + Arg cellStrsArg = {.names = {"-c", "--cells"}, + .scanFormat = "%1500c", + .valueName = "CELLS", + .value = &cellStrs, + .helpText = + "The cells to compact. Up to 100 cells if provided " + "as hexadecimals with zero padding."}; + Arg *args[] = {&compactCellsArg, &helpArg, &filenameArg, &cellStrsArg}; + PARSE_SUBCOMMAND(argc, argv, args); + if (!filenameArg.found && !cellStrsArg.found) { + fprintf(stderr, + "You must provide either a file to read from or a set of cells " + "to compact to use compactCells"); + exit(1); + } + // We use the same consumption logic for both kinds of input, and in fact + // use the cellStrs char array as out input buffer for the file path. The + // only difference between the two is when we reach the end of the buffer. + // If there's a non-null file pointer, we start from the last successful + // consumption from the buffer and move the data following it to the + // beginning of the buffer, then we read some of the file after that and + // slap it on after that and continue the consumption loops, while the other + // path just ends at that point. As we have no idea how many cells we're + // going to load, we allocate enough for 128 cells, but if that's not + // enough, we also have to re-allocate double the number of cells, copy them + // over, and free the old buffer of cells. Doing this manually since we want + // to keep the build process for H3 simple and C's stdlib is pretty bare. + H3Index *cells = calloc(128, sizeof(H3Index)); + FILE *fp = 0; + int cellStrsOffset = 0; + int cellsOffset = 0; + int cellsLen = 128; + bool isStdin = false; + if (filenameArg.found) { + if (strcmp(filename, "--") == 0) { + fp = stdin; + isStdin = true; + } else { + fp = fopen(filename, "r"); + } + if (fp == 0) { + fprintf(stderr, "The specified file does not exist."); + exit(1); + } + // Do the initial population of data from the file + if (fread(cellStrs, 1, 1500, fp) == 0) { + fprintf(stderr, "The specified file is empty."); + exit(1); + } + } + do { + // Always start from the beginning of the buffer + cellStrsOffset = 0; + int lastGoodOffset = 0; + while (cellStrsOffset < 1485) { // Keep consuming as much as possible + H3Index cell = 0; + while (cell == 0 && cellStrsOffset < 1485) { + // Grab 15 characters and then scan to see if it has an H3 index + // in it + char possibleIndex[16] = {0}; + bool badChar = false; + for (int i = 0; i < 15; i++) { + char c = cellStrs[i + cellStrsOffset]; + if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || + (c >= 'A' && c <= 'F')) { + possibleIndex[i] = c; + } else { + // Encountered a bad character, set the offset after + // this character as the next to check + cellStrsOffset += i + 1; + badChar = true; + break; + } + possibleIndex[i] = cellStrs[i + cellStrsOffset]; + } + if (!badChar) { + if (sscanf(possibleIndex, "%" PRIx64, &cell) != 0) { + // We can jump ahead 15 chars. The while loop check will + // make sure we don't overwrite this cell with another + // one + cellStrsOffset += 15; + lastGoodOffset = cellStrsOffset; + } else { + // This *shouldn't* happen, I think? But try again if + // necessary + cellStrsOffset++; + } + } + } + // If we still don't have a cell and we've reached the end, we reset + // the offset and `continue` to trigger another read + if (cell == 0 && cellStrsOffset == 1500) { + cellStrsOffset = 0; + continue; + } + // Otherwise, we have a cell to shove into the cells array. + cells[cellsOffset] = cell; + cellsOffset++; + // Potentially grow our array + if (cellsOffset == cellsLen) { + cellsLen *= 2; + H3Index *newCells = calloc(cellsLen, sizeof(H3Index)); + for (int i = 0; i < cellsOffset; i++) { + newCells[i] = cells[i]; + } + free(cells); + cells = newCells; + } + } + // In case there's a valid H3 index that was unfortunately split between + // buffer reads, we take from the lastGoodOffset and copy the rest to + // the beginning of the buffer so it can be re-assembled on the next + // file read. However, we also know that a valid H3 index is 15 + // characters long, so if the lastGoodOffset is 15 or more characters + // away from 1500, we only need to copy those final 14 bytes from the + // end, so if lastGoodOffset is 1485 or less, we force it to 1485 and + // then move the chunk as specified to the beginning and adjust the + // cellStrsOffset. + if (lastGoodOffset < 1485) { + lastGoodOffset = 1485; + } + for (int i = 0; i < 1500 - lastGoodOffset; i++) { + cellStrs[i] = cellStrs[i + lastGoodOffset]; + } + cellStrsOffset = 1500 - lastGoodOffset; + } while (fp != 0 && fread(cellStrs + cellStrsOffset, 1, + 1500 - cellStrsOffset, fp) != 0); + if (fp != 0 && !isStdin) { + fclose(fp); + } + // Now that we have the cells in a buffer and the actual cell count in + // cellsOffset, we can feed this to the H3 C API + H3Index *compactedSet = calloc(cellsOffset, sizeof(H3Index)); + H3Error err = H3_EXPORT(compactCells)(cells, compactedSet, cellsOffset); + if (err) { + free(cells); + free(compactedSet); + return err; + } + // We have a compacted set! Let's print them out + for (int i = 0; i < cellsOffset; i++) { + if (compactedSet[i] == 0) { + continue; + } + h3Println(compactedSet[i]); + } + free(cells); + free(compactedSet); + return E_SUCCESS; +} + +SUBCOMMAND(uncompactCells, + "Unompacts the provided set of compacted cells." + "The uncompacted " + "cells will be printed one per line to stdout.") { + // TODO: *Most* of this logic is shared with compactCells. See about DRYing + // it. + char filename[1024] = {0}; // More than Windows, lol + Arg filenameArg = { + .names = {"-f", "--file"}, + .scanFormat = "%1023c", + .valueName = "FILENAME", + .value = &filename, + .helpText = + "The file to load the cells from. Use -- to read from stdin."}; + char cellStrs[1501] = { + 0}; // Supports up to 100 cells at a time with zero padding + Arg cellStrsArg = { + .names = {"-c", "--cells"}, + .scanFormat = "%1500c", + .valueName = "CELLS", + .value = &cellStrs, + .helpText = + "The cells to uncompact. Up to 100 cells if provided " + "as hexadecimals with zero padding."}; + int res = 0; + Arg resArg = {.names = {"-r", "--resolution"}, + .required = true, + .scanFormat = "%d", + .valueName = "res", + .value = &res, + .helpText = + "Resolution, 0-15 inclusive, that the compacted set " + "should be uncompacted to. Must be greater than or equal " + "to the highest resolution within the compacted set."}; + Arg *args[] = {&uncompactCellsArg, &helpArg, &filenameArg, &cellStrsArg, + &resArg}; + PARSE_SUBCOMMAND(argc, argv, args); + if (!filenameArg.found && !cellStrsArg.found) { + fprintf(stderr, + "You must provide either a file to read from or a set of cells " + "to compact to use uncompactCells"); + exit(1); + } + // We use the same consumption logic for both kinds of input, and in fact + // use the cellStrs char array as out input buffer for the file path. The + // only difference between the two is when we reach the end of the buffer. + // If there's a non-null file pointer, we start from the last successful + // consumption from the buffer and move the data following it to the + // beginning of the buffer, then we read some of the file after that and + // slap it on after that and continue the consumption loops, while the other + // path just ends at that point. As we have no idea how many cells we're + // going to load, we allocate enough for 128 cells, but if that's not + // enough, we also have to re-allocate double the number of cells, copy them + // over, and free the old buffer of cells. Doing this manually since we want + // to keep the build process for H3 simple and C's stdlib is pretty bare. + H3Index *cells = calloc(128, sizeof(H3Index)); + FILE *fp = 0; + int cellStrsOffset = 0; + int cellsOffset = 0; + int cellsLen = 128; + bool isStdin = false; + if (filenameArg.found) { + if (strcmp(filename, "--") == 0) { + fp = stdin; + isStdin = true; + } else { + fp = fopen(filename, "r"); + } + if (fp == 0) { + fprintf(stderr, "The specified file does not exist."); + exit(1); + } + // Do the initial population of data from the file + if (fread(cellStrs, 1, 1500, fp) == 0) { + fprintf(stderr, "The specified file is empty."); + exit(1); + } + } + do { + // Always start from the beginning of the buffer + cellStrsOffset = 0; + int lastGoodOffset = 0; + while (cellStrsOffset < 1485) { // Keep consuming as much as possible + H3Index cell = 0; + while (cell == 0 && cellStrsOffset < 1485) { + // Grab 15 characters and then scan to see if it has an H3 index + // in it + char possibleIndex[16] = {0}; + bool badChar = false; + for (int i = 0; i < 15 && !badChar; i++) { + char c = cellStrs[i + cellStrsOffset]; + if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || + (c >= 'A' && c <= 'F')) { + possibleIndex[i] = c; + } else { + // Encountered a bad character, set the offset after + // this character as the next to check + cellStrsOffset += i + 1; + badChar = true; + } + possibleIndex[i] = cellStrs[i + cellStrsOffset]; + } + if (!badChar) { + if (sscanf(possibleIndex, "%" PRIx64, &cell) != 0) { + // We can jump ahead 15 chars. The while loop check will + // make sure we don't overwrite this cell with another + // one + cellStrsOffset += 15; + lastGoodOffset = cellStrsOffset; + } + } else { + cell = 0; + } + } + // If we still don't have a cell and we've reached the end, we reset + // the offset and `continue` to trigger another read + if (cell == 0 && cellStrsOffset == 1500) { + cellStrsOffset = 0; + continue; + } + // Otherwise, we have a cell to shove into the cells array. + cells[cellsOffset] = cell; + cellsOffset++; + // Potentially grow our array + if (cellsOffset == cellsLen) { + cellsLen *= 2; + H3Index *newCells = calloc(cellsLen, sizeof(H3Index)); + for (int i = 0; i < cellsOffset; i++) { + newCells[i] = cells[i]; + } + free(cells); + cells = newCells; + } + } + // In case there's a valid H3 index that was unfortunately split between + // buffer reads, we take from the lastGoodOffset and copy the rest to + // the beginning of the buffer so it can be re-assembled on the next + // file read. However, we also know that a valid H3 index is 15 + // characters long, so if the lastGoodOffset is 15 or more characters + // away from 1500, we only need to copy those final 14 bytes from the + // end, so if lastGoodOffset is 1485 or less, we force it to 1485 and + // then move the chunk as specified to the beginning and adjust the + // cellStrsOffset. + if (lastGoodOffset < 1485) { + lastGoodOffset = 1485; + } + for (int i = 0; i < 1500 - lastGoodOffset; i++) { + cellStrs[i] = cellStrs[i + lastGoodOffset]; + } + cellStrsOffset = 1500 - lastGoodOffset; + } while (fp != 0 && fread(cellStrs + cellStrsOffset, 1, + 1500 - cellStrsOffset, fp) != 0); + if (fp != 0 && !isStdin) { + fclose(fp); + } + // Now that we have the cells in a buffer and the actual cell count in + // cellsOffset, we can feed this to the H3 C API + int64_t uncompactedSize = 0; + H3Error err = H3_EXPORT(uncompactCellsSize)(cells, cellsOffset, res, + &uncompactedSize); + if (err) { + free(cells); + return err; + } + H3Index *uncompactedSet = calloc(uncompactedSize, sizeof(H3Index)); + err = H3_EXPORT(uncompactCells)(cells, cellsOffset, uncompactedSet, + uncompactedSize, res); + if (err) { + free(cells); + free(uncompactedSet); + return err; + } + // We have a compacted set! Let's print them out + for (int i = 0; i < uncompactedSize; i++) { + if (uncompactedSet[i] == 0) { + continue; + } + h3Println(uncompactedSet[i]); + } + free(cells); + free(uncompactedSet); + return E_SUCCESS; +} + // TODO: Is there any way to avoid this particular piece of duplication? SUBCOMMANDS_INDEX @@ -754,6 +1305,16 @@ SUBCOMMAND_INDEX(gridDistance) SUBCOMMAND_INDEX(cellToLocalIj) SUBCOMMAND_INDEX(localIjToCell) +/// Hierarchical subcommands +SUBCOMMAND_INDEX(cellToParent) +SUBCOMMAND_INDEX(cellToChildren) +SUBCOMMAND_INDEX(cellToChildrenSize) +SUBCOMMAND_INDEX(cellToCenterChild) +SUBCOMMAND_INDEX(cellToChildPos) +SUBCOMMAND_INDEX(childPosToCell) +SUBCOMMAND_INDEX(compactCells) +SUBCOMMAND_INDEX(uncompactCells) + END_SUBCOMMANDS_INDEX int main(int argc, char *argv[]) { diff --git a/tests/cli/cellToCenterChild.txt b/tests/cli/cellToCenterChild.txt new file mode 100644 index 000000000..a7212b3c3 --- /dev/null +++ b/tests/cli/cellToCenterChild.txt @@ -0,0 +1 @@ +add_h3_cli_test(testCliCellToCenterChild "cellToCenterChild -c 85283473fffffff --resolution 7" "872834700ffffff") diff --git a/tests/cli/cellToChildPos.txt b/tests/cli/cellToChildPos.txt new file mode 100644 index 000000000..05df374c2 --- /dev/null +++ b/tests/cli/cellToChildPos.txt @@ -0,0 +1 @@ +add_h3_cli_test(testCliCellToChildPos "cellToChildPos -c 85283473fffffff -r 3" "25") diff --git a/tests/cli/cellToChildren.txt b/tests/cli/cellToChildren.txt new file mode 100644 index 000000000..d6d8905e7 --- /dev/null +++ b/tests/cli/cellToChildren.txt @@ -0,0 +1 @@ +add_h3_cli_test(testCliCellToChildren "cellToChildren -c 85283473fffffff -r 6" "[ \"862834707ffffff\", \"86283470fffffff\", \"862834717ffffff\", \"86283471fffffff\", \"862834727ffffff\", \"86283472fffffff\", \"862834737ffffff\" ]") diff --git a/tests/cli/cellToChildrenSize.txt b/tests/cli/cellToChildrenSize.txt new file mode 100644 index 000000000..f51b29e5d --- /dev/null +++ b/tests/cli/cellToChildrenSize.txt @@ -0,0 +1 @@ +add_h3_cli_test(testCliCellToChildrenSize "cellToChildrenSize -c 85283473fffffff -r 6" "7") diff --git a/tests/cli/cellToParent.txt b/tests/cli/cellToParent.txt new file mode 100644 index 000000000..8ecd61423 --- /dev/null +++ b/tests/cli/cellToParent.txt @@ -0,0 +1 @@ +add_h3_cli_test(testCliCellToParent "cellToParent -c 8928342e20fffff --resolution 3" "832834fffffffff") diff --git a/tests/cli/childPosToCell.txt b/tests/cli/childPosToCell.txt new file mode 100644 index 000000000..60f1e7398 --- /dev/null +++ b/tests/cli/childPosToCell.txt @@ -0,0 +1 @@ +add_h3_cli_test(testCliChildPosToCell "childPosToCell -c 85283473fffffff -r 7 -p 42" "872834730ffffff") diff --git a/tests/cli/compactCells.txt b/tests/cli/compactCells.txt new file mode 100644 index 000000000..b89b726f6 --- /dev/null +++ b/tests/cli/compactCells.txt @@ -0,0 +1,9 @@ +add_h3_cli_test(testCliCompactCellsFile1 "compactCells -f tests/inputfiles/compact_test1.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsFile2 "compactCells -f tests/inputfiles/compact_test2.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsFile3 "compactCells -f tests/inputfiles/compact_test3.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsStdin1 "compactCells -f -- < tests/inputfiles/compact_test1.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsStdin2 "compactCells -f -- < tests/inputfiles/compact_test2.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsStdin3 "compactCells -f -- < tests/inputfiles/compact_test3.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsArg1 "compactCells -c \"\\\\`cat tests/inputfiles/compact_test1.txt\\\\`\"" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsArg2 "compactCells -c \\\\`cat tests/inputfiles/compact_test2.txt\\\\`" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsArg3 "compactCells -c \\\\`cat tests/inputfiles/compact_test3.txt\\\\`" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") diff --git a/tests/cli/uncompactCells.txt b/tests/cli/uncompactCells.txt new file mode 100644 index 000000000..b355c763c --- /dev/null +++ b/tests/cli/uncompactCells.txt @@ -0,0 +1,9 @@ +add_h3_cli_test(testCliUncompactCellsFile1 "uncompactCells -r 5 -f tests/inputfiles/uncompact_test1.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsFile2 "uncompactCells -r 5 -f tests/inputfiles/uncompact_test2.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsFile3 "uncompactCells -r 5 -f tests/inputfiles/uncompact_test3.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsStdin1 "uncompactCells -r 5 -f -- < tests/inputfiles/uncompact_test1.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsStdin2 "uncompactCells -r 5 -f -- < tests/inputfiles/uncompact_test2.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsStdin3 "uncompactCells -r 5 -f -- < tests/inputfiles/uncompact_test3.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsArg1 "uncompactCells -r 5 -c \"\\\\`cat tests/inputfiles/uncompact_test1.txt\\\\`\"" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsArg2 "uncompactCells -r 5 -c \"\\\\`cat tests/inputfiles/uncompact_test2.txt\\\\`\"" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsArg3 "uncompactCells -r 5 -c \\\\`cat tests/inputfiles/uncompact_test3.txt\\\\`" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") diff --git a/tests/inputfiles/compact_test1.txt b/tests/inputfiles/compact_test1.txt new file mode 100644 index 000000000..b7c763104 --- /dev/null +++ b/tests/inputfiles/compact_test1.txt @@ -0,0 +1,19 @@ +"85283473fffffff", +"85283447fffffff", +"8528347bfffffff", +"85283463fffffff", +"85283477fffffff", +"8528340ffffffff", +"8528340bfffffff", +"85283457fffffff", +"85283443fffffff", +"8528344ffffffff", +"852836b7fffffff", +"8528346bfffffff", +"8528346ffffffff", +"85283467fffffff", +"8528342bfffffff", +"8528343bfffffff", +"85283407fffffff", +"85283403fffffff", +"8528341bfffffff" diff --git a/tests/inputfiles/compact_test2.txt b/tests/inputfiles/compact_test2.txt new file mode 100644 index 000000000..6200da6f9 --- /dev/null +++ b/tests/inputfiles/compact_test2.txt @@ -0,0 +1 @@ +"85283473fffffff","85283447fffffff","8528347bfffffff","85283463fffffff","85283477fffffff","8528340ffffffff","8528340bfffffff","85283457fffffff","85283443fffffff","8528344ffffffff","852836b7fffffff","8528346bfffffff","8528346ffffffff","85283467fffffff","8528342bfffffff","8528343bfffffff","85283407fffffff","85283403fffffff","8528341bfffffff" diff --git a/tests/inputfiles/compact_test3.txt b/tests/inputfiles/compact_test3.txt new file mode 100644 index 000000000..c920c3467 --- /dev/null +++ b/tests/inputfiles/compact_test3.txt @@ -0,0 +1 @@ +85283473fffffff85283447fffffff8528347bfffffff85283463fffffff85283477fffffff8528340ffffffff8528340bfffffff85283457fffffff85283443fffffff8528344ffffffff852836b7fffffff8528346bfffffff8528346ffffffff85283467fffffff8528342bfffffff8528343bfffffff85283407fffffff85283403fffffff8528341bfffffff diff --git a/tests/inputfiles/uncompact_test1.txt b/tests/inputfiles/uncompact_test1.txt new file mode 100644 index 000000000..faecca4cd --- /dev/null +++ b/tests/inputfiles/uncompact_test1.txt @@ -0,0 +1,15 @@ +[ + "85283447fffffff", + "8528340ffffffff", + "8528340bfffffff", + "85283457fffffff", + "85283443fffffff", + "8528344ffffffff", + "852836b7fffffff", + "8528342bfffffff", + "8528343bfffffff", + "85283407fffffff", + "85283403fffffff", + "8528341bfffffff", + "8428347ffffffff" +] diff --git a/tests/inputfiles/uncompact_test2.txt b/tests/inputfiles/uncompact_test2.txt new file mode 100644 index 000000000..f32646773 --- /dev/null +++ b/tests/inputfiles/uncompact_test2.txt @@ -0,0 +1,13 @@ +85283447fffffff +8528340ffffffff +8528340bfffffff +85283457fffffff +85283443fffffff +8528344ffffffff +852836b7fffffff +8528342bfffffff +8528343bfffffff +85283407fffffff +85283403fffffff +8528341bfffffff +8428347ffffffff diff --git a/tests/inputfiles/uncompact_test3.txt b/tests/inputfiles/uncompact_test3.txt new file mode 100644 index 000000000..8c3f4b5cf --- /dev/null +++ b/tests/inputfiles/uncompact_test3.txt @@ -0,0 +1 @@ +85283447fffffff8528340ffffffff8528340bfffffff85283457fffffff85283443fffffff8528344ffffffff852836b7fffffff8528342bfffffff8528343bfffffff85283407fffffff85283403fffffff8528341bfffffff8428347ffffffff From 19cb695920fa57c5714ae436d3cf294a75f0b29e Mon Sep 17 00:00:00 2001 From: David Ellis Date: Fri, 14 Jun 2024 11:14:57 -0500 Subject: [PATCH 02/12] Update compactCells and uncompactCells tests to also work if a build directory is set --- tests/cli/compactCells.txt | 18 +++++++++--------- tests/cli/uncompactCells.txt | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/cli/compactCells.txt b/tests/cli/compactCells.txt index b89b726f6..9039df6c9 100644 --- a/tests/cli/compactCells.txt +++ b/tests/cli/compactCells.txt @@ -1,9 +1,9 @@ -add_h3_cli_test(testCliCompactCellsFile1 "compactCells -f tests/inputfiles/compact_test1.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") -add_h3_cli_test(testCliCompactCellsFile2 "compactCells -f tests/inputfiles/compact_test2.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") -add_h3_cli_test(testCliCompactCellsFile3 "compactCells -f tests/inputfiles/compact_test3.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") -add_h3_cli_test(testCliCompactCellsStdin1 "compactCells -f -- < tests/inputfiles/compact_test1.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") -add_h3_cli_test(testCliCompactCellsStdin2 "compactCells -f -- < tests/inputfiles/compact_test2.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") -add_h3_cli_test(testCliCompactCellsStdin3 "compactCells -f -- < tests/inputfiles/compact_test3.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") -add_h3_cli_test(testCliCompactCellsArg1 "compactCells -c \"\\\\`cat tests/inputfiles/compact_test1.txt\\\\`\"" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") -add_h3_cli_test(testCliCompactCellsArg2 "compactCells -c \\\\`cat tests/inputfiles/compact_test2.txt\\\\`" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") -add_h3_cli_test(testCliCompactCellsArg3 "compactCells -c \\\\`cat tests/inputfiles/compact_test3.txt\\\\`" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsFile1 "compactCells -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test1.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsFile2 "compactCells -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test2.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsFile3 "compactCells -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test3.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsStdin1 "compactCells -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test1.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsStdin2 "compactCells -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test2.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsStdin3 "compactCells -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test3.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsArg1 "compactCells -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test1.txt\\\\`\"" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsArg2 "compactCells -c \\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test2.txt\\\\`" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsArg3 "compactCells -c \\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test3.txt\\\\`" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") diff --git a/tests/cli/uncompactCells.txt b/tests/cli/uncompactCells.txt index b355c763c..cb2b1ae48 100644 --- a/tests/cli/uncompactCells.txt +++ b/tests/cli/uncompactCells.txt @@ -1,9 +1,9 @@ -add_h3_cli_test(testCliUncompactCellsFile1 "uncompactCells -r 5 -f tests/inputfiles/uncompact_test1.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") -add_h3_cli_test(testCliUncompactCellsFile2 "uncompactCells -r 5 -f tests/inputfiles/uncompact_test2.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") -add_h3_cli_test(testCliUncompactCellsFile3 "uncompactCells -r 5 -f tests/inputfiles/uncompact_test3.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") -add_h3_cli_test(testCliUncompactCellsStdin1 "uncompactCells -r 5 -f -- < tests/inputfiles/uncompact_test1.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") -add_h3_cli_test(testCliUncompactCellsStdin2 "uncompactCells -r 5 -f -- < tests/inputfiles/uncompact_test2.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") -add_h3_cli_test(testCliUncompactCellsStdin3 "uncompactCells -r 5 -f -- < tests/inputfiles/uncompact_test3.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") -add_h3_cli_test(testCliUncompactCellsArg1 "uncompactCells -r 5 -c \"\\\\`cat tests/inputfiles/uncompact_test1.txt\\\\`\"" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") -add_h3_cli_test(testCliUncompactCellsArg2 "uncompactCells -r 5 -c \"\\\\`cat tests/inputfiles/uncompact_test2.txt\\\\`\"" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") -add_h3_cli_test(testCliUncompactCellsArg3 "uncompactCells -r 5 -c \\\\`cat tests/inputfiles/uncompact_test3.txt\\\\`" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsFile1 "uncompactCells -r 5 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test1.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsFile2 "uncompactCells -r 5 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test2.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsFile3 "uncompactCells -r 5 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test3.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsStdin1 "uncompactCells -r 5 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test1.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsStdin2 "uncompactCells -r 5 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test2.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsStdin3 "uncompactCells -r 5 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test3.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsArg1 "uncompactCells -r 5 -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test1.txt\\\\`\"" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsArg2 "uncompactCells -r 5 -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test2.txt\\\\`\"" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsArg3 "uncompactCells -r 5 -c \\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test3.txt\\\\`" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") From c35620cd6a75ac519db0701e8c762d0f95507420 Mon Sep 17 00:00:00 2001 From: David Ellis Date: Fri, 14 Jun 2024 14:28:14 -0500 Subject: [PATCH 03/12] Attempt some newline mangling shenanigans to get Windows testing working --- tests/cli/compactCells.txt | 18 +++++++++--------- tests/cli/uncompactCells.txt | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/cli/compactCells.txt b/tests/cli/compactCells.txt index 9039df6c9..1873e9376 100644 --- a/tests/cli/compactCells.txt +++ b/tests/cli/compactCells.txt @@ -1,9 +1,9 @@ -add_h3_cli_test(testCliCompactCellsFile1 "compactCells -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test1.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") -add_h3_cli_test(testCliCompactCellsFile2 "compactCells -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test2.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") -add_h3_cli_test(testCliCompactCellsFile3 "compactCells -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test3.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") -add_h3_cli_test(testCliCompactCellsStdin1 "compactCells -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test1.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") -add_h3_cli_test(testCliCompactCellsStdin2 "compactCells -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test2.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") -add_h3_cli_test(testCliCompactCellsStdin3 "compactCells -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test3.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") -add_h3_cli_test(testCliCompactCellsArg1 "compactCells -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test1.txt\\\\`\"" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") -add_h3_cli_test(testCliCompactCellsArg2 "compactCells -c \\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test2.txt\\\\`" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") -add_h3_cli_test(testCliCompactCellsArg3 "compactCells -c \\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test3.txt\\\\`" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n8428347ffffffff") +add_h3_cli_test(testCliCompactCellsFile1 "compactCells -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test1.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsFile2 "compactCells -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test2.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsFile3 "compactCells -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test3.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsStdin1 "compactCells -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test1.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsStdin2 "compactCells -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test2.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsStdin3 "compactCells -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test3.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsArg1 "compactCells -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test1.txt\\\\`\" | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsArg2 "compactCells -c \\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test2.txt\\\\` | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsArg3 "compactCells -c \\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test3.txt\\\\` | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") diff --git a/tests/cli/uncompactCells.txt b/tests/cli/uncompactCells.txt index cb2b1ae48..a75d1513f 100644 --- a/tests/cli/uncompactCells.txt +++ b/tests/cli/uncompactCells.txt @@ -1,9 +1,9 @@ -add_h3_cli_test(testCliUncompactCellsFile1 "uncompactCells -r 5 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test1.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") -add_h3_cli_test(testCliUncompactCellsFile2 "uncompactCells -r 5 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test2.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") -add_h3_cli_test(testCliUncompactCellsFile3 "uncompactCells -r 5 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test3.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") -add_h3_cli_test(testCliUncompactCellsStdin1 "uncompactCells -r 5 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test1.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") -add_h3_cli_test(testCliUncompactCellsStdin2 "uncompactCells -r 5 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test2.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") -add_h3_cli_test(testCliUncompactCellsStdin3 "uncompactCells -r 5 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test3.txt" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") -add_h3_cli_test(testCliUncompactCellsArg1 "uncompactCells -r 5 -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test1.txt\\\\`\"" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") -add_h3_cli_test(testCliUncompactCellsArg2 "uncompactCells -r 5 -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test2.txt\\\\`\"" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") -add_h3_cli_test(testCliUncompactCellsArg3 "uncompactCells -r 5 -c \\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test3.txt\\\\`" "85283447fffffff\n8528340ffffffff\n8528340bfffffff\n85283457fffffff\n85283443fffffff\n8528344ffffffff\n852836b7fffffff\n8528342bfffffff\n8528343bfffffff\n85283407fffffff\n85283403fffffff\n8528341bfffffff\n85283463fffffff\n85283467fffffff\n8528346bfffffff\n8528346ffffffff\n85283473fffffff\n85283477fffffff\n8528347bfffffff") +add_h3_cli_test(testCliUncompactCellsFile1 "uncompactCells -r 5 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test1.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsFile2 "uncompactCells -r 5 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test2.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsFile3 "uncompactCells -r 5 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test3.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsStdin1 "uncompactCells -r 5 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test1.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsStdin2 "uncompactCells -r 5 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test2.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsStdin3 "uncompactCells -r 5 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test3.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsArg1 "uncompactCells -r 5 -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test1.txt\\\\`\" | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsArg2 "uncompactCells -r 5 -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test2.txt\\\\`\" | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsArg3 "uncompactCells -r 5 -c \\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test3.txt\\\\` | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") From bed10059b1af1360ad832c6c535127dc909d54ed Mon Sep 17 00:00:00 2001 From: David Ellis Date: Fri, 14 Jun 2024 15:08:46 -0500 Subject: [PATCH 04/12] Lol, how did this work before? What casting magic is the GNU libc doing? --- src/apps/applib/include/args.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/applib/include/args.h b/src/apps/applib/include/args.h index 511913836..038038b03 100644 --- a/src/apps/applib/include/args.h +++ b/src/apps/applib/include/args.h @@ -90,7 +90,7 @@ int _parseArgsList(int argc, char *argv[], int numArgs, Arg *args[], // common arguments #define ARG_HELP \ - { .names = {"-h", "--help"}, .helpText = "Show this help message." } + {.names = {"-h", "--help"}, .helpText = "Show this help message."} #define DEFINE_INDEX_ARG(varName, argName) \ H3Index varName = 0; \ Arg argName = { \ @@ -109,7 +109,7 @@ int _parseArgsList(int argc, char *argv[], int numArgs, Arg *args[], .value = &varName, \ .helpText = "H3 Cell"} #define ARG_KML \ - { .names = {"-k", "--kml"}, .helpText = "Print output in KML format." } + {.names = {"-k", "--kml"}, .helpText = "Print output in KML format."} #define DEFINE_KML_NAME_ARG(varName, argName) \ char varName[BUFF_SIZE] = {0}; \ Arg argName = { \ From e9cc63fb9aad1ad12699fa9ce0230b2967a0cb95 Mon Sep 17 00:00:00 2001 From: David Ellis Date: Fri, 14 Jun 2024 15:11:20 -0500 Subject: [PATCH 05/12] Revert "Lol, how did this work before? What casting magic is the GNU libc doing?" This reverts commit 7549c75ca424b779057599e9263a2ef48706cb51. --- src/apps/applib/include/args.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/applib/include/args.h b/src/apps/applib/include/args.h index 038038b03..511913836 100644 --- a/src/apps/applib/include/args.h +++ b/src/apps/applib/include/args.h @@ -90,7 +90,7 @@ int _parseArgsList(int argc, char *argv[], int numArgs, Arg *args[], // common arguments #define ARG_HELP \ - {.names = {"-h", "--help"}, .helpText = "Show this help message."} + { .names = {"-h", "--help"}, .helpText = "Show this help message." } #define DEFINE_INDEX_ARG(varName, argName) \ H3Index varName = 0; \ Arg argName = { \ @@ -109,7 +109,7 @@ int _parseArgsList(int argc, char *argv[], int numArgs, Arg *args[], .value = &varName, \ .helpText = "H3 Cell"} #define ARG_KML \ - {.names = {"-k", "--kml"}, .helpText = "Print output in KML format."} + { .names = {"-k", "--kml"}, .helpText = "Print output in KML format." } #define DEFINE_KML_NAME_ARG(varName, argName) \ char varName[BUFF_SIZE] = {0}; \ Arg argName = { \ From 93962f0fb624d1e34ce3381b5aec715e434214d3 Mon Sep 17 00:00:00 2001 From: David Ellis Date: Fri, 14 Jun 2024 15:11:47 -0500 Subject: [PATCH 06/12] Accidentally committed the wrong file --- src/apps/filters/h3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/filters/h3.c b/src/apps/filters/h3.c index 6a247658b..f6bf8ca9e 100644 --- a/src/apps/filters/h3.c +++ b/src/apps/filters/h3.c @@ -909,7 +909,7 @@ SUBCOMMAND(childPosToCell, Arg posArg = { .names = {"-p", "--position"}, .required = true, - .scanFormat = "%d", + .scanFormat = "%" PRIi64, .valueName = "pos", .value = &pos, .helpText = From 26240e6faa0c7aada1dac8a6c334fb8aa3f6fe0e Mon Sep 17 00:00:00 2001 From: David Ellis Date: Mon, 15 Jul 2024 18:04:27 +0200 Subject: [PATCH 07/12] Minor refactor to eliminate the string copy --- src/apps/filters/h3.c | 33 ++++++++++++++-------------- tests/inputfiles/compact_test3.txt | 2 +- tests/inputfiles/uncompact_test3.txt | 2 +- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/apps/filters/h3.c b/src/apps/filters/h3.c index f6bf8ca9e..2821a9c84 100644 --- a/src/apps/filters/h3.c +++ b/src/apps/filters/h3.c @@ -1000,15 +1000,14 @@ SUBCOMMAND(compactCells, while (cellStrsOffset < 1485) { // Keep consuming as much as possible H3Index cell = 0; while (cell == 0 && cellStrsOffset < 1485) { - // Grab 15 characters and then scan to see if it has an H3 index - // in it - char possibleIndex[16] = {0}; + // A valid H3 cell is exactly 15 hexadecomical characters. + // Determine if we have a match, otherwise increment bool badChar = false; for (int i = 0; i < 15; i++) { char c = cellStrs[i + cellStrsOffset]; if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) { - possibleIndex[i] = c; + // Do nothing } else { // Encountered a bad character, set the offset after // this character as the next to check @@ -1016,19 +1015,20 @@ SUBCOMMAND(compactCells, badChar = true; break; } - possibleIndex[i] = cellStrs[i + cellStrsOffset]; } if (!badChar) { - if (sscanf(possibleIndex, "%" PRIx64, &cell) != 0) { + if (sscanf(cellStrs + cellStrsOffset, "%" PRIx64, &cell) != + 0) { // We can jump ahead 15 chars. The while loop check will // make sure we don't overwrite this cell with another // one cellStrsOffset += 15; lastGoodOffset = cellStrsOffset; } else { - // This *shouldn't* happen, I think? But try again if - // necessary - cellStrsOffset++; + // This *shouldn't* happen because it should have been + // caught in the for loop above, but move to the next + // character and try again if it somehow does + return E_FAILED; } } } @@ -1179,33 +1179,32 @@ SUBCOMMAND(uncompactCells, while (cellStrsOffset < 1485) { // Keep consuming as much as possible H3Index cell = 0; while (cell == 0 && cellStrsOffset < 1485) { - // Grab 15 characters and then scan to see if it has an H3 index - // in it - char possibleIndex[16] = {0}; + // A valid H3 cell is exactly 15 hexadecomical characters. + // Determine if we have a match, otherwise increment bool badChar = false; for (int i = 0; i < 15 && !badChar; i++) { char c = cellStrs[i + cellStrsOffset]; if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) { - possibleIndex[i] = c; + // Do nothing } else { // Encountered a bad character, set the offset after // this character as the next to check cellStrsOffset += i + 1; badChar = true; } - possibleIndex[i] = cellStrs[i + cellStrsOffset]; } if (!badChar) { - if (sscanf(possibleIndex, "%" PRIx64, &cell) != 0) { + if (sscanf(cellStrs + cellStrsOffset, "%" PRIx64, &cell) != + 0) { // We can jump ahead 15 chars. The while loop check will // make sure we don't overwrite this cell with another // one cellStrsOffset += 15; lastGoodOffset = cellStrsOffset; + } else { + return E_FAILED; } - } else { - cell = 0; } } // If we still don't have a cell and we've reached the end, we reset diff --git a/tests/inputfiles/compact_test3.txt b/tests/inputfiles/compact_test3.txt index c920c3467..376a93988 100644 --- a/tests/inputfiles/compact_test3.txt +++ b/tests/inputfiles/compact_test3.txt @@ -1 +1 @@ -85283473fffffff85283447fffffff8528347bfffffff85283463fffffff85283477fffffff8528340ffffffff8528340bfffffff85283457fffffff85283443fffffff8528344ffffffff852836b7fffffff8528346bfffffff8528346ffffffff85283467fffffff8528342bfffffff8528343bfffffff85283407fffffff85283403fffffff8528341bfffffff +85283473fffffff,85283447fffffff,8528347bfffffff,85283463fffffff,85283477fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528346bfffffff,8528346ffffffff,85283467fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff diff --git a/tests/inputfiles/uncompact_test3.txt b/tests/inputfiles/uncompact_test3.txt index 8c3f4b5cf..0be180eed 100644 --- a/tests/inputfiles/uncompact_test3.txt +++ b/tests/inputfiles/uncompact_test3.txt @@ -1 +1 @@ -85283447fffffff8528340ffffffff8528340bfffffff85283457fffffff85283443fffffff8528344ffffffff852836b7fffffff8528342bfffffff8528343bfffffff85283407fffffff85283403fffffff8528341bfffffff8428347ffffffff +85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff From f823a1a9e03b83f4651e3351d1c57fa510354029 Mon Sep 17 00:00:00 2001 From: David Ellis Date: Mon, 15 Jul 2024 18:57:52 +0200 Subject: [PATCH 08/12] DRY the parsing logic --- src/apps/filters/h3.c | 246 ++++++++++++++++-------------------------- 1 file changed, 90 insertions(+), 156 deletions(-) diff --git a/src/apps/filters/h3.c b/src/apps/filters/h3.c index 2821a9c84..3d2cad4a7 100644 --- a/src/apps/filters/h3.c +++ b/src/apps/filters/h3.c @@ -929,120 +929,70 @@ SUBCOMMAND(childPosToCell, return E_SUCCESS; } -SUBCOMMAND(compactCells, - "Compacts the provided set of cells as best as possible. The set of " - "input cells must all share the same resolution. The compacted " - "cells will be printed one per line to stdout.") { - char filename[1024] = {0}; // More than Windows, lol - Arg filenameArg = { - .names = {"-f", "--file"}, - .scanFormat = "%1023c", - .valueName = "FILENAME", - .value = &filename, - .helpText = - "The file to load the cells from. Use -- to read from stdin."}; - char cellStrs[1501] = { - 0}; // Supports up to 100 cells at a time with zero padding - Arg cellStrsArg = {.names = {"-c", "--cells"}, - .scanFormat = "%1500c", - .valueName = "CELLS", - .value = &cellStrs, - .helpText = - "The cells to compact. Up to 100 cells if provided " - "as hexadecimals with zero padding."}; - Arg *args[] = {&compactCellsArg, &helpArg, &filenameArg, &cellStrsArg}; - PARSE_SUBCOMMAND(argc, argv, args); - if (!filenameArg.found && !cellStrsArg.found) { - fprintf(stderr, - "You must provide either a file to read from or a set of cells " - "to compact to use compactCells"); - exit(1); - } - // We use the same consumption logic for both kinds of input, and in fact - // use the cellStrs char array as out input buffer for the file path. The - // only difference between the two is when we reach the end of the buffer. - // If there's a non-null file pointer, we start from the last successful - // consumption from the buffer and move the data following it to the - // beginning of the buffer, then we read some of the file after that and - // slap it on after that and continue the consumption loops, while the other - // path just ends at that point. As we have no idea how many cells we're - // going to load, we allocate enough for 128 cells, but if that's not - // enough, we also have to re-allocate double the number of cells, copy them - // over, and free the old buffer of cells. Doing this manually since we want - // to keep the build process for H3 simple and C's stdlib is pretty bare. +H3Index *readCellsFromFile(FILE *fp, char *buffer, int *totalCells) { + // It's assumed the buffer is a character array of size 1501 to support up + // to 100 cells at a time. If the file pointer is a null pointer, we assume + // the buffer has all of the possible cells already stored in it and go from + // there. Otherwise we continue reading from the file until it's fully + // consumed. On an error, we de-allocate the output buffer and then return + // 0. It's the responsibility of the caller to free the returned buffer and + // the file pointer otherwise. The output array's filled length is set on + // the cellsOffset pointer so it can be used by the caller. H3Index *cells = calloc(128, sizeof(H3Index)); - FILE *fp = 0; - int cellStrsOffset = 0; - int cellsOffset = 0; int cellsLen = 128; - bool isStdin = false; - if (filenameArg.found) { - if (strcmp(filename, "--") == 0) { - fp = stdin; - isStdin = true; - } else { - fp = fopen(filename, "r"); - } - if (fp == 0) { - fprintf(stderr, "The specified file does not exist."); - exit(1); - } - // Do the initial population of data from the file - if (fread(cellStrs, 1, 1500, fp) == 0) { - fprintf(stderr, "The specified file is empty."); - exit(1); - } - } + int bufferOffset = 0; + int cellsOffset = 0; do { // Always start from the beginning of the buffer - cellStrsOffset = 0; + bufferOffset = 0; int lastGoodOffset = 0; - while (cellStrsOffset < 1485) { // Keep consuming as much as possible + while (bufferOffset < 1485) { // Keep consuming as much as possible H3Index cell = 0; - while (cell == 0 && cellStrsOffset < 1485) { + while (cell == 0 && bufferOffset < 1485) { // A valid H3 cell is exactly 15 hexadecomical characters. // Determine if we have a match, otherwise increment bool badChar = false; for (int i = 0; i < 15; i++) { - char c = cellStrs[i + cellStrsOffset]; + char c = buffer[i + bufferOffset]; if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) { // Do nothing } else { // Encountered a bad character, set the offset after // this character as the next to check - cellStrsOffset += i + 1; + bufferOffset += i + 1; badChar = true; break; } } if (!badChar) { - if (sscanf(cellStrs + cellStrsOffset, "%" PRIx64, &cell) != - 0) { + if (sscanf(buffer + bufferOffset, "%" PRIx64, &cell) != 0) { // We can jump ahead 15 chars. The while loop check will // make sure we don't overwrite this cell with another // one - cellStrsOffset += 15; - lastGoodOffset = cellStrsOffset; + bufferOffset += 15; + lastGoodOffset = bufferOffset; } else { // This *shouldn't* happen because it should have been // caught in the for loop above, but move to the next // character and try again if it somehow does - return E_FAILED; + free(cells); + return 0; } } } // If we still don't have a cell and we've reached the end, we reset // the offset and `continue` to trigger another read - if (cell == 0 && cellStrsOffset == 1500) { - cellStrsOffset = 0; + if (cell == 0 && bufferOffset == 1500) { + bufferOffset = 0; continue; } // Otherwise, we have a cell to shove into the cells array. cells[cellsOffset] = cell; - cellsOffset++; + cellsOffset += 1; // Potentially grow our array if (cellsOffset == cellsLen) { + printf("Growing the array?\n"); cellsLen *= 2; H3Index *newCells = calloc(cellsLen, sizeof(H3Index)); for (int i = 0; i < cellsOffset; i++) { @@ -1065,14 +1015,70 @@ SUBCOMMAND(compactCells, lastGoodOffset = 1485; } for (int i = 0; i < 1500 - lastGoodOffset; i++) { - cellStrs[i] = cellStrs[i + lastGoodOffset]; + buffer[i] = buffer[i + lastGoodOffset]; + } + bufferOffset = 1500 - lastGoodOffset; + } while (fp != 0 && + fread(buffer + bufferOffset, 1, 1500 - bufferOffset, fp) != 0); + *totalCells = cellsOffset; + return cells; +} + +SUBCOMMAND(compactCells, + "Compacts the provided set of cells as best as possible. The set of " + "input cells must all share the same resolution. The compacted " + "cells will be printed one per line to stdout.") { + char filename[1024] = {0}; // More than Windows, lol + Arg filenameArg = { + .names = {"-f", "--file"}, + .scanFormat = "%1023c", + .valueName = "FILENAME", + .value = &filename, + .helpText = + "The file to load the cells from. Use -- to read from stdin."}; + char cellStrs[1501] = {0}; // Up to 100 cells with zero padding + Arg cellStrsArg = {.names = {"-c", "--cells"}, + .scanFormat = "%1500c", + .valueName = "CELLS", + .value = &cellStrs, + .helpText = + "The cells to compact. Up to 100 cells if provided " + "as hexadecimals with zero padding."}; + Arg *args[] = {&compactCellsArg, &helpArg, &filenameArg, &cellStrsArg}; + PARSE_SUBCOMMAND(argc, argv, args); + if (!filenameArg.found && !cellStrsArg.found) { + fprintf(stderr, + "You must provide either a file to read from or a set of cells " + "to compact to use compactCells"); + exit(1); + } + FILE *fp = 0; + bool isStdin = false; + if (filenameArg.found) { + if (strcmp(filename, "--") == 0) { + fp = stdin; + isStdin = true; + } else { + fp = fopen(filename, "r"); } - cellStrsOffset = 1500 - lastGoodOffset; - } while (fp != 0 && fread(cellStrs + cellStrsOffset, 1, - 1500 - cellStrsOffset, fp) != 0); + if (fp == 0) { + fprintf(stderr, "The specified file does not exist."); + exit(1); + } + // Do the initial population of data from the file + if (fread(cellStrs, 1, 1500, fp) == 0) { + fprintf(stderr, "The specified file is empty."); + exit(1); + } + } + int cellsOffset = 0; + H3Index *cells = readCellsFromFile(fp, cellStrs, &cellsOffset); if (fp != 0 && !isStdin) { fclose(fp); } + if (cells == NULL) { + return E_FAILED; + } // Now that we have the cells in a buffer and the actual cell count in // cellsOffset, we can feed this to the H3 C API H3Index *compactedSet = calloc(cellsOffset, sizeof(H3Index)); @@ -1149,11 +1155,7 @@ SUBCOMMAND(uncompactCells, // enough, we also have to re-allocate double the number of cells, copy them // over, and free the old buffer of cells. Doing this manually since we want // to keep the build process for H3 simple and C's stdlib is pretty bare. - H3Index *cells = calloc(128, sizeof(H3Index)); FILE *fp = 0; - int cellStrsOffset = 0; - int cellsOffset = 0; - int cellsLen = 128; bool isStdin = false; if (filenameArg.found) { if (strcmp(filename, "--") == 0) { @@ -1172,82 +1174,14 @@ SUBCOMMAND(uncompactCells, exit(1); } } - do { - // Always start from the beginning of the buffer - cellStrsOffset = 0; - int lastGoodOffset = 0; - while (cellStrsOffset < 1485) { // Keep consuming as much as possible - H3Index cell = 0; - while (cell == 0 && cellStrsOffset < 1485) { - // A valid H3 cell is exactly 15 hexadecomical characters. - // Determine if we have a match, otherwise increment - bool badChar = false; - for (int i = 0; i < 15 && !badChar; i++) { - char c = cellStrs[i + cellStrsOffset]; - if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || - (c >= 'A' && c <= 'F')) { - // Do nothing - } else { - // Encountered a bad character, set the offset after - // this character as the next to check - cellStrsOffset += i + 1; - badChar = true; - } - } - if (!badChar) { - if (sscanf(cellStrs + cellStrsOffset, "%" PRIx64, &cell) != - 0) { - // We can jump ahead 15 chars. The while loop check will - // make sure we don't overwrite this cell with another - // one - cellStrsOffset += 15; - lastGoodOffset = cellStrsOffset; - } else { - return E_FAILED; - } - } - } - // If we still don't have a cell and we've reached the end, we reset - // the offset and `continue` to trigger another read - if (cell == 0 && cellStrsOffset == 1500) { - cellStrsOffset = 0; - continue; - } - // Otherwise, we have a cell to shove into the cells array. - cells[cellsOffset] = cell; - cellsOffset++; - // Potentially grow our array - if (cellsOffset == cellsLen) { - cellsLen *= 2; - H3Index *newCells = calloc(cellsLen, sizeof(H3Index)); - for (int i = 0; i < cellsOffset; i++) { - newCells[i] = cells[i]; - } - free(cells); - cells = newCells; - } - } - // In case there's a valid H3 index that was unfortunately split between - // buffer reads, we take from the lastGoodOffset and copy the rest to - // the beginning of the buffer so it can be re-assembled on the next - // file read. However, we also know that a valid H3 index is 15 - // characters long, so if the lastGoodOffset is 15 or more characters - // away from 1500, we only need to copy those final 14 bytes from the - // end, so if lastGoodOffset is 1485 or less, we force it to 1485 and - // then move the chunk as specified to the beginning and adjust the - // cellStrsOffset. - if (lastGoodOffset < 1485) { - lastGoodOffset = 1485; - } - for (int i = 0; i < 1500 - lastGoodOffset; i++) { - cellStrs[i] = cellStrs[i + lastGoodOffset]; - } - cellStrsOffset = 1500 - lastGoodOffset; - } while (fp != 0 && fread(cellStrs + cellStrsOffset, 1, - 1500 - cellStrsOffset, fp) != 0); + int cellsOffset = 0; + H3Index *cells = readCellsFromFile(fp, cellStrs, &cellsOffset); if (fp != 0 && !isStdin) { fclose(fp); } + if (cells == NULL) { + return E_FAILED; + } // Now that we have the cells in a buffer and the actual cell count in // cellsOffset, we can feed this to the H3 C API int64_t uncompactedSize = 0; From 8f9c35b51acf5cab6be4481dbd3bd3dc581566b2 Mon Sep 17 00:00:00 2001 From: David Ellis Date: Thu, 22 Aug 2024 17:48:34 -0500 Subject: [PATCH 09/12] Use sscanf and the %n 'formatter' that I wasn't aware of before --- src/apps/filters/h3.c | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/src/apps/filters/h3.c b/src/apps/filters/h3.c index 3d2cad4a7..4e65730f2 100644 --- a/src/apps/filters/h3.c +++ b/src/apps/filters/h3.c @@ -952,33 +952,16 @@ H3Index *readCellsFromFile(FILE *fp, char *buffer, int *totalCells) { // A valid H3 cell is exactly 15 hexadecomical characters. // Determine if we have a match, otherwise increment bool badChar = false; - for (int i = 0; i < 15; i++) { - char c = buffer[i + bufferOffset]; - if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || - (c >= 'A' && c <= 'F')) { - // Do nothing - } else { - // Encountered a bad character, set the offset after - // this character as the next to check - bufferOffset += i + 1; - badChar = true; - break; - } + int scanlen = 0; + sscanf(buffer + bufferOffset, "%" PRIx64 "%n", &cell, &scanlen); + if (scanlen != 15) { + badChar = true; } if (!badChar) { - if (sscanf(buffer + bufferOffset, "%" PRIx64, &cell) != 0) { - // We can jump ahead 15 chars. The while loop check will - // make sure we don't overwrite this cell with another - // one - bufferOffset += 15; - lastGoodOffset = bufferOffset; - } else { - // This *shouldn't* happen because it should have been - // caught in the for loop above, but move to the next - // character and try again if it somehow does - free(cells); - return 0; - } + bufferOffset += 16; + lastGoodOffset = bufferOffset; + } else { + bufferOffset += 1; } } // If we still don't have a cell and we've reached the end, we reset @@ -992,7 +975,6 @@ H3Index *readCellsFromFile(FILE *fp, char *buffer, int *totalCells) { cellsOffset += 1; // Potentially grow our array if (cellsOffset == cellsLen) { - printf("Growing the array?\n"); cellsLen *= 2; H3Index *newCells = calloc(cellsLen, sizeof(H3Index)); for (int i = 0; i < cellsOffset; i++) { From 0acfc3c0ee26006ac26fbf5d253725b4addb60a4 Mon Sep 17 00:00:00 2001 From: David Ellis Date: Thu, 22 Aug 2024 18:11:53 -0500 Subject: [PATCH 10/12] More simplification of the parsing logic --- src/apps/filters/h3.c | 52 ++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/src/apps/filters/h3.c b/src/apps/filters/h3.c index 4e65730f2..5ff262e8d 100644 --- a/src/apps/filters/h3.c +++ b/src/apps/filters/h3.c @@ -946,42 +946,38 @@ H3Index *readCellsFromFile(FILE *fp, char *buffer, int *totalCells) { // Always start from the beginning of the buffer bufferOffset = 0; int lastGoodOffset = 0; + H3Index cell = 0; while (bufferOffset < 1485) { // Keep consuming as much as possible - H3Index cell = 0; - while (cell == 0 && bufferOffset < 1485) { - // A valid H3 cell is exactly 15 hexadecomical characters. - // Determine if we have a match, otherwise increment - bool badChar = false; - int scanlen = 0; - sscanf(buffer + bufferOffset, "%" PRIx64 "%n", &cell, &scanlen); - if (scanlen != 15) { - badChar = true; - } - if (!badChar) { - bufferOffset += 16; - lastGoodOffset = bufferOffset; - } else { - bufferOffset += 1; - } + // A valid H3 cell is exactly 15 hexadecomical characters. + // Determine if we have a match, otherwise increment + int scanlen = 0; + sscanf(buffer + bufferOffset, "%" PRIx64 "%n", &cell, &scanlen); + if (scanlen != 15) { + cell = 0; + bufferOffset += 1; + } else { + bufferOffset += 16; + lastGoodOffset = bufferOffset; } // If we still don't have a cell and we've reached the end, we reset // the offset and `continue` to trigger another read if (cell == 0 && bufferOffset == 1500) { bufferOffset = 0; continue; - } - // Otherwise, we have a cell to shove into the cells array. - cells[cellsOffset] = cell; - cellsOffset += 1; - // Potentially grow our array - if (cellsOffset == cellsLen) { - cellsLen *= 2; - H3Index *newCells = calloc(cellsLen, sizeof(H3Index)); - for (int i = 0; i < cellsOffset; i++) { - newCells[i] = cells[i]; + } else if (cell != 0) { + // Otherwise, we have a cell to shove into the cells array. + cells[cellsOffset] = cell; + cellsOffset += 1; + // Potentially grow our array + if (cellsOffset == cellsLen) { + cellsLen *= 2; + H3Index *newCells = calloc(cellsLen, sizeof(H3Index)); + for (int i = 0; i < cellsOffset; i++) { + newCells[i] = cells[i]; + } + free(cells); + cells = newCells; } - free(cells); - cells = newCells; } } // In case there's a valid H3 index that was unfortunately split between From 1db646c551c672147c904b9d8bd1d372599548a6 Mon Sep 17 00:00:00 2001 From: David Ellis Date: Thu, 19 Sep 2024 17:15:45 -0500 Subject: [PATCH 11/12] Update src/apps/filters/h3.c Co-authored-by: Isaac Brodsky --- src/apps/filters/h3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/filters/h3.c b/src/apps/filters/h3.c index 5ff262e8d..11b631c7e 100644 --- a/src/apps/filters/h3.c +++ b/src/apps/filters/h3.c @@ -929,7 +929,7 @@ SUBCOMMAND(childPosToCell, return E_SUCCESS; } -H3Index *readCellsFromFile(FILE *fp, char *buffer, int *totalCells) { +H3Index *readCellsFromFile(FILE *fp, char *buffer, size_t *totalCells) { // It's assumed the buffer is a character array of size 1501 to support up // to 100 cells at a time. If the file pointer is a null pointer, we assume // the buffer has all of the possible cells already stored in it and go from From 3880fe2e91ad80c5f2177aa916c421b91d04b903 Mon Sep 17 00:00:00 2001 From: David Ellis Date: Thu, 19 Sep 2024 17:45:28 -0500 Subject: [PATCH 12/12] Update the cellsOffset type, too --- src/apps/filters/h3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/filters/h3.c b/src/apps/filters/h3.c index 11b631c7e..a21c10f67 100644 --- a/src/apps/filters/h3.c +++ b/src/apps/filters/h3.c @@ -1049,7 +1049,7 @@ SUBCOMMAND(compactCells, exit(1); } } - int cellsOffset = 0; + size_t cellsOffset = 0; H3Index *cells = readCellsFromFile(fp, cellStrs, &cellsOffset); if (fp != 0 && !isStdin) { fclose(fp); @@ -1152,7 +1152,7 @@ SUBCOMMAND(uncompactCells, exit(1); } } - int cellsOffset = 0; + size_t cellsOffset = 0; H3Index *cells = readCellsFromFile(fp, cellStrs, &cellsOffset); if (fp != 0 && !isStdin) { fclose(fp);