lib: convert threader/container to c++
Did change the code much, but it's now compiled as c++
This commit is contained in:
@ -63,8 +63,8 @@ libmu_la_SOURCES= \
|
|||||||
mu-bookmarks.h \
|
mu-bookmarks.h \
|
||||||
mu-contacts.cc \
|
mu-contacts.cc \
|
||||||
mu-contacts.hh \
|
mu-contacts.hh \
|
||||||
mu-container.c \
|
mu-container.cc \
|
||||||
mu-container.h \
|
mu-container.hh \
|
||||||
mu-data.hh \
|
mu-data.hh \
|
||||||
mu-flags.c \
|
mu-flags.c \
|
||||||
mu-flags.h \
|
mu-flags.h \
|
||||||
@ -100,8 +100,8 @@ libmu_la_SOURCES= \
|
|||||||
mu-server.hh \
|
mu-server.hh \
|
||||||
mu-store.cc \
|
mu-store.cc \
|
||||||
mu-store.hh \
|
mu-store.hh \
|
||||||
mu-threader.c \
|
mu-threader.cc \
|
||||||
mu-threader.h \
|
mu-threader.hh \
|
||||||
mu-tokenizer.cc \
|
mu-tokenizer.cc \
|
||||||
mu-tokenizer.hh \
|
mu-tokenizer.hh \
|
||||||
mu-tree.hh \
|
mu-tree.hh \
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright (C) 2011-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2011-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify it
|
** This program is free software; you can redistribute it and/or modify it
|
||||||
** under the terms of the GNU General Public License as published by the
|
** under the terms of the GNU General Public License as published by the
|
||||||
@ -16,11 +16,11 @@
|
|||||||
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
#include "mu-container.hh"
|
||||||
|
|
||||||
#include <string.h> /* for memset */
|
#include <string.h> /* for memset */
|
||||||
#include <math.h> /* for log, ceil */
|
#include <math.h> /* for log, ceil */
|
||||||
|
|
||||||
#include "mu-container.h"
|
|
||||||
#include "mu-msg.h"
|
#include "mu-msg.h"
|
||||||
#include "mu-msg-iter.h"
|
#include "mu-msg-iter.h"
|
||||||
|
|
||||||
@ -323,7 +323,7 @@ mu_container_from_list (GSList *lst)
|
|||||||
if (!lst)
|
if (!lst)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
tail = list_last_data (lst);
|
tail = (MuContainer*)list_last_data (lst);
|
||||||
for (c = cur = (MuContainer*)lst->data; cur; lst = g_slist_next(lst)) {
|
for (c = cur = (MuContainer*)lst->data; cur; lst = g_slist_next(lst)) {
|
||||||
cur->next = lst ? (MuContainer*)lst->data : NULL;
|
cur->next = lst ? (MuContainer*)lst->data : NULL;
|
||||||
cur->last = tail;
|
cur->last = tail;
|
||||||
@ -545,7 +545,11 @@ path_to_string (Path *p, const char* frmt)
|
|||||||
for (u = 0, str = NULL; p->_data[u] != 0; ++u) {
|
for (u = 0, str = NULL; p->_data[u] != 0; ++u) {
|
||||||
|
|
||||||
char segm[16];
|
char segm[16];
|
||||||
|
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||||
g_snprintf (segm, sizeof(segm), frmt, p->_data[u] - 1);
|
g_snprintf (segm, sizeof(segm), frmt, p->_data[u] - 1);
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
if (!str)
|
if (!str)
|
||||||
str = g_strdup (segm);
|
str = g_strdup (segm);
|
||||||
@ -17,50 +17,47 @@
|
|||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __MU_CONTAINER_H__
|
#ifndef MU_CONTAINER_HH__
|
||||||
#define __MU_CONTAINER_H__
|
#define MU_CONTAINER_HH__
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <mu-msg.h>
|
#include <mu-msg.h>
|
||||||
|
#include <utils/mu-utils.hh>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
enum MuContainerFlag {
|
||||||
|
|
||||||
enum _MuContainerFlag {
|
|
||||||
MU_CONTAINER_FLAG_NONE = 0,
|
MU_CONTAINER_FLAG_NONE = 0,
|
||||||
MU_CONTAINER_FLAG_DELETE = 1 << 0,
|
MU_CONTAINER_FLAG_DELETE = 1 << 0,
|
||||||
MU_CONTAINER_FLAG_SPLICE = 1 << 1,
|
MU_CONTAINER_FLAG_SPLICE = 1 << 1,
|
||||||
MU_CONTAINER_FLAG_DUP = 1 << 2
|
MU_CONTAINER_FLAG_DUP = 1 << 2
|
||||||
};
|
};
|
||||||
typedef enum _MuContainerFlag MuContainerFlag;
|
MU_ENABLE_BITOPS(MuContainerFlag);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MuContainer data structure, as seen in JWZs document:
|
* 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 {
|
||||||
struct _MuContainer *parent, *child, *next;
|
struct MuContainer *parent, *child, *next;
|
||||||
|
|
||||||
/* note: we cache the last of the string of next->next->...
|
/* note: we cache the last of the string of next->next->...
|
||||||
* `mu_container_append_siblings' shows up high in the
|
* `mu_container_append_siblings' shows up high in the
|
||||||
* profiles since it needs to walk to the end, and this give
|
* profiles since it needs to walk to the end, and this give
|
||||||
* O(n*n) behavior.
|
* O(n*n) behavior.
|
||||||
* */
|
* */
|
||||||
struct _MuContainer *last;
|
struct MuContainer *last;
|
||||||
|
|
||||||
/* Node in the subtree rooted at this node which comes first
|
/* Node in the subtree rooted at this node which comes first
|
||||||
* in the descending sort order, e.g. the latest message if
|
* in the descending sort order, e.g. the latest message if
|
||||||
* sorting by date. We compare the leaders when ordering
|
* sorting by date. We compare the leaders when ordering
|
||||||
* subtrees. */
|
* subtrees. */
|
||||||
struct _MuContainer *leader;
|
struct MuContainer *leader;
|
||||||
|
|
||||||
MuMsg *msg;
|
MuMsg *msg;
|
||||||
const char *msgid;
|
const char *msgid;
|
||||||
|
|
||||||
unsigned docid;
|
unsigned docid;
|
||||||
MuContainerFlag flags;
|
MuContainerFlag flags;
|
||||||
|
|
||||||
};
|
};
|
||||||
typedef struct _MuContainer MuContainer;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -223,6 +220,4 @@ MuContainer* mu_container_sort (MuContainer *c, MuMsgFieldId mfid,
|
|||||||
GHashTable* mu_container_thread_info_hash_new (MuContainer *root_set,
|
GHashTable* mu_container_thread_info_hash_new (MuContainer *root_set,
|
||||||
size_t matchnum);
|
size_t matchnum);
|
||||||
|
|
||||||
G_END_DECLS
|
#endif /*MU_CONTAINER_HH__*/
|
||||||
|
|
||||||
#endif /*__MU_CONTAINER_H__*/
|
|
||||||
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
#include "mu-msg.h"
|
#include "mu-msg.h"
|
||||||
#include "mu-msg-iter.h"
|
#include "mu-msg-iter.h"
|
||||||
#include "mu-threader.h"
|
#include "mu-threader.hh"
|
||||||
|
|
||||||
struct ltstr {
|
struct ltstr {
|
||||||
bool operator () (const std::string &s1,
|
bool operator () (const std::string &s1,
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
|
||||||
/*
|
/*
|
||||||
** Copyright (C) 2012-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2012-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify it
|
** This program is free software; you can redistribute it and/or modify it
|
||||||
** under the terms of the GNU General Public License as published by the
|
** under the terms of the GNU General Public License as published by the
|
||||||
@ -17,11 +16,12 @@
|
|||||||
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
#include "mu-threader.hh"
|
||||||
|
|
||||||
#include <math.h> /* for log, ceil */
|
#include <math.h> /* for log, ceil */
|
||||||
#include <string.h> /* for memset */
|
#include <string.h> /* for memset */
|
||||||
|
|
||||||
#include "mu-threader.h"
|
#include "mu-container.hh"
|
||||||
#include "mu-container.h"
|
|
||||||
#include "utils/mu-str.h"
|
#include "utils/mu-str.h"
|
||||||
|
|
||||||
/* msg threading implementation based on JWZ's algorithm, as described in:
|
/* msg threading implementation based on JWZ's algorithm, as described in:
|
||||||
@ -137,7 +137,7 @@ find_or_create_referred (GHashTable *id_table, const char *msgid,
|
|||||||
|
|
||||||
g_return_val_if_fail (msgid, NULL);
|
g_return_val_if_fail (msgid, NULL);
|
||||||
|
|
||||||
c = g_hash_table_lookup (id_table, msgid);
|
c = (MuContainer*)g_hash_table_lookup (id_table, msgid);
|
||||||
*created = !c;
|
*created = !c;
|
||||||
if (!c) {
|
if (!c) {
|
||||||
c = mu_container_new (NULL, 0, msgid);
|
c = mu_container_new (NULL, 0, msgid);
|
||||||
@ -172,7 +172,7 @@ find_or_create (GHashTable *id_table, MuMsg *msg, guint docid)
|
|||||||
|
|
||||||
/* XXX the '<none>' works around a crash; find a better
|
/* XXX the '<none>' works around a crash; find a better
|
||||||
* solution */
|
* solution */
|
||||||
c = g_hash_table_lookup (id_table, msgid);
|
c = (MuContainer*)g_hash_table_lookup (id_table, msgid);
|
||||||
|
|
||||||
/* If id_table contains an empty MuContainer for this ID: * *
|
/* If id_table contains an empty MuContainer for this ID: * *
|
||||||
* Store this message in the MuContainer's message slot. */
|
* Store this message in the MuContainer's message slot. */
|
||||||
@ -1,7 +1,5 @@
|
|||||||
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Copyright (C) 2012-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2012-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify it
|
** This program is free software; you can redistribute it and/or modify it
|
||||||
** under the terms of the GNU General Public License as published by the
|
** under the terms of the GNU General Public License as published by the
|
||||||
@ -19,14 +17,12 @@
|
|||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __MU_THREADER_H__
|
#ifndef MU_THREADER_HH__
|
||||||
#define __MU_THREADER_H__
|
#define MU_THREADER_HH__
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <mu-msg-iter.h>
|
#include <mu-msg-iter.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* takes an iter and the total number of matches, and from this
|
* takes an iter and the total number of matches, and from this
|
||||||
* generates a hash-table with information about the thread structure
|
* generates a hash-table with information about the thread structure
|
||||||
@ -50,7 +46,4 @@ G_BEGIN_DECLS
|
|||||||
GHashTable *mu_threader_calculate (MuMsgIter *iter, size_t matches,
|
GHashTable *mu_threader_calculate (MuMsgIter *iter, size_t matches,
|
||||||
MuMsgFieldId sortfield, gboolean revert);
|
MuMsgFieldId sortfield, gboolean revert);
|
||||||
|
|
||||||
|
#endif /*MU_THREADER_HH__*/
|
||||||
G_END_DECLS
|
|
||||||
|
|
||||||
#endif /*__MU_THREADER_H__*/
|
|
||||||
@ -1,5 +1,3 @@
|
|||||||
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Copyright (C) 2014 Jakub Sitnicki <jsitnicki@gmail.com>
|
** Copyright (C) 2014 Jakub Sitnicki <jsitnicki@gmail.com>
|
||||||
**
|
**
|
||||||
@ -19,14 +17,11 @@
|
|||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if HAVE_CONFIG_H
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif /*HAVE_CONFIG_H*/
|
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#include "test-mu-common.hh"
|
#include "test-mu-common.hh"
|
||||||
#include "mu-container.h"
|
#include "mu-container.hh"
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
container_has_children (const MuContainer *c)
|
container_has_children (const MuContainer *c)
|
||||||
|
|||||||
@ -197,15 +197,15 @@ copy_test_data (void)
|
|||||||
gchar *dir, *cmd;
|
gchar *dir, *cmd;
|
||||||
|
|
||||||
dir = test_mu_common_get_random_tmpdir();
|
dir = test_mu_common_get_random_tmpdir();
|
||||||
cmd = g_strdup_printf ("mkdir -m 0700 %s", dir);
|
cmd = g_strdup_printf ("mkdir -p -m 0700 %s", dir);
|
||||||
if (g_test_verbose())
|
if (g_test_verbose())
|
||||||
g_print ("cmd: %s\n", cmd);
|
g_debug ("cmd: %s\n", cmd);
|
||||||
g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL));
|
g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL));
|
||||||
g_free (cmd);
|
g_free (cmd);
|
||||||
|
|
||||||
cmd = g_strdup_printf ("cp -R %s %s", MU_TESTMAILDIR, dir);
|
cmd = g_strdup_printf ("cp -R %s %s", MU_TESTMAILDIR, dir);
|
||||||
if (g_test_verbose())
|
if (g_test_verbose())
|
||||||
g_print ("cmd: %s\n", cmd);
|
g_debug ("cmd: %s\n", cmd);
|
||||||
g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL));
|
g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL));
|
||||||
g_free (cmd);
|
g_free (cmd);
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ dir_cb (const char *fullpath, gboolean enter, WalkData *data)
|
|||||||
++data->_dir_left;
|
++data->_dir_left;
|
||||||
|
|
||||||
if (g_test_verbose())
|
if (g_test_verbose())
|
||||||
g_print ("%s: %s: %s (%u)\n", __func__, enter ? "entering" : "leaving",
|
g_debug ("%s: %s: %s (%u)\n", __func__, enter ? "entering" : "leaving",
|
||||||
fullpath, enter ? data->_dir_entered : data->_dir_left);
|
fullpath, enter ? data->_dir_entered : data->_dir_left);
|
||||||
|
|
||||||
return MU_OK;
|
return MU_OK;
|
||||||
|
|||||||
@ -49,8 +49,6 @@ static bool
|
|||||||
call (const Command::CommandMap& cmap, const std::string& str) try
|
call (const Command::CommandMap& cmap, const std::string& str) try
|
||||||
{
|
{
|
||||||
const auto sexp{Sexp::make_parse(str)};
|
const auto sexp{Sexp::make_parse(str)};
|
||||||
g_message ("invoking %s", to_string(sexp).c_str());
|
|
||||||
|
|
||||||
invoke (cmap, sexp);
|
invoke (cmap, sexp);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -75,8 +73,6 @@ test_command()
|
|||||||
"My command,",
|
"My command,",
|
||||||
{}});
|
{}});
|
||||||
|
|
||||||
std::cout << "****** " << cmap << "\n";
|
|
||||||
|
|
||||||
g_assert_true(call(cmap, "(my-command :param1 \"hello\")"));
|
g_assert_true(call(cmap, "(my-command :param1 \"hello\")"));
|
||||||
g_assert_true(call(cmap, "(my-command :param1 \"hello\" :param2 123)"));
|
g_assert_true(call(cmap, "(my-command :param1 \"hello\" :param2 123)"));
|
||||||
|
|
||||||
@ -127,6 +123,8 @@ test_command_fail()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void black_hole() {}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[]) try
|
main (int argc, char *argv[]) try
|
||||||
{
|
{
|
||||||
@ -137,6 +135,12 @@ main (int argc, char *argv[]) try
|
|||||||
g_test_add_func ("/utils/command-parser/command2", test_command2);
|
g_test_add_func ("/utils/command-parser/command2", test_command2);
|
||||||
g_test_add_func ("/utils/command-parser/command-fail", test_command_fail);
|
g_test_add_func ("/utils/command-parser/command-fail", test_command_fail);
|
||||||
|
|
||||||
|
g_log_set_handler (NULL,
|
||||||
|
(GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL|
|
||||||
|
G_LOG_FLAG_RECURSION),
|
||||||
|
(GLogFunc)black_hole, NULL);
|
||||||
|
|
||||||
|
|
||||||
return g_test_run ();
|
return g_test_run ();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,7 @@
|
|||||||
#include "utils/mu-date.h"
|
#include "utils/mu-date.h"
|
||||||
|
|
||||||
#include "mu-cmd.hh"
|
#include "mu-cmd.hh"
|
||||||
#include "mu-threader.h"
|
#include "mu-threader.hh"
|
||||||
|
|
||||||
using namespace Mu;
|
using namespace Mu;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user