apatite/docs/Array.html

362 lines
8.7 KiB
HTML
Raw Normal View History

2019-06-13 02:23:54 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="generator" content="Crystal Docs 0.29.0">
<link href="css/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/doc.js"></script>
<script type="text/javascript">
CrystalDoc.base_path = "";
</script>
<meta id="repository-name" content="github.com/watzon/apatite">
<title>Array(T) - github.com/watzon/apatite</title>
</head>
<body>
<div class="sidebar">
<div class="sidebar-header">
<div class="search-box">
<input type="search" class="search-input" placeholder="Search..." spellcheck="false" aria-label="Search">
</div>
<div class="repository-links">
<a href="index.html">README</a>
</div>
</div>
<div class="search-results" class="hidden">
<ul class="search-list"></ul>
</div>
<div class="types-list">
<ul>
<li class="parent " data-id="github.com/watzon/apatite/Apatite" data-name="apatite">
<a href="Apatite.html">Apatite</a>
<ul>
<li class="parent " data-id="github.com/watzon/apatite/Apatite/LinearAlgebra" data-name="apatite::linearalgebra">
<a href="Apatite/LinearAlgebra.html">LinearAlgebra</a>
<ul>
<li class=" " data-id="github.com/watzon/apatite/Apatite/LinearAlgebra/Matrix" data-name="apatite::linearalgebra::matrix">
<a href="Apatite/LinearAlgebra/Matrix.html">Matrix</a>
</li>
<li class=" " data-id="github.com/watzon/apatite/Apatite/LinearAlgebra/NDArray" data-name="apatite::linearalgebra::ndarray">
<a href="Apatite/LinearAlgebra/NDArray.html">NDArray</a>
</li>
<li class=" " data-id="github.com/watzon/apatite/Apatite/LinearAlgebra/Vector" data-name="apatite::linearalgebra::vector">
<a href="Apatite/LinearAlgebra/Vector.html">Vector</a>
</li>
</ul>
</li>
</ul>
</li>
<li class=" current" data-id="github.com/watzon/apatite/Array" data-name="array(t)">
<a href="Array.html">Array</a>
</li>
</ul>
</div>
</div>
<div class="main-content">
<h1 class="type-name">
<span class="kind">class</span> Array(T)
</h1>
<ul class="superclass-hierarchy"><li class="superclass"><a href="Array.html">Array(T)</a></li><li class="superclass">Reference</li><li class="superclass">Object</li></ul>
<h2>Overview</h2>
<p>An <code><a href="Array.html">Array</a></code> is an ordered, integer-indexed collection of objects of type T.</p>
<p>Array indexing starts at 0. A negative index is assumed to be
relative to the end of the array: -1 indicates the last element,
-2 is the next to last element, and so on.</p>
<p>An <code><a href="Array.html">Array</a></code> can be created using the usual <code>new</code> method (several are provided), or with an array literal:</p>
<pre><code><span class="t">Array</span>(<span class="t">Int32</span>).<span class="k">new</span> <span class="c"># =&gt; []</span>
[<span class="n">1</span>, <span class="n">2</span>, <span class="n">3</span>] <span class="c"># Array(Int32)</span>
[<span class="n">1</span>, <span class="s">&quot;hello&quot;</span>, <span class="s">&#39;x&#39;</span>] <span class="c"># Array(Int32 | String | Char)</span></code></pre>
<p>An <code><a href="Array.html">Array</a></code> can have mixed types, meaning T will be a union of types, but these are determined
when the array is created, either by specifying T or by using an array literal. In the latter
case, T will be set to the union of the array literal elements' types.</p>
<p>When creating an empty array you must always specify T:</p>
<pre><code><span class="o">[]</span> <span class="k">of</span> <span class="t">Int32</span> <span class="c"># same as Array(Int32)</span>
<span class="o">[]</span> <span class="c"># syntax error</span></code></pre>
<p>An <code><a href="Array.html">Array</a></code> is implemented using an internal buffer of some capacity
and is reallocated when elements are pushed to it when more capacity
is needed. This is normally known as a <a href="http://en.wikipedia.org/wiki/Dynamic_array" target="_blank">dynamic array</a>.</p>
<p>You can use a special array literal syntax with other types too, as long as they define an argless
<code>new</code> method and a <code><<</code> method. <code>Set</code> is one such type:</p>
<pre><code>set <span class="o">=</span> <span class="t">Set</span>{<span class="n">1</span>, <span class="n">2</span>, <span class="n">3</span>} <span class="c"># =&gt; Set{1, 2, 3}</span>
set.<span class="k">class</span> <span class="c"># =&gt; Set(Int32)</span></code></pre>
<p>The above is the same as this:</p>
<pre><code>set <span class="o">=</span> <span class="t">Set</span>(<span class="k">typeof</span>(<span class="n">1</span>, <span class="n">2</span>, <span class="n">3</span>)).<span class="k">new</span>
set <span class="o">&lt;&lt;</span> <span class="n">1</span>
set <span class="o">&lt;&lt;</span> <span class="n">2</span>
set <span class="o">&lt;&lt;</span> <span class="n">3</span></code></pre>
<h2>Included Modules</h2>
<ul class="other-types-list">
<li class="other-type">Comparable(<a href="Array.html">Array(T)</a>)</li>
<li class="other-type">Indexable(T)</li>
</ul>
<h2>Defined in:</h2>
2019-06-17 22:01:05 +00:00
<a href="https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/core_ext/array.cr#L1" target="_blank">
2019-06-13 02:23:54 +00:00
apatite/core_ext/array.cr
</a>
<br/>
<h2>Instance Method Summary</h2>
<ul class="list-summary">
<li class="entry-summary">
<a href="#all%3F-instance-method" class="signature"><strong>#all?</strong></a>
<div class="summary"><p>Tests whether all elements evaluate to true</p></div>
</li>
<li class="entry-summary">
<a href="#any%3F-instance-method" class="signature"><strong>#any?</strong></a>
<div class="summary"><p>Tests whether any of the elements evaluate to true</p></div>
</li>
<li class="entry-summary">
<a href="#shape-instance-method" class="signature"><strong>#shape</strong></a>
<div class="summary"><p>Get the array's dimensions</p></div>
</li>
<li class="entry-summary">
<a href="#to_vec-instance-method" class="signature"><strong>#to_vec</strong></a>
</li>
</ul>
<div class="methods-inherited">
</div>
<h2>Instance Method Detail</h2>
<div class="entry-detail" id="all?-instance-method">
<div class="signature">
def <strong>all?</strong>
<a class="method-permalink" href="#all%3F-instance-method">#</a>
</div>
<div class="doc"><p>Tests whether all elements evaluate to true</p></div>
<br/>
<div>
2019-06-17 22:01:05 +00:00
[<a href="https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/core_ext/array.cr#L3" target="_blank">View source</a>]
2019-06-13 02:23:54 +00:00
</div>
</div>
<div class="entry-detail" id="any?-instance-method">
<div class="signature">
def <strong>any?</strong>
<a class="method-permalink" href="#any%3F-instance-method">#</a>
</div>
<div class="doc"><p>Tests whether any of the elements evaluate to true</p></div>
<br/>
<div>
2019-06-17 22:01:05 +00:00
[<a href="https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/core_ext/array.cr#L11" target="_blank">View source</a>]
2019-06-13 02:23:54 +00:00
</div>
</div>
<div class="entry-detail" id="shape-instance-method">
<div class="signature">
def <strong>shape</strong>
<a class="method-permalink" href="#shape-instance-method">#</a>
</div>
<div class="doc"><p>Get the array's dimensions</p></div>
<br/>
<div>
2019-06-17 22:01:05 +00:00
[<a href="https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/core_ext/array.cr#L19" target="_blank">View source</a>]
2019-06-13 02:23:54 +00:00
</div>
</div>
<div class="entry-detail" id="to_vec-instance-method">
<div class="signature">
def <strong>to_vec</strong>
<a class="method-permalink" href="#to_vec-instance-method">#</a>
</div>
<br/>
<div>
2019-06-17 22:01:05 +00:00
[<a href="https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/core_ext/array.cr#L24" target="_blank">View source</a>]
2019-06-13 02:23:54 +00:00
</div>
</div>
</div>
</body>
</html>