--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 306FC6DE1642\r
+ for <notmuch@notmuchmail.org>; Sat, 29 Aug 2015 07:56:56 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.342\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.342 tagged_above=-999 required=5 tests=[AWL=0.378,\r
+ RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 9QYBvn1_ocJo for <notmuch@notmuchmail.org>;\r
+ Sat, 29 Aug 2015 07:56:54 -0700 (PDT)\r
+Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com\r
+ [209.85.212.178])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 32FA66DE00CB\r
+ for <notmuch@notmuchmail.org>; Sat, 29 Aug 2015 07:56:48 -0700 (PDT)\r
+Received: by wicne3 with SMTP id ne3so9345992wic.0\r
+ for <notmuch@notmuchmail.org>; Sat, 29 Aug 2015 07:56:46 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+ :references:in-reply-to:references;\r
+ bh=pxnad6MtpP8ZeVFYco5HnK3jBxG6v2lyls84zu9uWEY=;\r
+ b=JrRjM1e/RPMwlOEPdOsgOBXLrfVqC6I0YNjd+oc9Ft9bI9pc8ltjoaqpODvliZtRXJ\r
+ aeDYuuH/tznMY2Yw+Y+tqZg/1BIazqg+w4ww5I9rBoNMWtzhuZRTg9kFsFFOfoFsd5ZI\r
+ e/j+PxFfYYrzPXj9d895Dwr2rKFLg0IoBwp5+nAwNu9t5/uyz6TwjXfvL+0pkYn1/eIv\r
+ mpMxcQF4mwe/w9B6wyakGLGCbZtt/xOdgv2vJvzws+LvzID98hz5tYa4aCeQyQlmFhWF\r
+ UnYzLmV6tmgKDDwO/JbZYGlSeSOqqMWwDOUFCs6W+sH7nWk5Cf17tCfOtNHm5xr+XojH\r
+ sRaA==\r
+X-Gm-Message-State:\r
+ ALoCoQmr1kS8RyUARePM0Lvr5mBNgyZCzKOdEATIztdcTDqi4Uwfe5R2tr+KFohTvJTXGwR0ayah\r
+X-Received: by 10.195.11.202 with SMTP id ek10mr17938463wjd.12.1440860206781; \r
+ Sat, 29 Aug 2015 07:56:46 -0700 (PDT)\r
+Received: from localhost (mobile-access-bcee4f-131.dhcp.inet.fi.\r
+ [188.238.79.131])\r
+ by smtp.gmail.com with ESMTPSA id gt10sm8918092wib.20.2015.08.29.07.56.45\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Sat, 29 Aug 2015 07:56:46 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC PATCH 4/5] cli: change the data structure for notmuch address\r
+ deduplication\r
+Date: Sat, 29 Aug 2015 17:56:35 +0300\r
+Message-Id:\r
+ <ffe5975fd070d3e8e22602b01ceb8bf0d7d47ae0.1440859765.git.jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <cover.1440859765.git.jani@nikula.org>\r
+References: <cover.1440859765.git.jani@nikula.org>\r
+In-Reply-To: <cover.1440859765.git.jani@nikula.org>\r
+References: <cover.1440859765.git.jani@nikula.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 29 Aug 2015 14:56:56 -0000\r
+\r
+Currently we key the address hash table with the case sensitive "name\r
+<address>". Switch to case insensitive keying with just address, and\r
+store the case sensitive name and address in linked lists. This will\r
+be helpful in adding support different deduplication schemes in the\r
+future. There will be a slight performance penalty for the current\r
+full case sensitive name + address deduplication, but this is simpler\r
+as a whole when other deduplication schemes are added, and I expect\r
+the schemes to be added to become more popular than the current\r
+default.\r
+---\r
+ notmuch-client.h | 1 +\r
+ notmuch-search.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++----------\r
+ 2 files changed, 76 insertions(+), 16 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index 882aa30563df..97d68d1158ac 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -48,6 +48,7 @@ typedef GMimeCryptoContext notmuch_crypto_context_t;\r
+ #include <dirent.h>\r
+ #include <errno.h>\r
+ #include <signal.h>\r
++#include <ctype.h>\r
+ \r
+ #include "talloc-extra.h"\r
+ \r
+diff --git a/notmuch-search.c b/notmuch-search.c\r
+index be8afcc0187b..60311393198d 100644\r
+--- a/notmuch-search.c\r
++++ b/notmuch-search.c\r
+@@ -258,30 +258,79 @@ static mailbox_t *new_mailbox (void *ctx, const char *name, const char *addr)\r
+ return mailbox;\r
+ }\r
+ \r
++static int\r
++strcase_equal (const void *a, const void *b)\r
++{\r
++ return strcasecmp (a, b) == 0;\r
++}\r
++\r
++static unsigned int\r
++strcase_hash (const void *ptr)\r
++{\r
++ const char *s = ptr;\r
++\r
++ /* This is the djb2 hash. */\r
++ unsigned int hash = 5381;\r
++ while (s && *s) {\r
++ hash = ((hash << 5) + hash) + tolower (*s);\r
++ s++;\r
++ }\r
++\r
++ return hash;\r
++}\r
++\r
++static int mailbox_compare (const void *v1, const void *v2)\r
++{\r
++ const mailbox_t *m1 = v1, *m2 = v2;\r
++ int v;\r
++\r
++ if (m1->name && m2->name)\r
++ v = strcmp (m1->name, m2->name);\r
++ else\r
++ v = !!m1->name - !!m2->name;\r
++\r
++ if (! v)\r
++ v = strcmp (m1->addr, m2->addr);\r
++\r
++ return v;\r
++}\r
++\r
+ /* Returns TRUE iff name and addr is duplicate. If not, stores the\r
+ * name/addr pair in order to detect subsequent duplicates. */\r
+ static notmuch_bool_t\r
+ is_duplicate (const search_context_t *ctx, const char *name, const char *addr)\r
+ {\r
+ char *key;\r
++ GList *list, *l;\r
+ mailbox_t *mailbox;\r
+ \r
+- key = talloc_asprintf (ctx->format, "%s <%s>", name, addr);\r
+- if (! key)\r
++ mailbox = new_mailbox (ctx->format, name, addr);\r
++ if (! mailbox)\r
+ return FALSE;\r
+ \r
+- mailbox = g_hash_table_lookup (ctx->addresses, key);\r
+- if (mailbox) {\r
+- mailbox->count++;\r
+- talloc_free (key);\r
+- return TRUE;\r
++ list = g_hash_table_lookup (ctx->addresses, addr);\r
++ if (list) {\r
++ l = g_list_find_custom (list, mailbox, mailbox_compare);\r
++ if (l) {\r
++ talloc_free (mailbox);\r
++ mailbox = l->data;\r
++ mailbox->count++;\r
++ return TRUE;\r
++ }\r
++\r
++ g_list_append (list, mailbox);\r
++ return FALSE;\r
+ }\r
+ \r
+- mailbox = new_mailbox (ctx->format, name, addr);\r
+- if (! mailbox)\r
++ key = talloc_strdup (ctx->format, addr);\r
++ if (! key)\r
+ return FALSE;\r
+ \r
+- g_hash_table_insert (ctx->addresses, key, mailbox);\r
++ list = g_list_append (NULL, mailbox);\r
++ if (! list)\r
++ return FALSE;\r
++\r
++ g_hash_table_insert (ctx->addresses, key, list);\r
+ \r
+ return FALSE;\r
+ }\r
+@@ -393,12 +442,21 @@ _talloc_free_for_g_hash (void *ptr)\r
+ }\r
+ \r
+ static void\r
+-print_hash_value (unused (gpointer key), gpointer value, gpointer user_data)\r
++_list_free_for_g_hash (void *ptr)\r
++{\r
++ g_list_free_full (ptr, _talloc_free_for_g_hash);\r
++}\r
++\r
++static void\r
++print_list_value (void *mailbox, void *context)\r
+ {\r
+- const mailbox_t *mailbox = value;\r
+- search_context_t *ctx = user_data;\r
++ print_mailbox (context, mailbox);\r
++}\r
+ \r
+- print_mailbox (ctx, mailbox);\r
++static void\r
++print_hash_value (unused (void *key), void *list, void *context)\r
++{\r
++ g_list_foreach (list, print_list_value, context);\r
+ }\r
+ \r
+ static int\r
+@@ -778,8 +836,9 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[])\r
+ argc - opt_index, argv + opt_index))\r
+ return EXIT_FAILURE;\r
+ \r
+- ctx->addresses = g_hash_table_new_full (g_str_hash, g_str_equal,\r
+- _talloc_free_for_g_hash, _talloc_free_for_g_hash);\r
++ ctx->addresses = g_hash_table_new_full (strcase_hash, strcase_equal,\r
++ _talloc_free_for_g_hash,\r
++ _list_free_for_g_hash);\r
+ \r
+ ret = do_search_messages (ctx);\r
+ \r
+-- \r
+2.1.4\r
+\r