From 8dcc8600eb7b4cb11df377a8ae78a24281657873 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Mon, 12 Apr 2021 11:00:31 +0200 Subject: Fixed bug in csmap_X_erase_at() when erasing last element in map. --- docs/clist_api.md | 4 ++-- stc/csmap.h | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/clist_api.md b/docs/clist_api.md index 4660ad9c..9d0945d6 100644 --- a/docs/clist_api.md +++ b/docs/clist_api.md @@ -1,10 +1,10 @@ -# STC [clist](../stc/clist.h): Singly Linked List +# STC [clist](../stc/clist.h): Forward List ![List](pics/list.jpg) The **clist** container supports fast insertion and removal of elements from anywhere in the container. Fast random access is not supported. -Unlike the c++ class *std::forward_list*, **clist** has an API similar to *std::list*, and also supports +Unlike the c++ class *std::forward_list*, **clist** has an API similar to ***std::list***, and also supports *push_back()* (**O**(1) time). It is still implemented as a singly-linked list. A **clist** object occupies only one pointer in memory, and like *std::forward_list* the length of the list is not stored. The method *clist_X_count()* returns size of list, computed in **O**(*n*) time. diff --git a/stc/csmap.h b/stc/csmap.h index 7171a128..2c0b817a 100644 --- a/stc/csmap.h +++ b/stc/csmap.h @@ -501,10 +501,11 @@ static struct csmap_rep _csmap_inits = {0, 0, 0, 0}; \ STC_DEF CX##_iter_t \ CX##_erase_at(CX* self, CX##_iter_t it) { \ - RawKey raw = keyToRaw(KEY_REF_##C(it.ref)); CX##_next(&it); \ - RawKey nxt = keyToRaw(KEY_REF_##C(it.ref)); \ + RawKey raw = keyToRaw(KEY_REF_##C(it.ref)), nxt; \ + CX##_next(&it); \ + if (it.ref) nxt = keyToRaw(KEY_REF_##C(it.ref)); \ CX##_erase(self, raw); \ - CX##_find_it(self, nxt, &it); \ + if (it.ref) CX##_find_it(self, nxt, &it); \ return it; \ } \ \ -- cgit v1.2.3