0

シリアル化のために、クラスの writeObject メソッドをオーバーライドしています。クラスはリストベースのクラスです。リスト内のノードに同じキーが含まれている場合に備えて、メモリ効率を高める必要があります。したがって、同一の複数のキーを送信する代わりに、同じキーへの参照を送信したいと考えています。

私の基本的な目標は、重複したキーを書き出さないようにすることです。重複するキーがある場合は、キーを 1 回だけ送信し、その後はそのキーへの参照のみを送信するようにします。

@SuppressWarnings("rawtypes")
private void writeObject(java.io.ObjectOutputStream out){
    try{ // Attempt to write data out
        out.writeInt(size); // size is number of Nodes in list
        ArrayList<Node> reverse = new ArrayList<Node>();
        // Reverse the order to write out so readObject builds correctly
        for(Node c = head; c != null; c = c.next)
            reverse.add(0, c);      
        for(Node c: reverse){ // Break down objects and write out
            out.writeObject(c.key);
            out.writeObject(c.val);
        }

    } // Catch any exceptions
    catch(IOException e){
        System.out.println("seriallist writeobject");
        System.out.println(e);
    }
}

This is the code that I have working correctly for serializing the data. I've tried to make a list of all unique keys and attempted to have each node reference one of those keys, but I haven't been able to get the file size down when I write out.

Also ideally I would like to make the references inside of this method so I only have to worry about doing it before writing out instead of maintaining them during adding/removing.

Any help would be greatly appreciated!

4

0 に答える 0