Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Example of a class wrapping an STL vector
EXAMPLES::
sage: from sage.tests.stl_vector import stl_int_vector sage: v = stl_int_vector() sage: v A vector of integers vector<int>: data[0] = 123 data[1] = 456
AUTHORS:
- Volker Braun (2012-01-18): initial version """
#***************************************************************************** # Copyright (C) 2012 Volker Braun <vbraun.name@gmail.com> # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ #*****************************************************************************
from cysignals.signals cimport sig_on, sig_off
from sage.structure.sage_object cimport SageObject from sage.rings.integer cimport Integer from sage.libs.gmp.mpz cimport mpz_add_ui from libcpp.vector cimport vector from libcpp.string cimport string from sage.structure.richcmp cimport richcmp_not_equal, rich_to_bool
cdef class stl_int_vector(SageObject): """ Example class wrapping an STL vector
EXAMPLES::
sage: from sage.tests.stl_vector import stl_int_vector sage: v = stl_int_vector() """
cdef vector[int] *data cdef string *name
def __cinit__(self): """ The Cython constructor.
EXAMPLES::
sage: from sage.tests.stl_vector import stl_int_vector sage: v = stl_int_vector() # indirect doctest sage: TestSuite(v) Test suite for A vector of integers vector<int>: data[0] = 123 data[1] = 456 """
def __dealloc__(self): """ The Cython destructor.
EXAMPLES::
sage: from sage.tests.stl_vector import stl_int_vector sage: v = stl_int_vector() # indirect doctest """ del self.data del self.name
def __getitem__(self, int i): """ Return the ``i``-th element.
EXAMPLES::
sage: from sage.tests.stl_vector import stl_int_vector sage: v = stl_int_vector() sage: v[1] 456 """
def __repr__(self): """ Return a string representation.
EXAMPLES::
sage: from sage.tests.stl_vector import stl_int_vector sage: v = stl_int_vector() sage: v A vector of integers vector<int>: data[0] = 123 data[1] = 456 """
cpdef sum(self): """ Add the elements.
EXAMPLES::
sage: from sage.tests.stl_vector import stl_int_vector sage: v = stl_int_vector() sage: v.sum() 579 """
def __richcmp__(left, stl_int_vector right, int op): """ Compare with ``other``.
EXAMPLES::
sage: from sage.tests.stl_vector import stl_int_vector sage: u = stl_int_vector() sage: v = stl_int_vector() sage: u == v True """
return richcmp_not_equal(lx, rx, op)
return richcmp_not_equal(left_i, right_i, op) finally: |