Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 4C763431FBD for ; Thu, 2 Feb 2012 15:08:06 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FfU92uywqYy3 for ; Thu, 2 Feb 2012 15:08:05 -0800 (PST) Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 0EBC3431FAF for ; Thu, 2 Feb 2012 15:08:04 -0800 (PST) Received: by lahd3 with SMTP id d3so1700581lah.26 for ; Thu, 02 Feb 2012 15:08:03 -0800 (PST) Received: by 10.152.109.161 with SMTP id ht1mr2483217lab.33.1328224083512; Thu, 02 Feb 2012 15:08:03 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi. [84.248.80.253]) by mx.google.com with ESMTPS id k13sm3156059lbu.16.2012.02.02.15.08.00 (version=SSLv3 cipher=OTHER); Thu, 02 Feb 2012 15:08:02 -0800 (PST) From: Jani Nikula To: Mark Walters , notmuch@notmuchmail.org, amdragon@MIT.EDU Subject: Re: [PATCH v4 07/11] lib: added interface notmuch_thread_get_flag_messages In-Reply-To: <871uqcswfb.fsf@qmul.ac.uk> References: <874nv9rv79.fsf@qmul.ac.uk> <1328204619-25046-7-git-send-email-markwalters1009@gmail.com> <87k444yk6i.fsf@nikula.org> <871uqcswfb.fsf@qmul.ac.uk> User-Agent: Notmuch/0.11+139~g4340989 (http://notmuchmail.org) Emacs/23.3.1 (i686-pc-linux-gnu) Date: Fri, 03 Feb 2012 01:07:59 +0200 Message-ID: <87d39wygts.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Feb 2012 23:08:06 -0000 On Thu, 02 Feb 2012 22:27:36 +0000, Mark Walters wrote: > On Thu, 02 Feb 2012 23:55:33 +0200, Jani Nikula wrote: > > > > Hi Mark - > > > > This is my first look at any version of the series; apologies if I'm > > clueless about some details... Please find some comments below. > > > > BR, > > Jani. > > > > > > On Thu, 2 Feb 2012 17:43:35 +0000, Mark Walters wrote: > > > The function is > > > notmuch_thread_get_flag_messages > > > (notmuch_thread_t *thread, unsigned int flag_mask, unsigned int flags) > > > > > > and returns the number of messages with the specified flags on flag_mask. > > > > Is the purpose of this function to get the count of messages that have > > certain flags set, certain flags not set, and certain flags don't-care? > > Yes: I was trying to follow Austin's suggestion from > id:"20120124025331.GZ16740@mit.edu" (although stupidly I didn't > follow his suggestion of a function name). > > > At the very least, I think the documentation of the function should be > > greatly improved. > > > > I think the name of the function should be notmuch_thread_count_messages > > which is like notmuch_query_count_messages, but for messages in threads > > (and with some extra restrictions). > > Yes I like your name; before I change it do you (and others) prefer it > to Austin's suggestion of notmuch_thread_count_flags. Or we could even > be more verbose with something like > notmuch_thread_count_messages_with_flags I'd like to make it clear that it's about message count. Not about getting flags, not about flag counts. _with_flags is a matter of taste, no strong opinions there. > > > > /* Message flags */ > > > typedef enum _notmuch_message_flag { > > > - NOTMUCH_MESSAGE_FLAG_MATCH, > > > - NOTMUCH_MESSAGE_FLAG_EXCLUDED > > > + NOTMUCH_MESSAGE_FLAG_MATCH = (1<<0), > > > + NOTMUCH_MESSAGE_FLAG_EXCLUDED = (1<<1), > > > + NOTMUCH_MESSAGE_FLAG_MAX = (1<<2) > > > > How are these used by the current lib users at the moment? How will they > > break with this change? > > The only existing flag is NOTMUCH_MESSAGE_FLAG_MATCH: that is currently > zero but in the current code that is the bit offset of the flag; in my > version it is the actual bit for the flag (otherwise I think flag masks > end up very ugly). I believe all callers use notmuch_message_set_flag > and notmuch_message_get_flag so they should not notice the difference. > > > Please align the assignments. > > Will do. > > > > @@ -457,8 +452,8 @@ _notmuch_thread_create (void *ctx, > > > thread->message_hash = g_hash_table_new_full (g_str_hash, g_str_equal, > > > free, NULL); > > > > > > - thread->total_messages = 0; > > > - thread->matched_messages = 0; > > > + for (i = 0; i < NOTMUCH_MESSAGE_FLAG_MAX; i++) > > > + thread->flag_count_messages[i] = 0; > > > > memset (thread->flag_count_messages, 0, sizeof(thread->flag_count_messages)); > > > Will do > > > > thread->oldest = 0; > > > thread->newest = 0; > > > > > > @@ -473,6 +468,7 @@ _notmuch_thread_create (void *ctx, > > > notmuch_messages_move_to_next (messages)) > > > { > > > unsigned int doc_id; > > > + unsigned int message_flags; > > > > > > message = notmuch_messages_get (messages); > > > doc_id = _notmuch_message_get_doc_id (message); > > > @@ -485,6 +481,10 @@ _notmuch_thread_create (void *ctx, > > > _notmuch_doc_id_set_remove (match_set, doc_id); > > > _thread_add_matched_message (thread, message, sort); > > > } > > > + message_flags = > > > + notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) | > > > + notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED); > > > + thread->flag_count_messages[message_flags]++; > > > > The first impression of using a set of flags as index is that there's a > > bug. But this is to keep count of messages with certain flag sets rather > > than total for each flag, right? I think this needs more comments, more > > documentation. Already naming the field flag_set_message_counts or > > similar would help greatly. > > I will try and document it better: on first reading I parsed your name > as flag set (as verb) message counts whereas I assume you mean "flag > set" as a noun! I will see if I can come up with something though. Yes, as a noun! :) > > > > _notmuch_message_close (message); > > > } > > > @@ -511,15 +511,28 @@ notmuch_thread_get_thread_id (notmuch_thread_t *thread) > > > } > > > > > > int > > > +notmuch_thread_get_flag_messages (notmuch_thread_t *thread, unsigned int flag_mask, unsigned int flags) > > > +{ > > > + unsigned int i; > > > + int count = 0; > > > + for (i = 0; i < NOTMUCH_MESSAGE_FLAG_MAX; i++) > > > > ARRAY_SIZE (thread->flag_count_messages) > > ok > > > > > > + if ((i & flag_mask) == (flags & flag_mask)) > > > + count += thread->flag_count_messages[i]; > > > + return count; > > > +} > > > > I wonder if the same could be accomplished by using two flag mask > > parameters, include_flag_mask and exclude_flag_mask. I'm thinking of the > > usage, would it be easier to use: > > > > notmuch_query_count_messages (thread, NOTMUCH_MESSAGE_FLAG_MATCH, NOTMUCH_MESSAGE_FLAG_EXCLUDED); > > > > to get number of messages that have MATCH but not EXCLUDED? 0 as > > include_flag_mask could still be special for "all", and you could use: > > > > notmuch_query_count_messages (thread, 0, NOTMUCH_MESSAGE_FLAG_EXCLUDED); > > > > Note the name change according to my earlier suggestion. It might be > > wise to not export the function before the API is chrystal clear if > > there is no pressing need to do so. > > (I assume you mean notmuch_thread_count_messages.) Doh! Yes. > Can I just check this > would return the number of messages which have all the flags in > include_flag_mask and none of the flags in exclude_flag_mask? Yes, but only if it makes sense to you! :) > > I completely agree about leaving it until we have the API well worked > out. I wrote it in response to Austin's suggestion and then it looked > like it would useful in my attempts to remove the > notmuch_query_set_omit_excluded_messages API. However, those attempts > failed so it doesn't have any users yet. > > Best wishes > > Mark