admin管理员组文章数量:1123559
Is there formal name for such data structure?
Like Map<Key, Foo>
, but with restriction/guarantee that Key
is a subset of fields from Foo
, actually reference to those fields.
A bit contrived java illustration:
GamePiece { Integer x; Integer y; String gamePieceType; }
HypotheticalStructure<GamePiece> gameMap = new HypotheticalStructure<GamePiece>(GamePiece::getX, GamePiece::getY); // a cell can be occupied only by one piece.
gameMap.add(new GamePiece(1, 1, "Knight")); // ok
gameMap.add(new GamePiece(1, 1, "Rook")); // error - (1, 1 is already occupied by the knight)
(analogous to table where uniqueness constrain on (x,y) exists)
Maybe there is some implementation in some library in some language.
Is there formal name for such data structure?
Like Map<Key, Foo>
, but with restriction/guarantee that Key
is a subset of fields from Foo
, actually reference to those fields.
A bit contrived java illustration:
GamePiece { Integer x; Integer y; String gamePieceType; }
HypotheticalStructure<GamePiece> gameMap = new HypotheticalStructure<GamePiece>(GamePiece::getX, GamePiece::getY); // a cell can be occupied only by one piece.
gameMap.add(new GamePiece(1, 1, "Knight")); // ok
gameMap.add(new GamePiece(1, 1, "Rook")); // error - (1, 1 is already occupied by the knight)
(analogous to table where uniqueness constrain on (x,y) exists)
Maybe there is some implementation in some library in some language.
Share Improve this question asked 20 hours ago IndustryUser1942IndustryUser1942 1,2461 gold badge10 silver badges15 bronze badges1 Answer
Reset to default 1It looks like you're looking for HashSet<E> where E needs to override equals and hashCode. Your uniqueness guarantee depends on your hashCode and equals implementations.
本文标签:
版权声明:本文标题:data structures - datastructure: collection with uniqueness guarantees (analogous to DB table with unique key constraint) - Stac 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736578466a1944908.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论