Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Data structures 使用地图中的地图是否最佳?_Data Structures_Hashmap - Fatal编程技术网

Data structures 使用地图中的地图是否最佳?

Data structures 使用地图中的地图是否最佳?,data-structures,hashmap,Data Structures,Hashmap,我有关于不同国家不同运动队运动员姓名的数据。如果我的查询需要查找某个球员是否为某个国家的某支球队踢球,我应该使用什么样的数据结构来存储此数据集 以下哪项是更好的数据结构?为什么 1) HashMap<Country, HashMap<Sport, HashSet<PlayerName>>> 1)HashMap 或 2) 乡村体育{ 弦国 弦乐运动 } //重写hashcode和equals方法 哈希图 这两种情况下的查找都是O(1),那么在这种情况下哪个

我有关于不同国家不同运动队运动员姓名的数据。如果我的查询需要查找某个球员是否为某个国家的某支球队踢球,我应该使用什么样的数据结构来存储此数据集

以下哪项是更好的数据结构?为什么

1) HashMap<Country, HashMap<Sport, HashSet<PlayerName>>>
1)HashMap

2)
乡村体育{
弦国
弦乐运动
}
//重写hashcode和equals方法
哈希图

这两种情况下的查找都是O(1),那么在这种情况下哪个数据结构更好?

我认为您应该为您的
CountrySport
类和
Player
类提供
id
。假设两个
id
都是
long
类型。一旦有了它,就创建两个HashMap
HashMap
HashMap
。通过
CountrySportID
查找
PlayerID
,从
PlayerID
中,您可以查找
PlayerName
。有很多选择。要说哪一个是最好的,您必须更精确地知道查询的确切内容。到目前为止,听起来你想要一个球员和球队的关系。一种有效的存储方法,它是一组
对,其中id是小整数。您可以使用ID为索引的简单数组将整数映射到字符串名、团队国家等。集合可以是矩形数组、哈希表、平衡树、跳过列表等。最佳选择取决于您没有告诉我们的很多事情。
2)
class CountrySport{
String Country
String Sport
}
//override hashcode and equals methods

HashMap<CountrySport, HashSet<PlayerName>>