From ffebdbe367182c32dd4ac9cee33ac8613b7c45ed Mon Sep 17 00:00:00 2001 From: Jeff Garrett Date: Fri, 25 Jan 2008 03:58:11 -0600 Subject: Change function signature of tiger_get_states() Return a list instead of hash table --- src/import_tiger.c | 14 +++++++++----- src/tiger.c | 14 ++++++-------- src/tiger.h | 3 ++- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/import_tiger.c b/src/import_tiger.c index 408206d..e4bb992 100644 --- a/src/import_tiger.c +++ b/src/import_tiger.c @@ -1270,12 +1270,16 @@ static gboolean import_tiger_from_directory(const gchar* pszDirectoryPath, gint // did we read all files? if(bSuccess) { gint nStateID = (nTigerSetNumber / 1000); // int division (eg. turn 25017 into 25) - GHashTable *states = tiger_get_states(); - struct tiger_state *st; - if ((st = g_hash_table_lookup(states, &nStateID))) + GSList *states; + for (states = tiger_get_states(); states; states = g_slist_next(states)) { - gint nCountryID = 1; // USA is #1 *gag* - db_insert_state(st->name, st->abbrev, nCountryID, &g_nStateID); + struct tiger_state *st = g_slist_nth_data(states, 0); + + if (nStateID == atoi(st->fips_code)) + { + gint nCountryID = 1; // USA is #1 *gag* + db_insert_state(st->name, st->abbrev, nCountryID, &g_nStateID); + } } g_assert(G_N_ELEMENTS(apszExtensions) == 7); diff --git a/src/tiger.c b/src/tiger.c index a593e61..019e93d 100644 --- a/src/tiger.c +++ b/src/tiger.c @@ -26,10 +26,10 @@ #define TIGER_STATES_FILE DATADIR "/tiger-states.txt" -static GHashTable *state_list; +static GSList *state_list; -GHashTable *tiger_get_states() +GSList *tiger_get_states() { gchar *contents, **lines, **iter, **tokens; struct tiger_state *st; @@ -44,8 +44,6 @@ GHashTable *tiger_get_states() return NULL; } - state_list = g_hash_table_new(g_int_hash, g_int_equal); - /* The data file of TIGER states is tab-delimited with fields * for the state FIPS code, the abbreviation, and the state name. */ @@ -56,11 +54,11 @@ GHashTable *tiger_get_states() fips_code = g_new0(gint, 1); tokens = g_strsplit(*iter, "\t", 0); - *fips_code = g_ascii_strtoull(tokens[0], NULL, 10); - st->abbrev = g_strdup(tokens[1]); - st->name = g_strdup(tokens[2]); + st->fips_code = g_strdup(tokens[0]); + st->abbrev = g_strdup(tokens[1]); + st->name = g_strdup(tokens[2]); - g_hash_table_insert(state_list, fips_code, st); + state_list = g_slist_append(state_list, st); g_strfreev(tokens); } diff --git a/src/tiger.h b/src/tiger.h index 969021e..79e5f8b 100644 --- a/src/tiger.h +++ b/src/tiger.h @@ -26,11 +26,12 @@ struct tiger_state { + gchar *fips_code; gchar *name; gchar *abbrev; }; -GHashTable *tiger_get_states(); +GSList *tiger_get_states(); #endif -- cgit v1.2.3