English 中文(简体)
推荐存储和获取关键对数值和多个整数值的方法,并借助内存绘制的 IO 图
原标题:Recommended way of storing and accessing key value pairs and multiple integer values with the help of memory mapped IO

在 Java 程序中,我需要暂时存储许多记录 -- 一份记录包含一个密钥、一个对象和一个整数值。 总共处理数以百万计的记录, 但我计划在处理完毕后删除一个记录... 插入另一记录后,处理完成,然后删除...

以内存图绘制的IO来保存这些价值的最佳方式是什么?

我可以看到用于绘制字节缓冲的样本, 但我如何存储多个记录, 然后取回它们... 我是否必须在文件存储中添加记录时保存位置编号, 并用这些来检索数据? 那么我就必须另建一个阵列来存储位置数字... 是否有建议的方法 使用 Java 的内存地图 IO 存储/ 检索数据?

最佳回答
问题回答

您可以使用"http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html" rel=“nofollow”>Hashmap ,如果您能够根据 records key/int pap 创建组合键和数值作为 object ,然后您可以在“code>HashMap 中存储它,并在恒定时间操作中从 hashMap中删除值。


示例:

    //Constructs a new empty HashMap with default initial capacity        
    HashMap hashMap = new HashMap();

    //Key would be combination of "record key/int pair"
    hashMap.put(Key1, new Integer(1)); 
    hashMap.put(Key2, new Integer(2));
    hashMap.put(Key3, new Integer(3));

    //You can remove values from HashMap in constant time using remove
    hashMap.remove(Key1);




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签