mirror of https://github.com/djcb/mu.git
* threader/container: support reverse sorting for threaded output, some cleanups
This commit is contained in:
parent
f3264affba
commit
c8f869e041
|
@ -300,7 +300,7 @@ mu_container_from_list (GSList *lst)
|
|||
|
||||
struct _SortFuncData {
|
||||
MuMsgFieldId mfid;
|
||||
gboolean invert;
|
||||
gboolean revert;
|
||||
gpointer user_data;
|
||||
};
|
||||
typedef struct _SortFuncData SortFuncData;
|
||||
|
@ -323,7 +323,7 @@ sort_func_wrapper (MuContainer *a, MuContainer *b, SortFuncData *data)
|
|||
else if (!b1->msg)
|
||||
return -1;
|
||||
|
||||
if (data->invert)
|
||||
if (data->revert)
|
||||
return mu_msg_cmp (b1->msg, a1->msg, data->mfid);
|
||||
else
|
||||
return mu_msg_cmp (a1->msg, b1->msg, data->mfid);
|
||||
|
@ -355,14 +355,14 @@ mu_container_sort_real (MuContainer *c, SortFuncData *sfdata)
|
|||
|
||||
|
||||
MuContainer*
|
||||
mu_container_sort (MuContainer *c, MuMsgFieldId mfid, gpointer user_data,
|
||||
gboolean invert)
|
||||
mu_container_sort (MuContainer *c, MuMsgFieldId mfid, gboolean revert,
|
||||
gpointer user_data)
|
||||
{
|
||||
|
||||
SortFuncData sfdata;
|
||||
|
||||
sfdata.mfid = mfid;
|
||||
sfdata.invert = invert;
|
||||
sfdata.revert = revert;
|
||||
sfdata.user_data = user_data;
|
||||
|
||||
g_return_val_if_fail (c, NULL);
|
||||
|
|
|
@ -34,7 +34,7 @@ typedef guint8 MuContainerFlag;
|
|||
|
||||
/*
|
||||
* MuContainer data structure, as seen in JWZs document:
|
||||
* http://www.jwz.org/doc/threading.html
|
||||
* http://www.jwz.org/doc/threading.html
|
||||
*/
|
||||
struct _MuContainer {
|
||||
struct _MuContainer *parent, *child, *next;
|
||||
|
@ -48,11 +48,11 @@ typedef struct _MuContainer MuContainer;
|
|||
|
||||
/**
|
||||
* create a new Container object
|
||||
*
|
||||
*
|
||||
* @param msg a MuMsg, or NULL; when it's NULL, docid should be 0
|
||||
* @param docid a Xapian docid, or 0
|
||||
* @param msgid a message id, or NULL
|
||||
*
|
||||
*
|
||||
* @return a new Container instance, or NULL in case of error; free
|
||||
* with mu_container_destroy
|
||||
*/
|
||||
|
@ -61,7 +61,7 @@ MuContainer* mu_container_new (MuMsg *msg, guint docid, const char* msgid);
|
|||
|
||||
/**
|
||||
* free a Container object
|
||||
*
|
||||
*
|
||||
* @param c a Container object, or NULL
|
||||
*/
|
||||
void mu_container_destroy (MuContainer *c);
|
||||
|
@ -71,10 +71,10 @@ void mu_container_destroy (MuContainer *c);
|
|||
/**
|
||||
* append new child(ren) to this container; the child(ren) container's
|
||||
* parent pointer will point to this one
|
||||
*
|
||||
*
|
||||
* @param c a Container instance
|
||||
* @param child a child
|
||||
*
|
||||
*
|
||||
* @return the Container instance with a child added
|
||||
*/
|
||||
MuContainer* mu_container_append_children (MuContainer *c, MuContainer *child);
|
||||
|
@ -82,20 +82,20 @@ MuContainer* mu_container_append_children (MuContainer *c, MuContainer *child);
|
|||
/**
|
||||
* append a new sibling to this (list of) containers; all the siblings
|
||||
* will get the same parent that @c has
|
||||
*
|
||||
*
|
||||
* @param c a container instance
|
||||
* @param sibling a sibling
|
||||
*
|
||||
* @param sibling a sibling
|
||||
*
|
||||
* @return the container (list) with the sibling(s) appended
|
||||
*/
|
||||
MuContainer* mu_container_append_siblings (MuContainer *c, MuContainer *sibling);
|
||||
|
||||
/**
|
||||
* remove a _single_ child container from a container
|
||||
*
|
||||
*
|
||||
* @param c a container instance
|
||||
* @param child the child container to remove
|
||||
*
|
||||
*
|
||||
* @return the container with the child removed; if the container did
|
||||
* have this child, nothing changes
|
||||
*/
|
||||
|
@ -103,10 +103,10 @@ MuContainer* mu_container_remove_child (MuContainer *c, MuContainer *child);
|
|||
|
||||
/**
|
||||
* remove a _single_ sibling container from a container
|
||||
*
|
||||
*
|
||||
* @param c a container instance
|
||||
* @param sibling the sibling container to remove
|
||||
*
|
||||
*
|
||||
* @return the container with the sibling removed; if the container did
|
||||
* have this sibling, nothing changes
|
||||
*/
|
||||
|
@ -115,10 +115,10 @@ MuContainer* mu_container_remove_sibling (MuContainer *c, MuContainer *sibling);
|
|||
|
||||
/**
|
||||
* promote child's children to be parent's children and remove child
|
||||
*
|
||||
*
|
||||
* @param parent a container instance
|
||||
* @param child a child of this container
|
||||
*
|
||||
*
|
||||
* @return the new container with it's children's children promoted
|
||||
*/
|
||||
MuContainer* mu_container_splice_children (MuContainer *parent,
|
||||
|
@ -130,12 +130,12 @@ typedef gboolean (*MuContainerForeachFunc) (MuContainer*, gpointer);
|
|||
* execute some function on all siblings an children of some container
|
||||
* (recursively) until all children have been visited or the callback
|
||||
* function returns FALSE
|
||||
*
|
||||
*
|
||||
* @param c a container
|
||||
* @param func a function to call for each container
|
||||
* @param user_data a pointer to pass to the callback function
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
gboolean mu_container_foreach (MuContainer *c,
|
||||
MuContainerForeachFunc func,
|
||||
|
@ -144,10 +144,10 @@ gboolean mu_container_foreach (MuContainer *c,
|
|||
/**
|
||||
* check wither container needle is a child or sibling (recursively)
|
||||
* of container haystack
|
||||
*
|
||||
*
|
||||
* @param haystack a container
|
||||
* @param needle a container
|
||||
*
|
||||
*
|
||||
* @return TRUE if needle is reachable from haystack, FALSE otherwise
|
||||
*/
|
||||
gboolean mu_container_reachable (MuContainer *haystack, MuContainer *needle);
|
||||
|
@ -155,8 +155,8 @@ gboolean mu_container_reachable (MuContainer *haystack, MuContainer *needle);
|
|||
|
||||
/**
|
||||
* dump the container to stdout (for debugging)
|
||||
*
|
||||
* @param c a container
|
||||
*
|
||||
* @param c a container
|
||||
* @param recursive whether to include siblings, children
|
||||
*/
|
||||
void mu_container_dump (MuContainer *c, gboolean recursive);
|
||||
|
@ -169,26 +169,26 @@ typedef int (*MuContainerCmpFunc) (MuContainer *c1, MuContainer *c2,
|
|||
* sort the tree of MuContainers, recursively; ie. each of the list of
|
||||
* siblings (children) will be sorted according to @func; if the
|
||||
* container is empty, the first non-empty 'leftmost' child is used.
|
||||
*
|
||||
*
|
||||
* @param c a container
|
||||
* @param mfid the field to sort by
|
||||
* @param revert if TRUE, revert the sorting order *
|
||||
* @param user_data a user pointer to pass to the sorting function
|
||||
* @param invert if TRUE, invert the sorting order
|
||||
*
|
||||
*
|
||||
* @return a sorted container
|
||||
*/
|
||||
MuContainer* mu_container_sort (MuContainer *c, MuMsgFieldId mfid,
|
||||
gpointer user_data, gboolean invert);
|
||||
MuContainer* mu_container_sort (MuContainer *c, MuMsgFieldId mfid, gboolean revert,
|
||||
gpointer user_data);
|
||||
|
||||
|
||||
/**
|
||||
* create a hashtable with maps document-ids to information about them,
|
||||
* ie. Xapian docid => MuMsgIterThreadInfo
|
||||
*
|
||||
*
|
||||
* @param root_set the containers @param matchnum the number of
|
||||
* matches in the list (this is needed to determine the shortest
|
||||
* possible collation keys ('threadpaths') for the messages
|
||||
*
|
||||
*
|
||||
* @return a hash; free with g_hash_table_destroy
|
||||
*/
|
||||
GHashTable* mu_container_thread_info_hash_new (MuContainer *root_set,
|
||||
|
|
|
@ -58,7 +58,8 @@ GHashTable* create_doc_id_thread_path_hash (MuContainer *root, size_t match_num)
|
|||
/* msg threading algorithm, based on JWZ's algorithm,
|
||||
* http://www.jwz.org/doc/threading.html */
|
||||
GHashTable*
|
||||
mu_threader_calculate (MuMsgIter *iter, size_t matchnum, MuMsgFieldId sortfield)
|
||||
mu_threader_calculate (MuMsgIter *iter, size_t matchnum,
|
||||
MuMsgFieldId sortfield, gboolean revert)
|
||||
{
|
||||
GHashTable *id_table, *thread_ids;
|
||||
MuContainer *root_set;
|
||||
|
@ -81,8 +82,8 @@ mu_threader_calculate (MuMsgIter *iter, size_t matchnum, MuMsgFieldId sortfield)
|
|||
|
||||
/* sort root set */
|
||||
if (sortfield != MU_MSG_FIELD_ID_NONE)
|
||||
root_set = mu_container_sort (root_set, sortfield,
|
||||
NULL, FALSE);
|
||||
root_set = mu_container_sort (root_set, sortfield, revert,
|
||||
NULL);
|
||||
|
||||
/* step 5: group root set by subject */
|
||||
/* group_root_set_by_subject (root_set); */
|
||||
|
|
|
@ -43,11 +43,12 @@ G_BEGIN_DECLS
|
|||
* @param matches the number of matches in the set *
|
||||
* @param sortfield the field to sort results by, or
|
||||
* MU_MSG_FIELD_ID_NONE if no sorting should be performed
|
||||
*
|
||||
* @param revert if TRUE, if revert the sorting order
|
||||
*
|
||||
* @return a hashtable; free with g_hash_table_destroy when done with it
|
||||
*/
|
||||
*/
|
||||
GHashTable *mu_threader_calculate (MuMsgIter *iter, size_t matches,
|
||||
MuMsgFieldId sortfield);
|
||||
MuMsgFieldId sortfield, gboolean revert);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
|
Loading…
Reference in New Issue