vmware-archive / go-pmem-transaction

Golang library for using persistent memory
Other
29 stars 5 forks source link

API Update for Log & ReadLog methods of undo/redo transactions #12

Closed mohit10verma closed 5 years ago

mohit10verma commented 5 years ago

With this change, undo & redo log will support same API to Log & read back the values. ReadLog() now also supports reading back slices, slice elements & reslicing.

Updates to Log() API For Logging, the old usage was:

//undoTx
undoTx.Log(&a)
a = 10.1
//redoTx
redoTx.Log(&a,10.1)

New usage: tx.Log(&a, 10.1) // does the a = 10.1 operation internally if tx == undoTx

For undo transactions, the old usage is also supported. So, both of the following are valid & do the same thing:

// OLD WAY, STILL WORKS
undoTx.Log(&a)
a = 10.1
// NEW WAY, DOES SAME THING
undoTx.Log(&a, 10.1)

Updates to ReadLog() API. Works for both undo/redo tx

  1. Slice elements can be read as follows: f := tx.ReadLog(&slice1, 10).(float64) // Same as f := s slice1[10]
  2. Slices can be read as follows: s := tx.ReadLog(&slice1, 2,5).([]float64) // Same as f := slice1[2:5] t := tx.ReadLog(&slice2) // Same as t := slice2