2023-08-15 16:20:26 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02: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
|
|
|
|
2022-08-18 22:37:52 +02:00
|
|
|
#include "BLI_map.hh"
|
|
|
|
|
2013-08-23 22:35:00 +02:00
|
|
|
struct BLI_mempool;
|
2019-01-28 11:08:24 +01:00
|
|
|
struct ID;
|
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 22:37:52 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
class TreeStoreElemKey {
|
|
|
|
public:
|
|
|
|
ID *id = nullptr;
|
|
|
|
short type = 0;
|
|
|
|
short nr = 0;
|
|
|
|
|
|
|
|
explicit TreeStoreElemKey(const TreeStoreElem &elem);
|
|
|
|
TreeStoreElemKey(ID *id, short type, short nr);
|
|
|
|
|
|
|
|
uint64_t hash() const;
|
|
|
|
friend bool operator==(const TreeStoreElemKey &a, const TreeStoreElemKey &b);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
2022-08-18 20:15:36 +02:00
|
|
|
class TreeHash {
|
2022-08-18 22:37:52 +02:00
|
|
|
Map<TreeStoreElemKey, std::unique_ptr<class TseGroup>> elem_groups_;
|
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;
|
|
|
|
|
2022-08-18 22:37:52 +02:00
|
|
|
TseGroup *lookup_group(const TreeStoreElemKey &key) const;
|
|
|
|
TseGroup *lookup_group(const TreeStoreElem &elem) const;
|
|
|
|
TseGroup *lookup_group(short type, short nr, ID *id) const;
|
2022-08-18 20:15:36 +02:00
|
|
|
void fill_treehash(BLI_mempool &treestore);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace blender::bke::outliner::treehash
|