IndexOf< T > Class Template Reference

A contiguous, one-dimensional array of integers used to represent data structures, rather than numerical data in the arrays themselves. More...

#include <Index.h>

Inheritance diagram for IndexOf< T >:
Index

Public Member Functions

 IndexOf (const std::shared_ptr< T > &ptr, int64_t offset, int64_t length, kernel::lib ptr_lib)
 Creates an IndexOf from a full set of parameters. More...
 
 IndexOf (int64_t length, kernel::lib ptr_lib=kernel::lib::cpu)
 Allocates a new integer array buffer with a given length. More...
 
bool is_empty_advanced () const
 Returns true if this is an empty 'advanced' index. More...
 
const std::shared_ptr< T > ptr () const
 Reference-counted pointer to the integer array buffer. More...
 
kernel::lib ptr_lib () const
 The Kernel Library that ptr uses. More...
 
T * data () const
 Raw pointer to the beginning of data (i.e. offset accounted for). More...
 
int64_t offset () const
 Location of item zero in the buffer, relative to ptr, measured in the number of elements. More...
 
int64_t length () const
 Number of elements in the array. More...
 
const std::string classname () const
 User-friendly name of this class: "Index8", "IndexU8", "Index32", "IndexU32", or "Index64". More...
 
const std::string tostring () const
 Returns a string representation of this array (single-line XML). More...
 
const std::string tostring_part (const std::string &indent, const std::string &pre, const std::string &post) const
 Internal function to build an output string for tostring. More...
 
Form form () const
 Returns the enum describing this Index's integer specialization. More...
 
getitem_at (int64_t at) const
 Returns the element at a given position in the array, handling negative indexing and bounds-checking like Python. More...
 
getitem_at_nowrap (int64_t at) const
 Returns the element at a given position in the array, without handling negative indexing or bounds-checking. More...
 
void setitem_at_nowrap (int64_t at, T value) const
 Assigns an integer value (type T) in-place. More...
 
IndexOf< T > getitem_range (int64_t start, int64_t stop) const
 Subinterval of this array, handling negative indexing and bounds-checking like Python. More...
 
IndexOf< T > getitem_range_nowrap (int64_t start, int64_t stop) const
 Subinterval of this array, without handling negative indexing or bounds-checking. More...
 
void nbytes_part (std::map< size_t, int64_t > &largest) const
 Internal function used to calculate Content::nbytes. More...
 
const std::shared_ptr< Indexshallow_copy () const override
 Copies this Index node without copying its buffer. More...
 
IndexOf< int64_t > to64 () const override
 Converts this Index to an Index64. More...
 
bool iscontiguous () const override
 Returns true if this index is contiguous false otherwise. More...
 
const IndexOf< T > deep_copy () const
 Copies this Index node and all the data in its buffer. More...
 
const IndexOf< T > copy_to (kernel::lib ptr_lib) const
 
bool referentially_equal (const IndexOf< T > &other) const
 
- Public Member Functions inherited from Index
virtual ~Index ()
 Virtual destructor acts as a first non-inline virtual function that determines a specific translation unit in which vtable shall be emitted. More...
 

Static Public Member Functions

static IndexOf< T > empty_advanced ()
 Create a zero-length index representing an empty 'advanced' index. More...
 
- Static Public Member Functions inherited from Index
static Form str2form (const std::string &str)
 Converts a string into a Form enumeration. More...
 
static const std::string form2str (Form form)
 Converts a Form enumeration into a string. More...
 

Additional Inherited Members

- Public Types inherited from Index
enum  Form {
  i8, u8, i32, u32,
  i64, kNumIndexForm
}
 Integer type of an Index, used by ListForm, IndexedForm, etc. More...
 

Detailed Description

template<typename T>
class awkward::IndexOf< T >

A contiguous, one-dimensional array of integers used to represent data structures, rather than numerical data in the arrays themselves.

The Index superclass abstracts over templated specializations:

Constructor & Destructor Documentation

◆ IndexOf() [1/2]

IndexOf ( const std::shared_ptr< T > &  ptr,
int64_t  offset,
int64_t  length,
kernel::lib  ptr_lib 
)

Creates an IndexOf from a full set of parameters.

Parameters
ptrReference-counted pointer to the integer array buffer.
offsetLocation of item zero in the buffer, relative to ptr, measured in the number of elements. We keep this information in two parameters (ptr and offset) rather than moving ptr so that ptr can be reference counted among all arrays that use the same buffer.
lengthNumber of elements in the array.
Choosethe Kernel Library for this array, default:= kernel::lib::cpu

◆ IndexOf() [2/2]

IndexOf ( int64_t  length,
kernel::lib  ptr_lib = kernel::lib::cpu 
)

Allocates a new integer array buffer with a given length.

Member Function Documentation

◆ classname()

const std::string classname ( ) const

User-friendly name of this class: "Index8", "IndexU8", "Index32", "IndexU32", or "Index64".

◆ copy_to()

const IndexOf<T> copy_to ( kernel::lib  ptr_lib) const

◆ data()

T* data ( ) const

Raw pointer to the beginning of data (i.e. offset accounted for).

◆ deep_copy()

const IndexOf<T> deep_copy ( ) const

Copies this Index node and all the data in its buffer.

See also shallow_copy.

◆ empty_advanced()

static IndexOf<T> empty_advanced ( )
static

Create a zero-length index representing an empty 'advanced' index.

◆ form()

Form form ( ) const

Returns the enum describing this Index's integer specialization.

◆ getitem_at()

T getitem_at ( int64_t  at) const

Returns the element at a given position in the array, handling negative indexing and bounds-checking like Python.

The first item in the array is at 0, the second at 1, the last at -1, the penultimate at -2, etc.

◆ getitem_at_nowrap()

T getitem_at_nowrap ( int64_t  at) const

Returns the element at a given position in the array, without handling negative indexing or bounds-checking.

◆ getitem_range()

IndexOf<T> getitem_range ( int64_t  start,
int64_t  stop 
) const

Subinterval of this array, handling negative indexing and bounds-checking like Python.

The first item in the array is at 0, the second at 1, the last at -1, the penultimate at -2, etc.

Ranges beyond the array are not an error; they are trimmed to start = 0 on the left and stop = length() - 1 on the right.

This operation only affects the node metadata; its calculation time does not scale with the size of the array.

◆ getitem_range_nowrap()

IndexOf<T> getitem_range_nowrap ( int64_t  start,
int64_t  stop 
) const

Subinterval of this array, without handling negative indexing or bounds-checking.

If the array has Identities, the identity bounds are checked.

This operation only affects the node metadata; its calculation time does not scale with the size of the array.

◆ is_empty_advanced()

bool is_empty_advanced ( ) const

Returns true if this is an empty 'advanced' index.

◆ iscontiguous()

bool iscontiguous ( ) const
overridevirtual

Returns true if this index is contiguous false otherwise.

Implements Index.

◆ length()

int64_t length ( ) const

Number of elements in the array.

◆ nbytes_part()

void nbytes_part ( std::map< size_t, int64_t > &  largest) const

Internal function used to calculate Content::nbytes.

Parameters
largestThe largest range of bytes used in each reference-counted pointer (size_t).
Note
This method of accounting for overlapping buffers is insufficient: two nodes could use parts of the same buffer in which one doesn't completely overlap the other. It's not likely, but currently the calculation of Content::nbytes is an underestimate.

◆ offset()

int64_t offset ( ) const

Location of item zero in the buffer, relative to ptr, measured in the number of elements.

We keep this information in two parameters (ptr and offset) rather than moving ptr so that ptr can be reference counted among all arrays that use the same buffer.

◆ ptr()

const std::shared_ptr<T> ptr ( ) const

Reference-counted pointer to the integer array buffer.

◆ ptr_lib()

kernel::lib ptr_lib ( ) const

The Kernel Library that ptr uses.

◆ referentially_equal()

bool referentially_equal ( const IndexOf< T > &  other) const

◆ setitem_at_nowrap()

void setitem_at_nowrap ( int64_t  at,
value 
) const

Assigns an integer value (type T) in-place.

This modifies the array itself.

◆ shallow_copy()

const std::shared_ptr<Index> shallow_copy ( ) const
overridevirtual

Copies this Index node without copying its buffer.

See also deep_copy.

Implements Index.

◆ to64()

IndexOf<int64_t> to64 ( ) const
overridevirtual

Converts this Index to an Index64.

Implements Index.

◆ tostring()

const std::string tostring ( ) const

Returns a string representation of this array (single-line XML).

◆ tostring_part()

const std::string tostring_part ( const std::string &  indent,
const std::string &  pre,
const std::string &  post 
) const

Internal function to build an output string for tostring.

Parameters
indentIndentation depth as a string of spaces.
prePrefix string, usually an opening XML tag.
postPostfix string, usually a closing XML tag and carriage return.

The documentation for this class was generated from the following file: