Array data structure

A field (English Array [ əɹeɪ ] (stress on second syllable) for, arrangement ',' installation ', etc.) in computer science, a data structure variant, with the use of " many similarly structured data [ ... ] are processed should ". A distinction is made between a standard field 'and the' associative array '.

  • 3.1 Examples
  • 3.2 Addressing a field 3.2.1 memory mapping function
  • 3.2.2 dope vector
  • 3.2.3 program efficiency

Terms

Synonyms

In the language and mainly influenced from the use of different programming languages ​​( their terminology and history ) and translation from English, is the here - ' - concept described field' assigned different expressions shall have the meaning array: array, table, vector, series, stringing, field data, installation, field, gate array, matrix / matrix, indexed variable, etc. "The English and more common term for the field is an array. "

The individual elements of an array are denoted by different terms: element, component, subfield, array element - partly also field.

Contextual differences

In the important array ' is referred to with, field' depending on the context in detail different situations:

  • If, field 'is used as a synonym for' array ': the entire array with all its elements, possibly including multi-dimensional - with all index expressions.
  • With respect to a defined field, often only in declarations: The totality of all index expressions of the field ( an entire column ).
  • With (index) ' one refers to a single index expression, alternatively, an elementary field or an entire row.

Also, depending on the context concerns the reference to, the field ' alternatively the declaration plane of the array (eg: dim array ( 100) ) or stored content (eg: ADD array element (index) to total).

Differing importance

The expression box ' is descriptive construct as ' data' generally understood, which is used in the source code of a computer program for defining space. In this sense, a field is not a data type, but it has a data type, and it is independent of whether it ( such as composite or Record) belongs to an array or a higher-level data structure or not., Field ' in this sense is thus equated with i W. variable or data field. Examples of references:

  • Expressions such as static field class field, field length, etc. refer to, box ' in a general sense.
  • Field ' is used (eg in ) as type- neutral data construct.
  • The same applies to texts like " ... contents of the field job ID " (in the link to siko.de ) and " ... treats each array element as a separate field " in or phrases such as " fields for data exchange ", " ... transfers data to a field "," contents of the data field "," field description "," field length " in
  • Even in documents that use, field ' principle in the sense of, Array ', the term, field ' and non- array based used: "Here the array has 10 fields " or " all other fields have an undefined value " in

These two significantly differing meanings of field ' are and were always rise to partially heated discussions, see Example

Language-specific differences

Basically, arrays can be created and processed in all programming languages ​​(*). In addition to the different concepts that have developed in each language (usually after translation from English ), arrays are implemented differently / support of the languages ​​( compilers ) both in declaring and in use in commands. Examples:

  • Restrictions regarding possible data formats and lengths in the array
  • Distinction default field / associative array by the programming language ( the compiler ) - Y / N
  • Number of possible dimensions; Array size
  • Addressing the elements (from 0 from 1, starting from )
  • Compiler support for operations on volumes of data in the array: on elements, the entire array, part-ranges.
  • Addressing method: key lookup, various methods for establishing the index
  • Dynamic or fixed size arrays

(*) In most assembly language, the processing of arrays possible, but it is linguistic- syntactic usually not specifically supported. The programmer implements the array elements as well as other variables reserved in addition to the space for n more forms, to determine the position ( index ) of relevant elements of suitable algorithms and addressed this with - non- specifically to the array - processing oriented - appropriate instructions.

Standard field

By means of a field, the data of a single data type may typically be stored in the memory of a computer, that access to the data on an index becomes possible. The ( standard ) field used in contrast to the associative field an integer index for addressing. This begins at a field with N elements, by default, depending on the programming language at 0 (C : 0,1,2, ..., N -1) or 1 ( Fortran: 1,2,3, ..., N) can are, however, often also chosen freely ( 42,43,44, ..., N 41 ).

Examples

Below is a symbolic example code is used ( the start index is 1):

  • Vector ( one-dimensional)

Vector: = (10, -11, 12) So vector returns the value -11. Matrix or table ( two-dimensional)

Chess box: = array (8,8 ) of String array defines the arrangement of the entries of the type of the entry Chess box: = (( " Turm_W ", " Springer_W ", " Läufer_W ", ..., " Turm_W ")                 ( " Bauer_W " " Bauer_W " " Bauer_W ", ..., " Bauer_W ")                 ( " Idle ", " Empty", "Empty", ..., "empty " ),                 ( " Idle ", " Empty", "Empty", ..., "empty " ),                 ( " Idle ", " Empty", "Empty", ..., "empty " ),                 ( " Idle ", " Empty", "Empty", ..., "empty " ),                 ( " Bauer_S " " Bauer_S " " Bauer_S ", ..., " Bauer_S ")                 ( " Turm_S ", " Springer_S ", " Läufer_S ", ..., " Turm_S " ) ) The example statements chess field [3,3 ]: = chessboard [1,2 ] and chess field [1,2 ]: = " Empty" deliver the opening gambit "White knight on C3".

An array containing the data ' Lord, woman, company, etc. ' in the order 1,2,3 to n in the address data of the customer base, only the address number is stored ( between 1 and n ). When creating letters, etc. this address number is used as the index and the text, so the value of ' woman ' for '2 ', used from the array as Title- full text.

Addressing the field

Ultimately, the data stored in a field elements in a linear memory must be stored. The elements of a one-dimensional vector are successively stored in the memory at a two-dimensional array, the elements are placed one behind the other as either row or column vectors in a three-dimensional array corresponding to many matrices are stored sequentially, etc.

Memory mapping function

A program that wants to access the data field or individual elements of the memory address of any element must be calculated in a field.

The address of an element, for example, calculated using the formula in one -dimensional box. One calls this formula also memory mapping function.

The formula shown is only one of at least two alternatives, depending on the order in which the indices are combined into memory blocks from the first down to last or just the reverse. In English, we are differentiating Row -major order ( row by row arrangement ) and Column -major order ( column-wise arrangement ). It is usually the responsibility of the runtime environment of the compiler, which variant uses a program.

Dope vector

Since the products are constant in the above formula, it can be charged once, and the resulting dope vector d allows then the formula is a very fast calculation of the address of each stored item.

Program efficiency

If such a field is in a computer kept in RAM, accesses to array elements is usually fastest when directly consecutive addresses can be accessed. The programmer is held, the order of the indices in the box set so that this is done in the innermost loop as well. Since the memory mapping function depends on the compiler, the programmer should be informed about these details and then define the program to run through in the innermost loop index so that it corresponds to the increments in the memory map.

Field in freer form

In some programming languages ​​- as an example can serve Java - field contents are not limited to elements of a single data type, it can be objects or general data structures almost any composition and sequence are stored. In Java, not every line of a two-dimensional array must be of equal length. The above calculations must address the runtime environment of the programming then correspondingly different and possibly make more effort.

Associative field

A special form is the " associative array ". It does not use a numeric index, but so-called key for indexing and thus to address the elements. The most commonly used " associative arrays " implemented as a hash table.

An IT application creates customer invoices. The product should also be the total invoiced number and the total amount will be counted. The application reads the information ' product number, product description and price ' from a database into an associative array in main memory one to not access on every invoice item to the external storage medium must. Key in the array is the product number, all entries are sorted afterwards. To the product number contained in each invoice item, the corresponding array position is determined and the name and the price used in the calculation line. The product number for each item and the price is formed from it in the additionally created array elements ' Total ' and ' Total Price ' ( by product number) cumulative - to be issued at the end of the program as the sum of information.

246970
de