Skip to content

Commit

Permalink
Added Overwrite functionality to memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftioon authored Mar 26, 2024
1 parent bd66f02 commit 767b60c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/quojo/quantum.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ struct QuantumGates:

fn H(borrowed self, other: Qubit) raises -> Qubit:
return self.Hadamard(other)

fn X(borrowed self, other: Qubit) raises -> Qubit:
return self.PauliX(other)

Expand Down
26 changes: 23 additions & 3 deletions src/quojo/quantumComputer.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct QMC: #Quantum Memory Cells
for i in range(start, start+size):
self.data[i] = comp.ComplexNum(0,0)

fn write(inout self, contents: Q.Qubit, mode: String) raises:
fn write(inout self, contents: Q.Qubit, mode: String, address: Int = 0) raises:
if mode == "a":
var size = 2

Expand All @@ -39,13 +39,33 @@ struct QMC: #Quantum Memory Cells

self.top += size
self.addresses.push_back(self.top)

if mode == "o":
var size = 2
var start = self.addresses[address]
self.delete(address)

for i in range(start, start + size):
self.data[i] = contents.qubit[0, i - start]


fn write(inout self, contents: Q.Qudit, mode: String) raises:
fn write(inout self, contents: Q.Qudit, mode: String, address: Int = 0) raises:
if mode == "a":
var size = contents.qudit.cols

for i in range(size):
self.data[self.top + i] = contents.qudit[0, i]

self.top += size
self.addresses.push_back(self.top)
self.addresses.push_back(self.top)

if mode == "o":
var addrSize = self.addresses[address + 1] - self.addresses[address]
var size = contents.qudit.cols
if size > addrSize:
raise("Given contents too big, cannot overwrite")
var start = self.addresses[address]
self.delete(address)

for i in range(start, start + size):
self.data[i] = contents.qudit[0, i - start]

0 comments on commit 767b60c

Please sign in to comment.