# Index collections

Collections of `Index`

are used throughout ITensors.jl to represent the dimensions of tensors. In general, collections that are recognized and returned by ITensors.jl functions are either `Vector`

of `Index`

or `Tuple`

of `Index`

, depending on the context. For example internally an `ITensor`

has a static number of indices so stores a `Tuple`

of `Index`

, while set operations like `commoninds((i, j, k), (j, k, l))`

will return a `Vector`

`[j, k]`

since the operation is inherently dynamic, i.e. the number of indices in the intersection can't in general be known before running the code. `Vector`

of `Index`

and `Tuple`

of `Index`

can usually be used interchangeably, but one or the other may be faster depending on the operation being performed.

## Priming and tagging

Documentation for priming and tagging collections of Index can be found in the ITensor Priming and tagging section.

## Set operations

Documentation for set operations involving Index collections can be found in the ITensor Index collections set operations section.

## Subsets

`ITensors.getfirst`

— Method`getfirst(f::Function, is::Indices)`

Get the first Index matching the pattern function, return `nothing`

if not found.

`ITensors.getfirst`

— Method`getfirst(is::Indices)`

Return the first Index in the Indices. If the Indices is empty, return `nothing`

.

## Iterating

`ITensors.eachval`

— Method```
eachval(is::Index...)
eachval(is::Tuple{Vararg{Index}})
```

Create an iterator whose values correspond to a Cartesian indexing over the dimensions of the provided `Index`

objects.

`ITensors.eachindval`

— Method```
eachindval(is::Index...)
eachindval(is::Tuple{Vararg{Index}})
```

Create an iterator whose values are Index=>value pairs corresponding to a Cartesian indexing over the dimensions of the provided `Index`

objects.

**Example**

```
i = Index(3; tags = "i")
j = Index(2; tags = "j")
T = randomITensor(j,i)
for iv in eachindval(i,j)
@show T[iv...]
end
```

## Symmetry related properties

`ITensors.dir`

— Method`dir(is::Indices, i::Index)`

Return the direction of the Index `i`

in the Indices `is`

.