Skip to content

Instantly share code, notes, and snippets.

@ashkrit
Last active June 23, 2020 14:40
Show Gist options
  • Select an option

  • Save ashkrit/5c8306fc44b1d0cb4b1d1e5ab77ec69a to your computer and use it in GitHub Desktop.

Select an option

Save ashkrit/5c8306fc44b1d0cb4b1d1e5ab77ec69a to your computer and use it in GitHub Desktop.
public void restoreDisk() {
RaidDisk disk1 = new RaidDisk(2);
disk1.set(0, MoreInts.toByte("01101101"));
disk1.set(1, MoreInts.toByte("00101101"));
RaidDisk disk2 = new RaidDisk(1);
disk2.set(0, MoreInts.toByte("11010100"));
RaidDisk raidDisk = disk1.xor(disk2); // This xor allow to keep data for both disk in RaidDisk
RaidDisk newDisk1 = raidDisk.xor(disk2); // If we loose disk1 then disk1 can be restore using raidDisk ^ disk2
RaidDisk newDisk2 = raidDisk.xor(disk1);
assertEquals(disk1.toBinary(), newDisk1.toBinary());
assertEquals(disk2.toBinary(), newDisk2.toBinary());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment