This commit is contained in:
IlyaShurupov 2024-03-29 17:52:10 +03:00
parent 5fd14ea4dd
commit 96078f326d
3 changed files with 13 additions and 14 deletions

View file

@ -21,6 +21,6 @@ public:
bool isLink() const override { return true; }
private:
std::shared_ptr<Node> mLink = nullptr;
std::weak_ptr<Node> mLink;
bool mIsHard = false;
};

View file

@ -26,23 +26,24 @@ public:
virtual ~Node();
virtual NodeType getType() const { return FILE; }
[[nodiscard]] virtual std::shared_ptr<Node> clone() const;
virtual std::shared_ptr<Node> clone() const;
virtual bool detachNode(const Key& key) { return false; }
virtual bool attachNode(const Key &newKey, std::shared_ptr<Node> newNode) { return false; }
virtual void getMaxDepthUtil(ui32 depth, ui32& maxDepth) const {}
virtual void dumpUtil(std::stringstream& ss, const Key& key, ui32 currentDepth, std::vector<bool>& indents);
ui32 getMaxDepth() const;
void dump(std::stringstream& ss);
void getNodeStraightPath(const std::shared_ptr<Node>& node, std::vector<std::shared_ptr<Node>>& path) const;
virtual ui64 size() const { return 0; }
virtual std::shared_ptr<Node> getTarget();
virtual std::shared_ptr<Node> findNode(const std::vector<Key>& path, ui32 currentDepth = 0);
virtual std::shared_ptr<Node> findNode(const Key& path) { return nullptr; }
bool empty() const { return !size(); }
static void indent(std::stringstream & ss, ui32 depth, std::vector<bool>& indents);
virtual bool isDirectory() const { return false; }
virtual bool isLink() const { return false; }
virtual bool isHard() const { return false; }
ui32 getMaxDepth() const;
void dump(std::stringstream& ss);
void getNodeStraightPath(const std::shared_ptr<Node>& node, std::vector<std::shared_ptr<Node>>& path) const;
bool empty() const { return !size(); }
static void indent(std::stringstream & ss, ui32 depth, std::vector<bool>& indents);
public:
std::weak_ptr<Node> mParent;

View file

@ -41,7 +41,9 @@ Link::~Link() {
}
std::shared_ptr<Node> Link::getLink() const {
return mLink;
auto target = mLink.lock();
assert(target);
return target;
}
bool Link::isHard() const {
@ -53,14 +55,10 @@ std::shared_ptr<Node> Link::getTarget() {
}
std::shared_ptr<Node> Link::findNode(const std::vector<Key>& path, ui32 currentDepth) {
if (path.size() == currentDepth) {
return std::shared_ptr<Node>(this);
}
assert(mLink);
return mLink->findNode(path, currentDepth + 1);
assert(path.size() != currentDepth);
return getLink()->findNode(path, currentDepth + 1);
}
void Link::dumpUtil(std::stringstream& ss, const Key& key, ui32 currentDepth, std::vector<bool>& indents) {
indent(ss, currentDepth, indents);
ss << key << (isHard() ? " hlink[/" : " dlink[/");