Java:Map中的内部数据结构
我正在尝试创建一个实现 Map 接口的类。所以我正在编写代码来检查调用对象是否为空。然而,我对应该在内部使用哪种数据结构有点困惑。目前我正在使用哈希表。 提前致谢
I am trying to create a class that implements the Map interface. So I am writing code that will check if the calling object is empty or not. However I am a little confused as to which data structure I should use internally. At present I am using a Hash Table.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自维基百科,
From Wikipedia,
除了表本身之外,您还可以维护一个整数成员变量来跟踪集合的大小,每次放置新映射时递增它,每次删除映射时递减。这样,您可以简化
size
和isEmpty
接口方法:In addition to the table itself you could also maintain an integer member variable to track the size of the collection, incrementing it each time a new mapping is put and decrementing each time one is removed. This way, you can simplify the
size
andisEmpty
interface methods:我尝试了不同的方法,但最终扩展了一些数据结构,这些数据结构本身非常强大,不需要任何编码技能。因此,我决定使用普通字符串数组(2)来形成类似虚拟哈希图的结构,该结构会随着空间需求的增加而扩展。
下面是完整代码的链接。
http://code.google.com /p/rohan-oopconcept-assignment/source/browse/trunk/src/EmployeeMap.java
I tried different methods but ended up extending some data structure that was itself so strong that no coding skills were needed for it. So I decided to use normal string arrays( 2) to from a virtual hash map like structure which would expand as the need for space increased.
Below is the link to the complete code.
http://code.google.com/p/rohan-oopconcept-assignment/source/browse/trunk/src/EmployeeMap.java