Commit Graph

1 Commits

Author SHA1 Message Date
Paul Bone
ab44bbad3f Use a better algorithm for unwinding version_arrays.
The old version_array rewind code used linear stack space in order to
perform it's updates in the right order (newest to oldest) by following the
structure's next pointers (which are a oldest to newest list).  I previously
introduced week prev pointers so that walking over this structure newest to
oldest could be done with constant stack space.  However that is less
efficient than the method suggested by Peter Wang.

Peter suggested using a bitmap and traversing oldest-to-newest, marking
each update in the bitmap and checking the bitmap before making any update.
Thus preserving older values over newer ones (which is good, this code
_rewinds_ updates).  This patch implements Peter's suggestion and removes
the prev pointers from the structure for C and Java backends.

Thanks to Peter Wang for giving me a hand with C#.

library/version_array.m:
    As above.

runtime/mercury_bitmap.h:
    Add some macros for initialising bitmaps and testing, setting and clearing
    their bits.

library/bitmap.m:
java/runtime/MercuryBitmap.java:
    Move the Java MercuryBitmap class into the runtime library.  This makes
    it easier for other standard library modules to use this Java class.

library/bitmap.m:
runtime/mercury_dotnet.cs.in:
    Move C# MercuryBitmap class into runtime/mercury_dotnet.cs

library/bitmap.m:
    Add extra methods to the C# MercuryBitmap class.

tests/hard_coded/version_array_test.exp:
tests/hard_coded/version_array_test.m:
    Ensure that the test verifies that rolling back updates to a version
    array rolls back changes in the correct order: If two updates modify the
    same cell, then the older one should be visible in the result.

    Use longer arrays so that the bitmap used in the rollback code is more
    than one byte in length.
2014-09-10 12:04:53 +10:00