use of suite.primitive.Bytes in project suite by stupidsing.
the class TextUtil method patch.
public Bytes patch(Bytes bytes, List<Pair<Bytes, Bytes>> pairs) throws ConflictException {
BytesBuilder bb = new BytesBuilder();
int p = 0;
for (Pair<Bytes, Bytes> pair : pairs) {
int p1 = p + pair.t0.size();
if (Objects.equals(bytes.range(p, p1), pair.t0))
bb.append(pair.t1);
else
throw new ConflictException();
p = p1;
}
return bb.toBytes();
}
use of suite.primitive.Bytes in project suite by stupidsing.
the class RollingHashUtilTest method test2.
@Test
public void test2() {
Bytes bytes = To.bytes("0123456789abcdef");
int size = bytes.size();
int rollingHash = rollingHashUtil.hash(bytes.range(0, 10));
for (int pos = 10; pos < size; pos++) {
rollingHash = rollingHashUtil.unroll(rollingHash, bytes.get(pos - 10), 10);
rollingHash = rollingHashUtil.roll(rollingHash, bytes.get(pos));
}
assertEquals(rollingHashUtil.hash(bytes.range(size - 10)), rollingHash);
}
use of suite.primitive.Bytes in project suite by stupidsing.
the class BootMain method run.
@Override
protected boolean run(String[] args) throws IOException {
Bytes bootLoader = new Assembler(16).assemble(FileUtil.read("src/main/asm/bootloader.asm"));
Bytes kernel = new ImperativeCompiler().compile(0x40000, Paths.get("src/main/il/kernel.il"));
if (bootLoader.size() == 512 && kernel.size() < 65536) {
// combine the images and align to 512 bytes
Bytes disk0 = Bytes.concat(bootLoader, kernel);
Bytes disk1 = disk0.pad(disk0.size() + 511 & 0xFFFFFE00);
String image = "target/boot.bin";
Files.write(Paths.get(image), disk1.toArray());
System.out.println("cat " + image + " | dd bs=512 count=1 | /opt/udis86-1.7.2/udcli/udcli -16 | less");
System.out.println("cat " + image + " | dd bs=512 skip=1 | /opt/udis86-1.7.2/udcli/udcli -32 | less");
System.out.println("qemu-system-x86_64 target/boot.bin");
return true;
} else
return Fail.t("size not match");
}
use of suite.primitive.Bytes in project suite by stupidsing.
the class AllocatorImpl method updateAllocMap.
private void updateAllocMap(int start, int end, byte b) {
while (start < end) {
int p = start / pageSize;
int s = p * pageSize;
int e = s + pageSize;
int end_ = min(e, end);
int p0 = 0;
int p1 = start - s;
int p2 = end_ - s;
int p3 = pageSize;
Bytes bytes = allocMapFile.load(p);
BytesBuilder bb = new BytesBuilder();
bb.append(bytes.range(p0, p1));
for (int i = p1; i < p2; i++) bb.append(b);
bb.append(bytes.range(p2, p3));
allocMapFile.save(p, bb.toBytes());
start = end_;
}
}
use of suite.primitive.Bytes in project suite by stupidsing.
the class FileFactory method extentFile.
public static ExtentFile extentFile(PageFile pf) {
Serialize serialize = Serialize.me;
Serializer<Extent> extentSerializer = serialize.extent();
Serializer<Bytes> bytesSerializer = serialize.variableLengthBytes;
SerializedPageFile<Block> pageFile = SerializedFileFactory.serialized(pf, new Serializer<>() {
public Block read(DataInput_ dataInput) throws IOException {
Extent extent = extentSerializer.read(dataInput);
Bytes bytes = bytesSerializer.read(dataInput);
return new Block(extent, bytes);
}
public void write(DataOutput_ dataOutput, Block block) throws IOException {
extentSerializer.write(dataOutput, block.extent);
bytesSerializer.write(dataOutput, block.bytes);
}
});
return new ExtentFile() {
public void close() throws IOException {
pageFile.close();
}
public void sync() {
pageFile.sync();
}
public Bytes load(Extent extent) {
BytesBuilder bb = new BytesBuilder();
for (int pointer = extent.start; pointer < extent.end; pointer++) {
Block block = pageFile.load(pointer);
Util.assert_(Objects.equals(block.extent, extent));
bb.append(block.bytes);
}
return bb.toBytes();
}
public void save(Extent extent, Bytes bytes) {
for (int pointer = extent.start, p = 0; pointer < extent.end; pointer++) {
int p1 = p + blockSize;
pageFile.save(pointer, new Block(extent, bytes.range(p, p1)));
p = p1;
}
}
public List<Extent> scan(int start, int end) {
List<Extent> extents = new ArrayList<>();
int pointer = start;
while (pointer < end) {
Extent extent = pageFile.load(pointer).extent;
if (start <= extent.start && extent.end <= end)
extents.add(extent);
pointer = extent.end;
}
return extents;
}
};
}
Aggregations