unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Ruben Pollan <meskio@sindominio.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 1/5] Convert notmuch_message_list_t in a doubly linked
Date: Sat, 20 Mar 2010 11:23:21 +0100	[thread overview]
Message-ID: <1269080605-5617-2-git-send-email-meskio@sindominio.net> (raw)
In-Reply-To: <873a09jt2t.fsf@yoom.home.cworth.org>

The messages list now have pointers to previous nodes, so it is possible
to iterate backwards.
---
 lib/messages.c        |   18 +++++++++++++-----
 lib/notmuch-private.h |    3 ++-
 lib/thread.cc         |    4 ++--
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/lib/messages.c b/lib/messages.c
index db2b7a1..2a85774 100644
--- a/lib/messages.c
+++ b/lib/messages.c
@@ -37,20 +37,28 @@ _notmuch_message_list_create (const void *ctx)
 	return NULL;
 
     list->head = NULL;
-    list->tail = &list->head;
+    list->tail = NULL;
 
     return list;
 }
 
-/* Append 'node' (which can of course point to an arbitrarily long
- * list of nodes) to the end of 'list'.
+/* Append 'node' to the end of 'list'.
  */
 void
 _notmuch_message_list_append (notmuch_message_list_t *list,
 			      notmuch_message_node_t *node)
 {
-    *(list->tail) = node;
-    list->tail = &node->next;
+    node->prev = list->tail;
+    if (list->head)
+    {
+        list->tail->next = node;
+    }
+    else
+    {
+        list->head = node;
+        list->tail = node;
+    }
+    list->tail = node;
 }
 
 /* Allocate a new node for 'message' and append it to the end of
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index d52d84d..3b3f0eb 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -349,11 +349,12 @@ notmuch_message_file_get_header (notmuch_message_file_t *message,
 typedef struct _notmuch_message_node {
     notmuch_message_t *message;
     struct _notmuch_message_node *next;
+    struct _notmuch_message_node *prev;
 } notmuch_message_node_t;
 
 typedef struct _notmuch_message_list {
     notmuch_message_node_t *head;
-    notmuch_message_node_t **tail;
+    notmuch_message_node_t *tail;
 } notmuch_message_list_t;
 
 /* There's a rumor that there's an alternate struct _notmuch_messages
diff --git a/lib/thread.cc b/lib/thread.cc
index ec80f85..05d2c39 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -169,8 +169,8 @@ _resolve_thread_relationships (unused (notmuch_thread_t *thread))
 					  (void **) &parent))
 	{
 	    *prev = node->next;
-	    if (thread->message_list->tail == &node->next)
-		thread->message_list->tail = prev;
+	    if (thread->message_list->tail == node)
+		thread->message_list->tail = node->prev;
 	    node->next = NULL;
 	    _notmuch_message_add_reply (parent, node);
 	} else {
-- 
1.7.0

  parent reply	other threads:[~2010-03-20 10:21 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-26 20:23 notmuch_threads_back and notmuch_messages_back Ruben Pollan
2009-11-28  3:57 ` Carl Worth
2009-12-06 17:34   ` Ruben Pollan
2009-12-07 17:23     ` Carl Worth
2009-12-08  9:41 ` regress option to messages iterator meskio
2009-12-08  9:41   ` [PATCH 1/2] Convert notmuch_message_list_t in a doubly linked meskio
2009-12-08  9:41     ` [PATCH 2/2] Added regress option to messages iterator meskio
2009-12-08  9:57   ` ruben pollan
2009-12-09 12:45 ` [PATCH] Added regress option to threads iterator Ruben Pollan
2009-12-09 13:10 ` [PATCH] Added regress option to tags iterator Ruben Pollan
2009-12-09 13:24   ` Ruben Pollan
2009-12-09 20:08     ` Carl Worth
2009-12-09 21:21       ` Mark Anderson
2009-12-09 21:37         ` Carl Worth
2009-12-09 22:05         ` Ruben Pollan
2009-12-09 22:01       ` Ruben Pollan
2009-12-22  1:23       ` Carl Worth
2009-12-22  3:16         ` Carl Worth
2010-01-05 15:33           ` Ruben Pollan
2010-01-05 19:39             ` Carl Worth
2010-01-06  9:08               ` Ruben Pollan
2010-03-09 17:36           ` Carl Worth
2010-03-11 14:28             ` Ruben Pollan
2010-03-20 10:23             ` reverse iterators Ruben Pollan
2010-03-21 20:07               ` Sebastian Spaeth
2010-03-22 10:18                 ` Ruben Pollan
2010-03-21 21:32               ` [PATCH] sending again patches 3 & 4 Ruben Pollan
2010-03-21 21:32               ` [PATCH 1/2] Move the logic of threads iterator out of 'valid' Ruben Pollan
2010-03-21 21:32               ` [PATCH 2/2] Added backwards iterator to threads Ruben Pollan
2010-03-20 10:23             ` Ruben Pollan [this message]
2010-03-20 10:23             ` [PATCH 2/5] Added backwards iterator to messages Ruben Pollan
2010-03-20 10:23             ` [PATCH 3/5] Move the logic of threads iterator out of 'valid' Ruben Pollan
2010-03-20 10:23             ` [PATCH 4/5] Added backwards iterator to threads Ruben Pollan
2010-03-20 10:23             ` [PATCH 5/5] Added backwards iterator to tags Ruben Pollan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1269080605-5617-2-git-send-email-meskio@sindominio.net \
    --to=meskio@sindominio.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).