是否有人知道允许可变密钥的基于密钥的数据结构的任何实现或论文?
由于密钥正在变异,我不确定“密钥”是否是正确的术语,但我希望你理解我的意思。
我想要这个的具体原因是能够尽可能高效地进行邻居查找以更改对象,而无需经常对并行列表进行排序,不断重构树或类似结构,或者当然处理完全崩溃的问题。当其键被突变时的hashmap。
一个快速,非常简单的用法示例是(Java HashMap语法):
MutableKeyMap<Point, String> m = new MutableKeyMap<Point, String>();
Point p = new Point(5, 6)
m.put(p, "foo");
Point o = new Point(6, 6);
m.put(o, "bar");
// The points are currently neighbors, so
m.get(new Point(o.x - 1, o.y)); // returns "foo".
m.get(new Point(p.x + 1, p.y)); // returns "bar"
// Now here is where most data structures fall apart without some reworking
o.y += 1;
m.get(new Point(o.x - 1, o.y - 1)); // Still returns "foo" because the point "foo" is mapped to has not changed
m.get(new Point(p.x + 1, p.y)); // returns null, as to be expected because o would no longer map to there
m.get(new Point(p.x + 1, p.y + 1)); // A hash map would return null here as well when it should return "bar",
// because the data structure cannot account for the identity-changing mutation of the key.
m.get(o); // even returns null because of this in a hash map.
// Therefore we have effectively deleted the entry. In this data structure the idea would be to maintain this link despite the mutation.
理想情况下,此数据结构将允许地图提供的优雅(如果可能,速度)用于访问集合中与其他元素相关的其他元素,同时允许访问元素的那些值发生更改。
我意识到这可能要求一个“完美”的数据结构,但我真的只是对这种数据结构中存在的内容或人们的任何想法感兴趣。