andraskovacs / dynamic-mvector Goto Github PK
View Code? Open in Web Editor NEWA wrapper around MVector that enables push/pop/append functionality.
License: Other
A wrapper around MVector that enables push/pop/append functionality.
License: Other
Looking at the code of readBack
-- | Read the back value. Throws an error if the vector is empty.
readBack :: PrimMonad m => MVector (PrimState m) a -> m a
readBack (MVector v) = do
MVectorData s v <- readMutVar v
if (s <= 0) then
error "Data.Vector.Mutable.Dynamic: reading the back of an empty vector"
else
MV.unsafeRead v (MV.length v - 1)
{-# INLINABLE readBack #-}
Shouldn't last line of code be MV.unsafeRead v (s-1)
?
Today, new and safeNew return a vector of length equal to its capacity, but the notion of length is the count of valid elements so it should be zero in this case because elements are uninitialized.
I think it is more in line with what implementations of the C++ STL do... but I agree that it is debatable.
My view is that I prefer that the capacity is kept to not waste time reallocating when the vector grows again.
I created unit tests for the few functions I use:
https://github.com/OlivierSohn/hamazed/blob/master/test/Test/Vector.hs
It's testing this reduced version, adapted to support Unboxed vectors and where a sort function was added:
https://github.com/OlivierSohn/hamazed/blob/master/src/Render/Delta/DynUnboxedVec.hs
I think this package would benefit from implementing that kind of tests, both to document the behaviour and to test against regressions.
The problem is that the when
guard to check if we need to shrink the vector is also guarding the writeMutVar
invocation that decrements the size of the vector. Instead, the size needs to be decremented unconditionally.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.