2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
* Copyright 2001-2002 NaN Holding BV. All rights reserved. */
|
2018-06-17 16:32:54 +02:00
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#pragma once
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bli
|
2011-02-18 13:58:08 +00:00
|
|
|
*/
|
|
|
|
|
2015-06-12 16:57:15 +10:00
|
|
|
#include "BLI_compiler_attrs.h"
|
|
|
|
|
2020-03-02 15:04:53 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-08-16 05:50:00 +00:00
|
|
|
struct BLI_mempool;
|
2019-01-28 21:08:24 +11:00
|
|
|
struct MemArena;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
typedef void (*LinkNodeFreeFP)(void *link);
|
2006-08-28 01:12:36 +00:00
|
|
|
typedef void (*LinkNodeApplyFP)(void *link, void *userdata);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
typedef struct LinkNode {
|
|
|
|
struct LinkNode *next;
|
|
|
|
void *link;
|
|
|
|
} LinkNode;
|
|
|
|
|
2015-06-12 16:57:15 +10:00
|
|
|
/**
|
|
|
|
* Use for append (single linked list, storing the last element).
|
|
|
|
*
|
|
|
|
* \note list manipulation functions don't operate on this struct.
|
|
|
|
* This is only to be used while appending.
|
|
|
|
*/
|
|
|
|
typedef struct LinkNodePair {
|
|
|
|
LinkNode *list, *last_node;
|
|
|
|
} LinkNodePair;
|
|
|
|
|
2015-11-26 08:50:35 +11:00
|
|
|
int BLI_linklist_count(const LinkNode *list) ATTR_WARN_UNUSED_RESULT;
|
|
|
|
int BLI_linklist_index(const LinkNode *list, void *ptr) ATTR_WARN_UNUSED_RESULT;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2015-06-12 16:57:15 +10:00
|
|
|
LinkNode *BLI_linklist_find(LinkNode *list, int index) ATTR_WARN_UNUSED_RESULT;
|
2020-07-10 12:04:29 +10:00
|
|
|
LinkNode *BLI_linklist_find_last(LinkNode *list) ATTR_WARN_UNUSED_RESULT;
|
2010-06-22 15:20:06 +00:00
|
|
|
|
2015-06-12 16:57:15 +10:00
|
|
|
void BLI_linklist_reverse(LinkNode **listp) ATTR_NONNULL(1);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Move an item from its current position to a new one inside a single-linked list.
|
|
|
|
* \note `*listp` may be modified.
|
|
|
|
*/
|
2015-06-12 16:57:15 +10:00
|
|
|
void BLI_linklist_move_item(LinkNode **listp, int curr_index, int new_index) ATTR_NONNULL(1);
|
2015-02-10 17:28:55 +01:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* A version of #BLI_linklist_prepend that takes the allocated link.
|
|
|
|
*/
|
2015-06-12 16:57:15 +10:00
|
|
|
void BLI_linklist_prepend_nlink(LinkNode **listp, void *ptr, LinkNode *nlink) ATTR_NONNULL(1, 3);
|
|
|
|
void BLI_linklist_prepend(LinkNode **listp, void *ptr) ATTR_NONNULL(1);
|
|
|
|
void BLI_linklist_prepend_arena(LinkNode **listp, void *ptr, struct MemArena *ma)
|
|
|
|
ATTR_NONNULL(1, 3);
|
|
|
|
void BLI_linklist_prepend_pool(LinkNode **listp, void *ptr, struct BLI_mempool *mempool)
|
|
|
|
ATTR_NONNULL(1, 3);
|
2013-08-16 13:02:34 +00:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/* Use #LinkNodePair to avoid full search. */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A version of append that takes the allocated link.
|
|
|
|
*/
|
2015-06-12 16:57:15 +10:00
|
|
|
void BLI_linklist_append_nlink(LinkNodePair *list_pair, void *ptr, LinkNode *nlink)
|
|
|
|
ATTR_NONNULL(1, 3);
|
|
|
|
void BLI_linklist_append(LinkNodePair *list_pair, void *ptr) ATTR_NONNULL(1);
|
|
|
|
void BLI_linklist_append_arena(LinkNodePair *list_pair, void *ptr, struct MemArena *ma)
|
|
|
|
ATTR_NONNULL(1, 3);
|
|
|
|
void BLI_linklist_append_pool(LinkNodePair *list_pair, void *ptr, struct BLI_mempool *mempool)
|
|
|
|
ATTR_NONNULL(1, 3);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-06-12 16:57:15 +10:00
|
|
|
void *BLI_linklist_pop(LinkNode **listp) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
|
|
|
void *BLI_linklist_pop_pool(LinkNode **listp, struct BLI_mempool *mempool) ATTR_WARN_UNUSED_RESULT
|
|
|
|
ATTR_NONNULL(1, 2);
|
|
|
|
void BLI_linklist_insert_after(LinkNode **listp, void *ptr) ATTR_NONNULL(1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-06-12 16:57:15 +10:00
|
|
|
void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc);
|
|
|
|
void BLI_linklist_freeN(LinkNode *list);
|
|
|
|
void BLI_linklist_free_pool(LinkNode *list, LinkNodeFreeFP freefunc, struct BLI_mempool *mempool);
|
|
|
|
void BLI_linklist_apply(LinkNode *list, LinkNodeApplyFP applyfunc, void *userdata);
|
|
|
|
LinkNode *BLI_linklist_sort(LinkNode *list,
|
|
|
|
int (*cmp)(const void *, const void *)) ATTR_WARN_UNUSED_RESULT
|
|
|
|
ATTR_NONNULL(2);
|
|
|
|
LinkNode *BLI_linklist_sort_r(LinkNode *list,
|
|
|
|
int (*cmp)(void *, const void *, const void *),
|
|
|
|
void *thunk) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-08-16 13:02:34 +00:00
|
|
|
#define BLI_linklist_prepend_alloca(listp, ptr) \
|
2022-12-02 12:34:26 +01:00
|
|
|
BLI_linklist_prepend_nlink(listp, ptr, (LinkNode *)alloca(sizeof(LinkNode)))
|
2015-12-07 19:13:30 +11:00
|
|
|
#define BLI_linklist_append_alloca(list_pair, ptr) \
|
2022-12-02 12:34:26 +01:00
|
|
|
BLI_linklist_append_nlink(list_pair, ptr, (LinkNode *)alloca(sizeof(LinkNode)))
|
2013-08-16 13:02:34 +00:00
|
|
|
|
2020-03-02 15:04:53 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|