Miranor Widget Store


You have to be logged in to use this function.


   Create New Account ˖ Forgot password?
MVECTOR (Logic App)Buy this Widget!
10 Credits

Miranor::MVector is a linear ordered sequence of generic elements, which allows to append/remove elements to/from the tail at O(1) time on average. Similar to std::vector, but easier to use, and more efficient in both time and space (especially when it comes to iterators). In particular, you can pass MVector object by value with practically no performance penalty thanks to its shared copy mechanism. Before modifying a shared copy, it must be unshared, or all shared objects will be modified by this operation. However, unsharing is automatic and completely transparent to the developer, so generally you don't have to worry about it. The only concern is that some operations like removal, which should ordinarily never fail, can now fail due to insufficient memory (even though it's unlikely), because unsharing requires extra memory. Therefore, all mutators return 'true' on success and 'false' on failure, except setError, which never fails. A failure is either a memory error or a numeric overflow (kind of the same thing).
MVector defines CIter and Iter child classes, which allow to iterate on all the elements. These iterators are more convenient and more efficient than those defined in STL, and safer too, especially in DEBUG mode.
The getError member function returns 'true' between setError(true) and setError(false). If a mutator returns 'false', setError(true) is called automatically, so getError can be used to find out if there has been an error since the last call to setError(false) or since MVector's creation (error flag is initially false). Invalid parameters can be handled in most cases. If they can't, then an exception is thrown.
Another interesting quality of MVector is that an empty collection always consists of a memory block filled with zeros. In particular this means that an empty collections never allocates memory. This quality is important for safety (even uninitialized static variable thus has a legal value), and for some other purposes too.

Author: Dimitry Rotstein

Tags: vector, array, dynamic array, data structure, class, template, sequence, collection

Code preview:

#ifndef MIRANOR_VECTOR_CLASS #define MIRANOR_VECTOR_CLASS #include <new> // For operator "placement new" #include <algorithm> // For 'sort' namespace Miranor { // Basic definitions typedef unsigned long MNum; // 32 or 64 bit integer (depending on OS) const MNum MaxNum = MNum(-1);

***************Buy the widget to get the rest of the code***************

Miranor Home | About Miranor | About Elgrint | Create account | Login | Account settings | Contact Us | Privacy Policy | Site map

© Copyright 2014 by Miranor. All rights reserved. By using this site you agree to the Terms of Use.

Page last updated on August 10th, 2014.

Real Time Web Analytics