org.exist.storage.index
Class FreeList

java.lang.Object
  extended by org.exist.storage.index.FreeList

public class FreeList
extends Object

Manages a list of pages containing unused sections. Class BFile stores all data in variable length records. As records may grow or shrink, the database has to keep track of the amount of free space currently available in pages. Class BFile will always check if FreeList has a page that can be filled before creating a new page. FreeList implements a linked list of FreeSpace objects. Each object in the list describes a page and the unused space in this page.

Author:
wolf
See Also:
FreeList

Field Summary
static int MAX_FREE_LIST_LEN
           
 
Constructor Summary
FreeList()
           
 
Method Summary
 void add(FreeSpace free)
          Append a new FreeSpace object to the list, describing the amount of free space available on a page.
 FreeSpace find(int requiredSize)
          Try to find a page that has at least requiredSize bytes available.
 int read(byte[] buf, int offset)
          Read the list from a RandomAccessFile.
 void remove(FreeSpace node)
          Remove a record from the list.
 FreeSpace retrieve(long pageNum)
          Retrieve the record stored for the given page number.
 String toString()
           
 int write(byte[] buf, int offset)
          Write the list to a RandomAccessFile.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_FREE_LIST_LEN

public static final int MAX_FREE_LIST_LEN
See Also:
Constant Field Values
Constructor Detail

FreeList

public FreeList()
Method Detail

add

public void add(FreeSpace free)
Append a new FreeSpace object to the list, describing the amount of free space available on a page.

Parameters:
free -

remove

public void remove(FreeSpace node)
Remove a record from the list.

Parameters:
node -

retrieve

public FreeSpace retrieve(long pageNum)
Retrieve the record stored for the given page number.

Parameters:
pageNum -

find

public FreeSpace find(int requiredSize)
Try to find a page that has at least requiredSize bytes available. This method selects the page with the smallest possible space. This guarantees that all pages will be filled before creating a new page.

Parameters:
requiredSize -

toString

public String toString()
Overrides:
toString in class Object

read

public int read(byte[] buf,
                int offset)
         throws IOException
Read the list from a RandomAccessFile.

Parameters:
buf -
offset -
Throws:
IOException

write

public int write(byte[] buf,
                 int offset)
          throws IOException
Write the list to a RandomAccessFile. As the list is written to the file header, its maximum length has to be restricted. The method will thus only store MAX_FREE_LIST_LEN entries and throw away the rest. Usually, this should not happen very often, so it is ok to waste some space.

Parameters:
buf -
offset -
Throws:
IOException


Copyright (C) Wolfgang Meier. All rights reserved.