summaryrefslogtreecommitdiff
path: root/src/analysis/db/collection.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-09-29 20:57:16 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-09-29 20:57:16 (GMT)
commit55bc8570f25a479b222733c4093f9ae996c9f68e (patch)
tree258773ab9cbcab5ec459527f3b3a40bf2897ce00 /src/analysis/db/collection.c
parent2de826110c85feb68d6e5b09c133e2300ae4c0d0 (diff)
Handled disabled update items.
Diffstat (limited to 'src/analysis/db/collection.c')
-rw-r--r--src/analysis/db/collection.c84
1 files changed, 75 insertions, 9 deletions
diff --git a/src/analysis/db/collection.c b/src/analysis/db/collection.c
index 7b2082a..6e877a4 100644
--- a/src/analysis/db/collection.c
+++ b/src/analysis/db/collection.c
@@ -36,6 +36,7 @@
#include "collection-int.h"
#include "misc/rlestr.h"
#include "../../common/extstr.h"
+#include "../../common/sort.h"
#include "../../glibext/chrysamarshal.h"
@@ -56,14 +57,8 @@ static void g_db_collection_dispose(GDbCollection *);
/* Procède à la libération totale de la mémoire. */
static void g_db_collection_finalize(GDbCollection *);
-
-
-#define g_db_collection_find_by_timestamped(c, i) c->count
-
-#define g_db_collection_find_by_timestamp(c, i) c->count
-
-
-
+/* Retrouve l'élément correspondant à un horodatage. */
+size_t g_db_collection_find_by_timestamped(GDbCollection *, const GDbItem *);
/* Ajoute un élément dans la liste des éléments actifs. */
static void g_db_collection_set_last_item(GDbCollection *, GDbItem *, bool);
@@ -71,6 +66,9 @@ static void g_db_collection_set_last_item(GDbCollection *, GDbItem *, bool);
/* Retire un élément de la liste des éléments courants. */
static void g_db_collection_unset_last_item(GDbCollection *, GDbItem *, size_t);
+/* Retrouve le premier élément correspondant à un horodatage. */
+size_t g_db_collection_find_by_timestamp(GDbCollection *, timestamp_t);
+
/* --------------------- MANIPULATIONS AVEC UNE BASE DE DONNEES --------------------- */
@@ -453,7 +451,7 @@ bool g_db_collection_unpack(GDbCollection *collec, packed_buffer *pbuf, sqlite3
* *
******************************************************************************/
-bool g_db_collection_pack(GDbCollection *collec, packed_buffer *pbuf, DBAction action, GDbItem *item)
+bool g_db_collection_pack(GDbCollection *collec, packed_buffer *pbuf, DBAction action, const GDbItem *item)
{
bool result; /* Bilan à retourner */
@@ -617,6 +615,37 @@ GDbItem *g_db_collection_has_key(GDbCollection *collec, ...)
/******************************************************************************
* *
+* Paramètres : binary = élément binaire à consulter. *
+* item = définition de l'élément à retrouver. *
+* *
+* Description : Retrouve l'élément correspondant à un horodatage. *
+* *
+* Retour : Indice valide pour un élément retrouvé, invalide sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_db_collection_find_by_timestamped(GDbCollection *collec, const GDbItem *item)
+{
+ size_t result; /* Indice à retourner */
+ GDbItem **found; /* Emplacement de la trouvaille*/
+
+ found = bsearch(&item, collec->items, collec->count, sizeof(GDbItem *),
+ (__compar_fn_t)g_db_item_cmp_timestamp);
+
+ if (found == NULL)
+ result = collec->count;
+ else
+ result = found - collec->items;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : collec = ensemble d'éléments à consulter. *
* item = élément complet dont un double est à rechercher. *
* *
@@ -942,6 +971,43 @@ static void g_db_collection_unset_last_item(GDbCollection *collec, GDbItem *item
* *
* Paramètres : binary = élément binaire à consulter. *
* timestamp = date du dernier élément à garder comme actif. *
+* *
+* Description : Retrouve le premier élément correspondant à un horodatage. *
+* *
+* Retour : Indice valide pour un élément retrouvé, invalide sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_db_collection_find_by_timestamp(GDbCollection *collec, timestamp_t timestamp)
+{
+ size_t result; /* Indice à retourner */
+ timestamp_t prev_ts; /* Horodatage précédent */
+
+ bsearch_index(&timestamp, collec->items, collec->count, sizeof(GDbItem *),
+ (__compar_fn_t)g_db_item_cmp_with_timestamp, &result);
+
+ while (result > 0)
+ {
+ prev_ts = g_db_item_get_timestamp(collec->items[result - 1]);
+
+ if (cmp_timestamp(&prev_ts, &timestamp) != 0)
+ break;
+
+ result--;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à consulter. *
+* timestamp = date du dernier élément à garder comme actif. *
* db = base de données à mettre à jour. *
* pbuf = paquet de données où venir inscrire les infos. *
* *