<h4>17.1 <span class="Heading">Reading and writing elements to a file</span></h4>
<p>The functions <code class="func">ReadGenerators</code> (<a href="chap17_mj.html#X8728096E8427EDE8"><span class="RefLink">17.1-1</span></a>) and <code class="func">WriteGenerators</code> (<a href="chap17_mj.html#X78041E8F87EFDE62"><span class="RefLink">17.1-2</span></a>) can be used to read or write, respectively, elements of a semigroup to a file.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ReadGenerators</code>( <var class="Arg">filename</var>[, <var class="Arg">nr</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: A list of lists of semigroup elements.</p>
<p>If <var class="Arg">filename</var> is an <strong class="pkg">IO</strong> package file object or is the name of a file created using <code class="func">WriteGenerators</code> (<a href="chap17_mj.html#X78041E8F87EFDE62"><span class="RefLink">17.1-2</span></a>), then <code class="code">ReadGenerators</code> returns the contents of this file as a list of lists of elements of a semigroup.</p>
<p>If the optional second argument <var class="Arg">nr</var> is present, then <code class="code">ReadGenerators</code> returns the elements stored in the <var class="Arg">nr</var>th line of <var class="Arg">filename</var>.</p>
<p>This function provides a method for writing collections of elements of a semigroup to a file. The resulting file can be further compressed using <code class="code">gzip</code> or <code class="code">xz</code>.</p>
<p>The argument <var class="Arg">list</var> should be a list of lists of elements, or semigroups.</p>
<p>The argument <var class="Arg">filename</var> should be a string containing the name of a file or an <strong class="pkg">IO</strong> package file object where the entries in <var class="Arg">list</var> will be written; see <code class="func">IO_File</code> (<a href="https://gap-packages.github.io/io/doc/chap4_mj.html#X7EC160D07E815DBB"><span class="RefLink">IO: IO_File mode</span></a>) and <code class="func">IO_CompressedFile</code> (<a href="https://gap-packages.github.io/io/doc/chap4_mj.html#X7B425F3B7A68C2FB"><span class="RefLink">IO: IO_CompressedFile</span></a>).</p>
<p>If the optional third argument <var class="Arg">append</var> is not present or is given and equals <code class="code">"w"</code>, then the previous content of the file is deleted and overwritten. If the third argument is <code class="code">"a"</code>, then <code class="code">list</code> is appended to the file.</p>
<p>If any element of <var class="Arg">list</var> is a semigroup, then the generators of that semigroup are written to <var class="Arg">filename</var>. More specifically, the list returned by <code class="func">GeneratorsOfSemigroup</code> (<a href="../../../doc/ref/chap51_mj.html#X78147A247963F23B"><span class="RefLink">Reference: GeneratorsOfSemigroup</span></a>) is written to the file.</p>
<p>This function returns <code class="func">IO_OK</code> (<a href="https://gap-packages.github.io/io/doc/chap5_mj.html#X7D4D092B8401EA0F"><span class="RefLink">IO: IO_OK</span></a>) if everything went well or <code class="func">IO_ERROR</code> (<a href="https://gap-packages.github.io/io/doc/chap5_mj.html#X86E06A128511BA25"><span class="RefLink">IO: IO_Error</span></a>) if something went wrong.</p>
<p>The file produced by <code class="code">WriteGenerators</code> can be read using <code class="func">ReadGenerators</code> (<a href="chap17_mj.html#X8728096E8427EDE8"><span class="RefLink">17.1-1</span></a>).</p>
<p>From Version 3.0.0 onwards the <strong class="pkg">Semigroups</strong> package used the <span class="URL"><a href="https://gap-packages.github.io/io">IO</a></span> package pickling functionality; see <a href="https://gap-packages.github.io/io/doc/chap5_mj.html#X7F68A8F47F87B243"><span class="RefLink">IO: Pickling and unpickling</span></a> for more details. This approach is used because it is more general and more robust than the methods used by earlier versions of <strong class="pkg">Semigroups</strong>, although the performance is somewhat worse, and the resulting files are somewhat larger.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IteratorFromGeneratorsFile</code>( <var class="Arg">filename</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: An iterator.</p>
<p>If <var class="Arg">filename</var> is a file or a string containing the name of a file created using <code class="func">WriteGenerators</code> (<a href="chap17_mj.html#X78041E8F87EFDE62"><span class="RefLink">17.1-2</span></a>), then <code class="code">IteratorFromGeneratorsFile</code> returns an iterator <code class="code">iter</code> such that <code class="code">NextIterator(iter)</code> returns the next collection of generators stored in the file <var class="Arg">filename</var>.</p>
<p>This function is a convenient way of, for example, looping over a collection of generators in a file without loading every object in the file into memory. This might be useful if the file contains more information than there is available memory.</p>
<p>If you want to get an iterator for a file written using <code class="code">WriteGenerators</code> from a version of <strong class="pkg">Semigroups</strong> before version 3.0.0, then you can use <code class="code">IteratorFromOldGeneratorsFile</code>.</p>
<h4>17.2 <span class="Heading">Reading and writing multiplication tables to a file</span></h4>
<p>The functions <code class="func">ReadMultiplicationTable</code> (<a href="chap17_mj.html#X805058C07F9373B4"><span class="RefLink">17.2-1</span></a>) and <code class="func">WriteMultiplicationTable</code> (<a href="chap17_mj.html#X868B824B7E24FA96"><span class="RefLink">17.2-2</span></a>) can be used to read or write, respectively, multiplication tables to a file.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ReadMultiplicationTable</code>( <var class="Arg">filename</var>[, <var class="Arg">nr</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: A list of multiplication tables.</p>
<p>If <var class="Arg">filename</var> is a file or is the name of a file created using <code class="func">WriteMultiplicationTable</code> (<a href="chap17_mj.html#X868B824B7E24FA96"><span class="RefLink">17.2-2</span></a>), then <code class="code">ReadMultiplicationTable</code> returns the contents of this file as a list of multiplication tables.</p>
<p>If the optional second argument <var class="Arg">nr</var> is present, then <code class="code">ReadMultiplicationTable</code> returns the multiplication table stored in the <var class="Arg">nr</var>th line of <var class="Arg">filename</var>.</p>
<p>This function provides a method for writing collections of multiplication tables to a file. The resulting file can be further compressed using <code class="code">gzip</code> or <code class="code">xz</code>. This function applies to square arrays with a maximum of 255 rows where the entries are integers from <code class="code">[1, 2, .., n]</code> (where <code class="code">n</code> is the number of rows in the array.</p>
<p>The argument <var class="Arg">list</var> should be a list of multiplication tables.</p>
<p>The argument <var class="Arg">filename</var> should be a file or a string containing the name of a file where the entries in <var class="Arg">list</var> will be written or an <strong class="pkg">IO</strong> package file object; see <code class="func">IO_File</code> (<a href="https://gap-packages.github.io/io/doc/chap4_mj.html#X7EC160D07E815DBB"><span class="RefLink">IO: IO_File mode</span></a>) and <code class="func">IO_CompressedFile</code> (<a href="https://gap-packages.github.io/io/doc/chap4_mj.html#X7B425F3B7A68C2FB"><span class="RefLink">IO: IO_CompressedFile</span></a>).</p>
<p>If the optional third argument <var class="Arg">append</var> is not present or is given and equals <code class="code">"w"</code>, then the previous content of the file is deleted and overwritten. If the third argument is given and equals <code class="code">"a"</code> then <code class="code">list</code> is appended to the file. This function returns <code class="func">IO_OK</code> (<a href="https://gap-packages.github.io/io/doc/chap5_mj.html#X7D4D092B8401EA0F"><span class="RefLink">IO: IO_OK</span></a>) if everything went well or <code class="func">IO_ERROR</code> (<a href="https://gap-packages.github.io/io/doc/chap5_mj.html#X86E06A128511BA25"><span class="RefLink">IO: IO_Error</span></a>) if something went wrong.</p>
<p>The multiplication tables saved in <var class="Arg">filename</var> can be recovered from the file using <code class="func">ReadMultiplicationTable</code> (<a href="chap17_mj.html#X805058C07F9373B4"><span class="RefLink">17.2-1</span></a>).</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IteratorFromMultiplicationTableFile</code>( <var class="Arg">filename</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: An iterator.</p>
<p>If <var class="Arg">filename</var> is a file or a string containing the name of a file created using <code class="func">WriteMultiplicationTable</code> (<a href="chap17_mj.html#X868B824B7E24FA96"><span class="RefLink">17.2-2</span></a>), then <code class="code">IteratorFromMultiplicationTableFile</code> returns an iterator <code class="code">iter</code> such that <code class="code">NextIterator(iter)</code> returns the next multiplication table stored in the file <var class="Arg">filename</var>.</p>
<p>This function is a convenient way of, for example, looping over a collection of multiplication tables in a file without loading every object in the file into memory. This might be useful if the file contains more information than there is available memory.</p>
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.