From 4724962cd3e187e6b574ef642a8995016b459957 Mon Sep 17 00:00:00 2001 From: Masahiko AMANO Date: Wed, 28 Dec 2022 17:05:09 +0300 Subject: [PATCH] feat(core): add functions to remove all kazari with a specific sasa/tanzaku ID --- core/shoppyou.c | 32 ++++++++++++++++++++++++++++++++ include/core.h | 6 ++++++ 2 files changed, 38 insertions(+) diff --git a/core/shoppyou.c b/core/shoppyou.c index b6fe7c6..c5ac453 100644 --- a/core/shoppyou.c +++ b/core/shoppyou.c @@ -137,3 +137,35 @@ int kazari_rem(Shoppyou *shoppyou, uint64_t sasa_id, uint64_t tanzaku_id) { } return 0; } + +int kazari_rem_by_sasa(Shoppyou *shoppyou, uint64_t sasa_id) { + if (sasa_id == HOLE_ID) { + return 1; + } + for (uint64_t i = 0; i < shoppyou->size; i++) { + if (shoppyou->database[i].sasa_id == sasa_id) { + shoppyou->database[i].sasa_id = HOLE_ID; + shoppyou->hole_cnt++; + shoppyou->holes = realloc(shoppyou->holes, shoppyou->hole_cnt * sizeof(Kazari *)); + shoppyou->holes[shoppyou->hole_cnt - 1] = shoppyou->database + i; + shoppyou->modified_ts = time(NULL); + } + } + return 0; +} + +int kazari_rem_by_tanzaku(Shoppyou *shoppyou, uint64_t tanzaku_id) { + if (tanzaku_id == HOLE_ID) { + return 1; + } + for (uint64_t i = 0; i < shoppyou->size; i++) { + if (shoppyou->database[i].tanzaku_id == tanzaku_id) { + shoppyou->database[i].tanzaku_id = HOLE_ID; + shoppyou->hole_cnt++; + shoppyou->holes = realloc(shoppyou->holes, shoppyou->hole_cnt * sizeof(Kazari *)); + shoppyou->holes[shoppyou->hole_cnt - 1] = shoppyou->database + i; + shoppyou->modified_ts = time(NULL); + } + } + return 0; +} diff --git a/include/core.h b/include/core.h index 1f98686..f3e833b 100644 --- a/include/core.h +++ b/include/core.h @@ -163,6 +163,12 @@ int kazari_add(Shoppyou *shoppyou, uint64_t sasa_id, uint64_t tanzaku_id); // Remove kazari from shoppyou int kazari_rem(Shoppyou *shoppyou, uint64_t sasa_id, uint64_t tanzaku_id); +// Remove all kazari with a specific sasa ID from shoppyou +int kazari_rem_by_sasa(Shoppyou *shoppyou, uint64_t sasa_id); + +// Remove all kazari with a specific tanzaku ID from shoppyou +int kazari_rem_by_tanzaku(Shoppyou *shoppyou, uint64_t tanzaku_id); + #ifdef __cplusplus } #endif