KJB

This class implements vectors, in the linearalgebra sense, restricted to integervalued elements. More...
#include <l_int_vector.h>
Public Types  
typedef int  Value_type 
data type of the elements More...  
typedef kjb_c::Int_vector  Impl_type 
the underlying implementation More...  
typedef Int_matrix  Mat_type 
the associated matrix type More...  
typedef Int_vector  Vec_type 
the associated vector type More...  
typedef Value_type(*  Mapper )(Value_type) 
element transformer fun More...  
typedef int  value_type 
typedef int *  pointer 
typedef const int *  const_pointer 
typedef int &  reference 
typedef int  const_reference 
typedef value_type *  iterator 
typedef const value_type *  const_iterator 
typedef std::reverse_iterator < iterator >  reverse_iterator 
typedef std::reverse_iterator < const_iterator >  const_reverse_iterator 
const Iterator type More...  
typedef int  size_type 
typedef int  difference_type 
Public Member Functions  
Int_vector (int length=0)  
Allocate vector of given length; contents are uninitialized. More...  
Int_vector (unsigned length)  
Allocate vector of given length; contents are uninitialized. More...  
Int_vector (unsigned long length)  
Allocate vector of given length; contents are uninitialized. More...  
Int_vector (int length, Value_type num)  
Allocate vector of given length; initialize all elts to 'num'. More...  
Int_vector (int length, const Value_type *data)  
Initialize from an array of int, of given length. More...  
Int_vector (Impl_type *vec_ptr)  
Conversion ctor: claim ownership of an existing int vector pointer (i.e., make a shallow copy). More...  
Int_vector (const std::vector< int > &src)  
Conversion ctor: Create from stlstyle vector. More...  
Int_vector (const Impl_type &vec_ref)  
Ctor copies contents (i.e., deep copy) of an existing vector. More...  
Int_vector (const Mat_type &src)  
Ctor builds from a onerow or onecolumn Int_matrix (making a deep copy). More...  
Int_vector (const std::string &file_name)  
Construct a vector by reading contents from a named file. More...  
Int_vector (const Int_vector &vec_ref)  
Copy ctor – calls the kjb_c function to copy an int vector. More...  
template<typename InputIterator_ >  
Int_vector (InputIterator_ begin_, InputIterator_ end_)  
"Range constructor" More...  
~Int_vector ()  
Destructor – which just calls the KJB destructor. More...  
int  get_length () const 
Return the length of the vector. More...  
size_type  size () const 
Alias to get_length(). Required to comply with stl Container concept. More...  
size_type  max_size () const 
Maximum size vector can ever have. Currently defined as INT_MAX. More...  
bool  empty () const 
Returns true iff size is zero. Required to comply with stl Container concept. More...  
iterator  begin () 
const_iterator  begin () const 
iterator  end () 
const_iterator  end () const 
reverse_iterator  rbegin () 
const_reverse_iterator  rbegin () const 
reverse_iterator  rend () 
const_reverse_iterator  rend () const 
void  reserve (int capacity) 
Int_vector &  randomize (int length) 
Clobber current vector; resize and fill with random values. More...  
Int_vector &  randomize () 
Clobber current vector contents with random values. More...  
Int_vector &  operator= (const Impl_type &vec_ref) 
Assignment operator: assign from a kjb_c::Int_vector, a C struct. More...  
Int_vector &  operator= (const Int_vector &src) 
Assignment operator: assign from a kjb::Int_vector, a C++ object. More...  
const Impl_type *  get_c_vector () const 
Get const pointer to the underlying kjb_c::Int_vector C struct. More...  
Impl_type *  get_underlying_representation_with_guilt () 
Get pointer to the underlying kjb_c::Vector C struct. More...  
void  swap (Int_vector &other) 
Swap the representations of two vectors. More...  
Int_vector &  resize (int new_length, Value_type pad=Value_type(0)) 
Resize vector, retaining previous values. More...  
Value_type &  operator[] (int i) 
Subscript vector like a C array, e.g., A[10], returning an lvalue. More...  
Value_type  operator[] (int i) const 
Subscript vector like a C array, e.g., A[10], returning an rvalue. More...  
Value_type &  operator() (int i) 
Fortranstyle vector subscript, e.g., A(10), to get an lvalue. More...  
Value_type  operator() (int i) const 
Fortranstyle vector subscript, e.g., A(10), to get an rvalue. More...  
void  check_bounds (int i) const 
Test whether a subscript is valid, throw an exception if not. More...  
Value_type &  at (int i) 
Safely subscript vector, e.g., A.at(10), to get an lvalue. More...  
Value_type  at (int i) const 
Safely subscript vector, e.g., A.at(10), to get an rvalue. More...  
iterator  insert (iterator position, value_type t) 
A copy of t is inserted before position. More...  
void  insert (iterator position, size_type N, value_type t) 
Insert N copies of t before position. More...  
template<typename InputIterator >  
void  insert (iterator position, InputIterator begin_, InputIterator end_) 
Insert range [begin, end) before position. More...  
iterator  erase (iterator position) 
erase element at position and shift all elements after p up by 1. More...  
void  erase (iterator begin_, iterator end_) 
erase all elements beginning with begin_ up to but not including end_ More...  
void  clear () 
delete all elements from vector More...  
reference  front () 
Returns the first element of the vector. More...  
const_reference  front () const 
Returns the first element of the vector. More...  
reference  back () 
Returns the last element of the vector. More...  
const_reference  back () const 
Returns the last element of the vector. More...  
void  push_back (Value_type x) 
inserts an element at the back of the vector in amortized constant time. More...  
void  pop_back () 
Returns the last element of the vector. More...  
void  write_row (const char *filename=0) const 
Write vector as a row to a file, or to standard output. More...  
void  write_col (const char *filename=0) const 
Write vector as a column to a file, or to standard output. More...  
void  write (const char *filename=0) const 
Write vector to a file, or to standard output. More...  
Int_vector &  operator*= (Value_type op2) 
Scalar multiply self, inplace, e.g., v *= 6. More...  
Int_vector &  multiply (Value_type op2) 
Scalar multiply self, inplace, just like v *= 6. More...  
Int_vector &  operator/= (Value_type op2) 
Scalar integer division of self, inplace. More...  
Int_vector &  divide (Value_type op2) 
Scalar integer division of self, inplace, just like v /= 2. More...  
Int_vector &  operator+= (const Int_vector &op2) 
Add vector to self, inplace, e.g., v += delta_v. More...  
Int_vector &  add (const Int_vector &op2) 
Add vector to self, inplace, just like v += delta_v. More...  
Int_vector &  operator= (const Int_vector &op2) 
Subtract vector from self, inplace, e.g., v = delta_v. More...  
Int_vector &  subtract (const Int_vector &op2) 
Subtract vector from self, inplace, just like v = delta_v. More...  
Int_vector &  negate () 
Negate self, inplace, just like v *= (1). More...  
Vec_type &  mapcar (Mapper) 
Transform the elements of a vector. More...  
Value_type  min () const 
Return the value of the minimum element in the vector. More...  
Value_type  min (int *min_index) const 
Find minimum element in the vector, both its value and index. More...  
Value_type  max () const 
Return the value of the maximum element in the vector. More...  
Value_type  max (int *max_index) const 
Find maximum element in the vector, both its value and index. More...  
Int_vector &  cross_with (const Int_vector &op2) 
Compute (in place) cross product of this vector and op2. More...  
kjb::Int_matrix  hat () const 
Construct an "equivalent" skewsymmetric matrix from 3vector. More...  
double  magnitude () const 
Return this vector's magnitude. More...  
long int  magnitude_squared () const 
Return this vector's squared magnitude. More...  
This class implements vectors, in the linearalgebra sense, restricted to integervalued elements.
For better maintainability, refer to the element type using this class's Value_type typedef, instead of referring to 'int' directly.
Most methods of this class are implemented in the C language portion of the KJB library, with this class forming a thin (usually inlined) layer.
typedef const value_type* kjb::Int_vector::const_iterator 
typedef const int* kjb::Int_vector::const_pointer 
typedef int kjb::Int_vector::const_reference 
typedef std::reverse_iterator<const_iterator> kjb::Int_vector::const_reverse_iterator 
const Iterator type
typedef int kjb::Int_vector::difference_type 
typedef kjb_c::Int_vector kjb::Int_vector::Impl_type 
the underlying implementation
typedef value_type* kjb::Int_vector::iterator 
typedef Value_type(* kjb::Int_vector::Mapper)(Value_type) 
element transformer fun
typedef Int_matrix kjb::Int_vector::Mat_type 
the associated matrix type
typedef int* kjb::Int_vector::pointer 
typedef int& kjb::Int_vector::reference 
typedef std::reverse_iterator<iterator> kjb::Int_vector::reverse_iterator 
typedef int kjb::Int_vector::size_type 
typedef int kjb::Int_vector::Value_type 
data type of the elements
typedef int kjb::Int_vector::value_type 
typedef Int_vector kjb::Int_vector::Vec_type 
the associated vector type

inlineexplicit 
Allocate vector of given length; contents are uninitialized.
This also serves as a default ctor

inlineexplicit 
Allocate vector of given length; contents are uninitialized.
This ctor is almost mandatory since we want to construct from a size_t, which on most platforms is unsigned int or unsigned long int.

inlineexplicit 
Allocate vector of given length; contents are uninitialized.
This ctor is almost mandatory since we want to construct from a size_t, which on most platforms is unsigned int or unsigned long int.

inline 
Allocate vector of given length; initialize all elts to 'num'.

inline 
Initialize from an array of int, of given length.

inline 
Conversion ctor: claim ownership of an existing int vector pointer (i.e., make a shallow copy).
This method is the proper way to say, ''Here is a kjb_c::Int_vector struct that I am responsible for deleting, and I must make sure that it gets destroyed when it goes out of scope.'' This is a good way to wrap a vector "dynamically," after it has already been created.
Anyplace you find yourself using free_int_vector() in your C++ code, you should consider using instead this Vector class with this ctor.
If the input pointer equals NULL then a zero length vector is constructed.

inline 
Conversion ctor: Create from stlstyle vector.

inlineexplicit 
Ctor copies contents (i.e., deep copy) of an existing vector.
This kind of conversion is relatively expensive, thus we restrict its use only to explicit invocation.

inline 
Copy ctor – calls the kjb_c function to copy an int vector.
Although this method is essential, I hope it is seldom actually used. Most of the time it should be unnecessary or optimized away somehow.

inline 
"Range constructor"

inline 
Destructor – which just calls the KJB destructor.

inline 
Add vector to self, inplace, just like v += delta_v.

inline 
Safely subscript vector, e.g., A.at(10), to get an lvalue.
"Safely" here means we do bounds checking and throw if out of bounds.

inline 
Safely subscript vector, e.g., A.at(10), to get an rvalue.
"Safely" here means we do bounds checking and throw if out of bounds.

inline 
Returns the last element of the vector.

inline 
Returns the last element of the vector.

inline 
Returns a read/write iterator that points to the first element in the Vector. Iteration is done in ordinary element order.

inline 
Returns a readonly (constant) iterator that points to the first element in the Vector. Iteration is done in ordinary element order.

inline 
Test whether a subscript is valid, throw an exception if not.
Index_out_of_bounds  with a message, if the index is bad. 

inline 
delete all elements from vector

inline 
Scalar integer division of self, inplace, just like v /= 2.

inline 
Returns true iff size is zero. Required to comply with stl Container concept.

inline 
Returns a read/write iterator that points one past the last element in the Vector. Iteration is done in ordinary element order.

inline 
Returns a readonly (constant) iterator that points one past the last element in the Vector. Iteration is done in ordinary element order.
erase element at position and shift all elements after p up by 1.
erase all elements beginning with begin_ up to but not including end_

inline 
Returns the first element of the vector.

inline 
Returns the first element of the vector.

inline 
Get const pointer to the underlying kjb_c::Int_vector C struct.

inline 
Return the length of the vector.

inline 
Get pointer to the underlying kjb_c::Vector C struct.
iterator kjb::Int_vector::insert  (  iterator  position, 
value_type  t  
) 
A copy of t is inserted before position.
void kjb::Int_vector::insert  (  iterator  position, 
size_type  N,  
value_type  t  
) 
Insert N copies of t before position.

inline 
Return this vector's magnitude.

inline 
Return this vector's squared magnitude.

inline 
Return the value of the maximum element in the vector.

inline 
Find maximum element in the vector, both its value and index.
This will search for the maximum value in the vector, and return that value. Also this method can work like an argmax function, and emit the index of a location containing that value.
[out]  max_index  Pointer to a location to store the index of the maximum value. If it equals null, then this method behaves the same as max(). 
Result_error  if the vector has size of zero 
The vector might store the maximum value in more than one location. In that case, the value in *max_index will store one of the locations, but it is undefined which one.

inline 
Maximum size vector can ever have. Currently defined as INT_MAX.

inline 
Return the value of the minimum element in the vector.

inline 
Find minimum element in the vector, both its value and index.
This will search for the minimum value in the vector, and return that value. Also this method can work like an argmin function, and emit the index of a location containing that value.
[out]  min_index  Pointer to a location to store the index of the minimum value. If it equals null, then this method behaves the same as min(). 
Result_error  if the vector has size of zero 
The vector might store the minimum value in more than one location. In that case, the value in *min_index will store one of the locations, but it is undefined which one.

inline 
Scalar multiply self, inplace, just like v *= 6.

inline 
Negate self, inplace, just like v *= (1).

inline 
Fortranstyle vector subscript, e.g., A(10), to get an lvalue.

inline 
Fortranstyle vector subscript, e.g., A(10), to get an rvalue.

inline 
Scalar multiply self, inplace, e.g., v *= 6.

inline 
Add vector to self, inplace, e.g., v += delta_v.

inline 
Subtract vector from self, inplace, e.g., v = delta_v.

inline 
Assignment operator: assign from a kjb_c::Int_vector, a C struct.

inline 
Assignment operator: assign from a kjb::Int_vector, a C++ object.

inline 
Subscript vector like a C array, e.g., A[10], returning an lvalue.

inline 
Subscript vector like a C array, e.g., A[10], returning an rvalue.

inline 
Returns the last element of the vector.

inline 
inserts an element at the back of the vector in amortized constant time.

inline 
Clobber current vector contents with random values.
Random values are uniformly distributed between 0 and RAND_MAX.

inline 
Returns a read/write reverse iterator that points to the last element in the Vector. Iteration is done in reverse element order.

inline 
Returns a readonly (constant) reverse iterator that points to the last element in the Vector. Iteration is done in reverse element order.

inline 
Returns a read/write reverse iterator that points to one before the first element in the Vector. Iteration is done in reverse element order.

inline 
Returns a readonly (constant) reverse iterator that points to one before the first element in the Vector. Iteration is done in reverse element order.

inline 
After calling, the vector will be able to contain capacity elements without needing to resize itself.

inline 
Alias to get_length(). Required to comply with stl Container concept.

inline 
Subtract vector from self, inplace, just like v = delta_v.

inline 
Swap the representations of two vectors.

inline 
Write vector to a file, or to standard output.
If filename equals NULL or filename[0] is the null character then the output is directed to standard output.

inline 
Write vector as a column to a file, or to standard output.
If filename equals NULL or filename[0] is the null character then the output is directed to standard output.

inline 
Write vector as a row to a file, or to standard output.
If filename equals NULL or filename[0] is a null character then the output is directed to standard output.