2022-02-10 23:07:11 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2015-04-07 03:01:47 +02:00
|
|
|
#pragma once
|
2013-08-23 22:35:00 +02:00
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2022-08-18 20:15:36 +02:00
|
|
|
*
|
|
|
|
* Hash table of tree-store elements (#TreeStoreElem) for fast lookups via a (id, type, index)
|
|
|
|
* tuple as key.
|
|
|
|
*
|
|
|
|
* The Outliner may have to perform many lookups for rebuilding complex trees, so this should be
|
|
|
|
* treated as performance sensitive.
|
2013-08-23 22:35:00 +02:00
|
|
|
*/
|
|
|
|
|
2022-08-18 20:15:36 +02:00
|
|
|
#include <memory>
|
2020-03-02 15:07:49 +01:00
|
|
|
|
2013-08-23 22:35:00 +02:00
|
|
|
struct BLI_mempool;
|
2019-01-28 11:08:24 +01:00
|
|
|
struct ID;
|
2022-08-17 21:00:22 +02:00
|
|
|
struct GHash;
|
2013-08-23 22:35:00 +02:00
|
|
|
struct TreeStoreElem;
|
|
|
|
|
2022-08-18 20:15:36 +02:00
|
|
|
namespace blender::bke::outliner::treehash {
|
2013-08-23 22:35:00 +02:00
|
|
|
|
2022-08-18 20:15:36 +02:00
|
|
|
class TreeHash {
|
|
|
|
GHash *treehash_ = nullptr;
|
2013-08-23 22:35:00 +02:00
|
|
|
|
2022-08-18 20:15:36 +02:00
|
|
|
public:
|
|
|
|
~TreeHash();
|
2018-05-28 17:07:52 +02:00
|
|
|
|
2022-08-19 05:49:13 +02:00
|
|
|
/** Create and fill hash-table with treestore elements */
|
2022-08-18 20:15:36 +02:00
|
|
|
static std::unique_ptr<TreeHash> create_from_treestore(BLI_mempool &treestore);
|
2013-08-23 22:35:00 +02:00
|
|
|
|
2022-08-19 05:49:13 +02:00
|
|
|
/** Full rebuild for already allocated hash-table. */
|
2022-08-18 20:15:36 +02:00
|
|
|
void rebuild_from_treestore(BLI_mempool &treestore);
|
2013-08-23 22:35:00 +02:00
|
|
|
|
2022-08-19 05:49:13 +02:00
|
|
|
/** Clear element usage flags. */
|
2022-08-18 20:15:36 +02:00
|
|
|
void clear_used();
|
2013-08-23 22:35:00 +02:00
|
|
|
|
2022-08-19 05:49:13 +02:00
|
|
|
/** Add hash-table element. */
|
2022-08-18 20:15:36 +02:00
|
|
|
void add_element(TreeStoreElem &elem);
|
2022-08-19 05:49:13 +02:00
|
|
|
/** Remove hash-table element. */
|
2022-08-18 20:15:36 +02:00
|
|
|
void remove_element(TreeStoreElem &elem);
|
2013-08-23 22:35:00 +02:00
|
|
|
|
2022-08-19 05:49:13 +02:00
|
|
|
/** Find first unused element with specific type, nr and id. */
|
2022-08-18 20:15:36 +02:00
|
|
|
TreeStoreElem *lookup_unused(short type, short nr, ID *id) const;
|
|
|
|
|
2022-08-19 05:49:13 +02:00
|
|
|
/** Find user or unused element with specific type, nr and id. */
|
2022-08-18 20:15:36 +02:00
|
|
|
TreeStoreElem *lookup_any(short type, short nr, ID *id) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
TreeHash() = default;
|
|
|
|
|
|
|
|
void fill_treehash(BLI_mempool &treestore);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace blender::bke::outliner::treehash
|