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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

It 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.

本文标签: