Container (abstract data type)

From Infogalactic: the planetary knowledge core
Jump to: navigation, search

<templatestyles src="Module:Hatnote/styles.css"></templatestyles>

Lua error in package.lua at line 80: module 'strict' not found. Lua error in package.lua at line 80: module 'strict' not found.

In computer science, a container is a class, a data structure,[1][2] or an abstract data type (ADT) whose instances are collections of other objects. In other words, they store objects in an organized way that follows specific access rules. The size of the container depends on the number of objects (elements) it contains. Underlying implementation of various container types may vary in space and time complexity, which provides flexibility in choosing the right implementation for a given scenario.

Overview

Containers can be looked at in three ways:

  • access, that is the way of accessing the objects of the container. In the case of arrays, access is done with the array index. In the case of stacks, access is done according to the LIFO (last in, first out) order (alternative name: FILO, first in, last out)[3] and in the case of queues it is done according to the FIFO (first in, first out) order (alternative name: LILO, last in, last out);[3][4]
  • storage, that is the way of storing the objects of the container;
  • traversal, that is the way of traversing the objects of the container.

Container classes are expected to implement methods to do the following:

  • create an empty container;
  • insert objects into the container;
  • delete objects from the container;
  • delete all the objects in the container (clear);
  • access the objects in the container;
  • access the number of objects in the container (size).

Containers are sometimes implemented in conjunction with iterators.

Single value and associative containers

Containers can be divided into two groups.

Single value containers

Each object is stored independently in the container and it is accessed directly or with an iterator.

Associative containers

An associative array, map, or dictionary is a container composed of (key,value) pairs, such that each key appears at most once in the container. The key is used to find the value, the object, if it is stored in the container.

Graphic containers

Widget toolkits use special widgets also called Containers to group the other widgets together (windows, panels, ...). Apart from their graphical properties, they have the same type of behavior as container classes, as they keep a list of their child widgets, and allow to add, remove, or retrieve widgets amongst their children.

Implementations

See also

References

  1. Paul E. Black (ed.), entry for data structure in Dictionary of Algorithms and Data Structures. US National Institute of Standards and Technology.15 December 2004. Accessed on Oct 04, 2011.
  2. Entry data structure in the Encyclopædia Britannica (2009) Online entry Accessed on Oct 04, 2011.
  3. 3.0 3.1 LIFO(investopedia.com) Cite error: Invalid <ref> tag; name "investopedia" defined multiple times with different content
  4. FIFO(businessdictionary.com)
  5. Lua error in package.lua at line 80: module 'strict' not found.

External links

eo:Ujo pt:Container (programação) qu:Wisina