net.metanotion.util
Class ByteCord
java.lang.Object
net.metanotion.util.ByteCord
- All Implemented Interfaces:
- java.lang.Iterable<java.lang.Byte>
public class ByteCord
- extends java.lang.Object
- implements java.lang.Iterable<java.lang.Byte>
Immutable "Byte Array" supporting efficient delete, insert, replace, and get operations.
For an explanation of the "cord" data structure see:
"Ropes: An Alternative to Strings" by Boehm, et. al.
Software-Practice and Experience, Vol. 25(12), 1315-1330 (December 1995)
|
Method Summary |
ByteCord |
append(byte[] b)
|
ByteCord |
append(byte[] b,
int bOffset,
int bLength)
|
ByteCord |
append(ByteCord b,
long bOffset,
long bLength)
|
ByteCord |
delete(long cordOffset,
long length)
Remove a section of the byte cord starting at cordOffset, for length bytes. |
boolean |
equals(java.lang.Object v)
|
int |
get(byte[] b,
int bOffset,
int bLength,
long thisOffset)
|
byte |
get(long thisOffset)
|
ByteCord |
get(long thisOffset,
long length)
|
int |
hashCode()
|
ByteCord |
insert(byte[] b,
int bOffset,
int bLength,
long thisOffset)
|
ByteCord |
insert(byte[] b,
long thisOffset)
|
ByteCord |
insert(ByteCord b,
long bOffset,
long bLength,
long thisOffset)
Insert a subsection of another ByteCord into this byte cord at offset thisOffset. |
java.util.Iterator<java.lang.Byte> |
iterator()
|
java.util.Iterator<java.lang.Byte> |
iterator(long offset)
|
long |
length()
|
protected int |
maxDepth()
|
protected int |
minDepth()
|
protected ByteCord |
rebalance()
|
ByteCord |
set(byte[] b,
int bOffset,
int bLength,
long thisOffset)
|
ByteCord |
set(byte[] b,
long thisOffset)
|
ByteCord |
set(ByteCord b,
long bOffset,
long bLength,
long thisOffset)
|
ByteCord |
set(byte b,
long thisOffset)
|
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
EMPTY
public static final ByteCord EMPTY
ByteCord
protected ByteCord(ByteCord r)
ByteCord
public ByteCord(byte[] initial)
ByteCord
public ByteCord(byte[] initial,
int initialOffset,
int initialLength)
minDepth
protected int minDepth()
maxDepth
protected int maxDepth()
rebalance
protected ByteCord rebalance()
delete
public ByteCord delete(long cordOffset,
long length)
- Remove a section of the byte cord starting at cordOffset, for length bytes.
- Parameters:
cordOffset - the starting byte in the cord to remove(inclusive).length - the number of bytes to remove.
- Returns:
- ByteCord with bytes removed.
insert
public ByteCord insert(ByteCord b,
long bOffset,
long bLength,
long thisOffset)
- Insert a subsection of another ByteCord into this byte cord at offset thisOffset.
- Parameters:
b - ByteCord to insert.bOffset - offset in b to start at.bLength - number of bytes from b to insert.thisOffset - position in this bytecord to start inserting at.
- Returns:
- ByteCord with b inserted.
insert
public ByteCord insert(byte[] b,
long thisOffset)
insert
public ByteCord insert(byte[] b,
int bOffset,
int bLength,
long thisOffset)
set
public ByteCord set(ByteCord b,
long bOffset,
long bLength,
long thisOffset)
set
public ByteCord set(byte[] b,
long thisOffset)
set
public ByteCord set(byte[] b,
int bOffset,
int bLength,
long thisOffset)
set
public ByteCord set(byte b,
long thisOffset)
append
public ByteCord append(ByteCord b,
long bOffset,
long bLength)
append
public ByteCord append(byte[] b)
append
public ByteCord append(byte[] b,
int bOffset,
int bLength)
get
public ByteCord get(long thisOffset,
long length)
get
public int get(byte[] b,
int bOffset,
int bLength,
long thisOffset)
get
public byte get(long thisOffset)
length
public long length()
hashCode
public int hashCode()
- Overrides:
hashCode in class java.lang.Object
equals
public boolean equals(java.lang.Object v)
- Overrides:
equals in class java.lang.Object
iterator
public java.util.Iterator<java.lang.Byte> iterator()
- Specified by:
iterator in interface java.lang.Iterable<java.lang.Byte>
iterator
public java.util.Iterator<java.lang.Byte> iterator(long offset)