Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Bib Ind

### 19 IO

#### 19.1 Reading and writing elements to a file

The functions ReadGenerators (19.1-1) and WriteGenerators (19.1-2) can be used to read or write, respectively, elements of a semigroup to a file.

 ‣ ReadGenerators( filename[, nr] ) ( function )
 ‣ ReadOldGenerators( filename[, nr] ) ( function )

Returns: A list of lists of semigroup elements.

If filename is the name of a file created using WriteGenerators (19.1-2), then ReadGenerators returns the contents of this file as a list of lists of elements of a semigroup.

If the optional second argument nr is present, then ReadGenerators returns the elements stored in the nrth line of filename.

If you want to read generators from a file written using WriteGenerators from a version of Semigroups before version 3.0.0, then you can use ReadOldGenerators.

gap> file := Concatenation(SEMIGROUPS.PackageDir,
> "/data/tst/testdata");;
[ <identity partial perm on [ 2, 3, 4, 5, 6 ]>,
<identity partial perm on [ 2, 3, 5, 6 ]>, [1,2](5)(6) ]

##### 19.1-2 WriteGenerators
 ‣ WriteGenerators( filename, list[, append] ) ( function )

Returns: IO_OK or IO_ERROR.

This function provides a method for writing collections of elements of a semigroup to a file. The resulting file can be further compressed using gzip or xz.

The argument list should be a list of elements, a semigroup, or a list of lists of elements, or semigroups.

The argument filename should be a string containing the name of a file where the entries in list will be written or an IO package file object; see IO_File (IO: IO_File mode) and IO_CompressedFile (IO: IO_CompressedFile).

If the optional third argument append is given and equals "w", then the previous content of the file is deleted and overwritten. If the optional third argument is "a" or is not present, then list is appended to the file. This function returns IO_OK (IO: IO_OK) if everything went well or IO_ERROR (IO: IO_Error) if something went wrong.

WriteGenerators appends a line to the file filename for every entry in list. If any element of list is a semigroup, then the generators of that semigroup are written to filename. More specifically, the list returned by GeneratorsOfSemigroup (Reference: GeneratorsOfSemigroup) is written to the file.

The file filename can be read using ReadGenerators (19.1-1).

From Version 3.0.0 onwards the Semigroups package used the IO package pickling functionality; see IO: Pickling and unpickling for more details. This approach is used because it is more general and more robust than the methods used by earlier versions of Semigroups, although the performance is somewhat worse, and the resulting files are somewhat larger.

A file written in the old format can be read using ReadOldGenerators (19.1-1).

##### 19.1-3 IteratorFromPickledFile
 ‣ IteratorFromPickledFile( filename ) ( function )
 ‣ IteratorFromOldGeneratorsFile( filename ) ( function )

Returns: An iterator.

If filename is a string containing the name of a file created using WriteGenerators (19.1-2), then IteratorFromPickledFile returns an iterator iter such that NextIterator(iter) returns the next collection of generators stored in the file filename.

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.

If you want to get an iterator for a file written using WriteGenerators from a version of Semigroups before version 3.0.0, then you can use IteratorFromOldGeneratorsFile.

Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Bib Ind

generated by GAPDoc2HTML