Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

63 lines (51 sloc) 1.524 kb
module virtualoffset;
import std.conv;
/// Structure representing virtual offset in BAM file.
struct VirtualOffset {
/// Params:
///
/// coffset = unsigned byte offset into the BGZF file
/// to the beginning of a BGZF block.
/// Must be strictly less than 2^48.
///
/// uoffset = unsigned byte offset into the uncompressed
/// data stream represented by that BGZF block
this(ulong coffset, ushort uoffset)
in {
assert(coffset < (1UL<<48));
}
body {
voffset = (coffset << 16) | uoffset;
}
/// Set both coffset and uoffset packed as (coffset<<16)|uoffset
this(ulong voffset) {
this.voffset = voffset;
}
/// ditto
ulong coffset() @property {
return voffset >> 16;
}
/// ditto
ushort uoffset() @property {
return voffset & 0xFFFF;
}
int opCmp(VirtualOffset other) {
if (this.voffset > other.voffset) { return 1; }
if (this.voffset < other.voffset) { return -1; }
return 0;
}
int opCmp(ulong voffset) {
return opCmp(VirtualOffset(voffset));
}
/// String representation in format "<coffset>/<uoffset>"
string toString() {
return to!string(coffset) ~ "/" ~ to!string(uoffset);
}
private:
ulong voffset;
}
unittest {
auto voffset = VirtualOffset(100500, 42);
assert(voffset.coffset == 100500);
assert(voffset.uoffset == 42);
}
Jump to Line
Something went wrong with that request. Please try again.