GLib is a bundle of three (formerly five) low-level system libraries written in C and developed mainly by GNOME . GLib's code was separated from GTK , so it can be used by software other than GNOME and has been developed in parallel ever since.
63-401: The name "GLib" originates from the project's start as a GTK C utility library. GLib provides advanced data structures, such as memory chunks, doubly and singly linked lists , hash tables , dynamic strings and string utilities, such as a lexical scanner, string chunks (groups of strings), dynamic arrays , balanced binary trees , N-ary trees , quarks (a two-way association of a string and
126-419: A monad with the following functions (using E rather than L to represent monomorphic lists with elements of type E ): where append is defined as: Alternatively, the monad may be defined in terms of operations return , fmap and join , with: Note that fmap , join , append and bind are well-defined, since they're applied to progressively deeper arguments at each recursive call. The list type
189-414: A "first" and "last" node. An empty list is a list that contains no data records. This is usually the same as saying that it has zero nodes. If sentinel nodes are being used, the list is usually said to be empty when it has only sentinel nodes. The link fields need not be physically part of the nodes. If the data records are stored in an array and referenced by their indices, the link field may be stored in
252-416: A 'value' field as well as 'next' field, which points to the next node in line of nodes. Operations that can be performed on singly linked lists include insertion, deletion and traversal. The following C language code demonstrates how to add a new node with the "value" to the end of a singly linked list: In a 'doubly linked list', each node contains, besides the next-node link, a second link field pointing to
315-513: A linear initial segment. Algorithms for searching or otherwise operating on these have to take precautions to avoid accidentally entering an endless loop. One well-known method is to have a second pointer walking the list at half or double the speed, and if both pointers meet at the same node, a cycle has been found. Sentinel node may simplify certain list operations, by ensuring that the next or previous nodes exist for every element, and that even empty lists have at least one node. One may also use
378-560: A linked list while permitting much more efficient indexing, taking O(log n) time instead of O(n) for a random access. However, insertion and deletion operations are more expensive due to the overhead of tree manipulations to maintain balance. Schemes exist for trees to automatically maintain themselves in a balanced state: AVL trees or red–black trees . While doubly linked and circular lists have advantages over singly linked linear lists, linear lists offer some advantages that make them preferable in some situations. A singly linked linear list
441-479: A list by a handle that consists of two links, pointing to its first and last nodes. The alternatives listed above may be arbitrarily combined in almost every way, so one may have circular doubly linked lists without sentinels, circular singly linked lists with sentinels, etc. As with most choices in computer programming and design, no method is well suited to all circumstances. A linked list data structure might work well in one case, but cause problems in another. This
504-429: A list. Lists also form the basis for other abstract data types including the queue , the stack , and their variations. The abstract list type L with elements of some type E (a monomorphic list) is defined by the following functions: with the axioms for any element e and any list l . It is implicit that Note that first (nil ()) and rest (nil ()) are not defined. These axioms are equivalent to those of
567-500: A particular order . An instance of a list is a computer representation of the mathematical concept of a tuple or finite sequence . A list may contain the same value more than once, and each occurrence is considered a distinct item. The term list is also used for several concrete data structures that can be used to implement abstract lists, especially linked lists and arrays . In some contexts, such as in Lisp programming,
630-461: A pointer to any node serves as a handle to the whole list. With a circular list, a pointer to the last node gives easy access also to the first node, by following one link. Thus, in applications that require access to both ends of the list (e.g., in the implementation of a queue), a circular structure allows one to handle the structure by a single pointer, instead of two. A circular list can be split into two circular lists, in constant time, by giving
693-400: A sentinel node at the end of the list, with an appropriate data field, to eliminate some end-of-list tests. For example, when scanning the list looking for a node with a given value x , setting the sentinel's data field to x makes it unnecessary to test for end-of-list inside the loop. Another example is the merging two sorted lists: if their sentinels have data fields set to +∞, the choice of
SECTION 10
#1732782353383756-491: A separate array with the same indices as the data records. Since a reference to the first node gives access to the whole list, that reference is often called the 'address', 'pointer', or 'handle' of the list. Algorithms that manipulate linked lists usually get such handles to the input lists and return the handles to the resulting lists. In fact, in the context of such algorithms, the word "list" often means "list handle". In some situations, however, it may be convenient to refer to
819-415: A separate case. In the last node of a linked list, the link field often contains a null reference, a special value is used to indicate the lack of further nodes. A less common convention is to make it point to the first node of the list; in that case, the list is said to be 'circular' or 'circularly linked'; otherwise, it is said to be 'open' or 'linear'. It is a list where the last node pointer points to
882-490: A separate software bundle. GLib was released as a separate library so other developers, those not using the GUI-related parts of GTK+, could use the non-GUI parts of the library without the overhead of depending on the full GUI library. Since GLib is a cross-platform library, applications using it to interface with the operating system are usually portable across different operating systems without major changes. Glib
945-401: A special internal representation (invisible to the user). Lists can be manipulated using iteration or recursion . The former is often preferred in imperative programming languages , while the latter is the norm in functional languages . Lists can be implemented as self-balancing binary search trees holding index-value pairs, providing equal-time access to any element (e.g. all residing in
1008-518: A specific point of a list, assuming that a pointer is indexed to the node (before the one to be removed, or before the insertion point) already, is a constant-time operation (otherwise without this reference it is O(n)), whereas insertion in a dynamic array at random locations will require moving half of the elements on average, and all the elements in the worst case. While one can "delete" an element from an array in constant time by somehow marking its slot as "vacant", this causes fragmentation that impedes
1071-440: A thing makes sense) is a null pointer, indicating that the list has no nodes. Without this choice, many algorithms have to test for this special case, and handle it separately. By contrast, the use of null to denote an empty linear list is more natural and often creates fewer special cases. For some applications, it can be useful to use singly linked lists that can vary between being circular and being linear, or even circular with
1134-786: A unique integer identifier), keyed data lists, relations, and tuples . Caches provide memory management. GLib implements functions that provide threads , thread programming and related facilities such as primitive variable access, mutexes , asynchronous queues , secure memory pools , message passing and logging, hook functions (callback registering) and timers . GLib also includes message passing facilities such as byte order conversion and I/O channels. Some other features of GLib include: The GLib package consisted of five libraries, but they were all merged into one library, since then named simply GLib , and are no longer sustained as standalone libraries. The original libraries were: Of these, three continue to reside in distinct subdirectories of
1197-439: Is a recursive data structure, because it contains a pointer to a smaller object of the same type. For that reason, many operations on singly linked linear lists (such as merging two lists, or enumerating the elements in reverse order) often have very simple recursive algorithms, much simpler than any solution using iterative commands . While those recursive solutions can be adapted for doubly linked and circularly linked lists,
1260-452: Is a list of some of the common tradeoffs involving linked list structures. A dynamic array is a data structure that allocates all elements contiguously in memory, and keeps a count of the current number of elements. If the space reserved for the dynamic array is exceeded, it is reallocated and (possibly) copied, which is an expensive operation. Linked lists have several advantages over dynamic arrays. Insertion or deletion of an element at
1323-441: Is a much more expensive operation. Linked lists allow insertion and removal of nodes at any point in the list, and allow doing so with a constant number of operations by keeping the link previous to the link being added or removed in memory during list traversal. On the other hand, since simple linked lists by themselves do not allow random access to the data or any form of efficient indexing, many basic operations—such as obtaining
SECTION 20
#17327823533831386-414: Is also faster than on linked lists on many machines, because they have optimal locality of reference and thus make good use of data caching. Another disadvantage of linked lists is the extra storage needed for references, which often makes them impractical for lists of small data items such as characters or Boolean values , because the storage overhead for the links may exceed by a factor of two or more
1449-430: Is not true with the other variants: a node may never belong to two different circular or doubly linked lists. In particular, end-sentinel nodes can be shared among singly linked non-circular lists. The same end-sentinel node may be used for every such list. In Lisp , for example, every proper list ends with a link to a special node, denoted by nil or () . The advantages of the fancy variants are often limited to
1512-420: Is not uncommon to implement those data structures directly without using a linked list as the basis. The principal benefit of a linked list over a conventional array is that the list elements can be easily inserted or removed without reallocation or reorganization of the entire structure because the data items do not need to be stored contiguously in memory or on disk, while restructuring an array at run-time
1575-594: Is that data access time is linear in respect to the number of nodes in the list. Because nodes are serially linked, accessing any node requires that the prior node be accessed beforehand (which introduces difficulties in pipelining ). Faster access, such as random access, is not feasible. Arrays have better cache locality compared to linked lists. Linked lists are among the simplest and most common data structures. They can be used to implement several other common abstract data types , including lists , stacks , queues , associative arrays , and S-expressions , though it
1638-652: Is the linked list. By the early 1960s, the utility of both linked lists and languages which use these structures as their primary data representation was well established. Bert Green of the MIT Lincoln Laboratory published a review article entitled "Computer languages for symbol manipulation" in IRE Transactions on Human Factors in Electronics in March 1961 which summarized the advantages of
1701-483: Is to unlink themselves from these lists. In a 'multiply linked list', each node contains two or more link fields, each field being used to connect the same set of data arranged in a different order (e.g., by name, by department, by date of birth, etc.). While a doubly linked list can be seen as a special case of multiply linked list, the fact that the two and more orders are opposite to each other leads to simpler and more efficient algorithms, so they are usually treated as
1764-477: Is undergoing active development. For a current overview see https://gitlab.gnome.org/GNOME/glib/-/blob/main/NEWS . The table below documents major patch notes from 1998 to 2022. Other libraries provide low-level functions and implementations of data structures, including: Linked list In computer science , a linked list is a linear collection of data elements whose order is not given by their physical placement in memory. Instead, each element points to
1827-443: The n th person is reached, one should remove them from the circle and have the members close the circle. The process is repeated until only one person is left. That person wins the election. This shows the strengths and weaknesses of a linked list vs. a dynamic array, because if the people are viewed as connected nodes in a circular linked list, then it shows how easily the linked list is able to delete nodes (as it only has to rearrange
1890-441: The 'data', 'information', 'value', 'cargo', or 'payload' fields. The 'head' of a list is its first node. The 'tail' of a list may refer either to the rest of the list after the head, or to the last node in the list. In Lisp and some derived languages, the next node may be called the ' cdr ' (pronounced /'kʊd.əɹ/ ) of the list, while the payload of the head node may be called the 'car'. Singly linked lists contain nodes which have
1953-586: The 'previous' node in the sequence. The two links may be called 'forward('s') and 'backwards', or 'next' and 'prev'('previous'). A technique known as XOR-linking allows a doubly linked list to be implemented using a single link field in each node. However, this technique requires the ability to do bit operations on addresses, and therefore may not be available in some high-level languages. Many modern operating systems use doubly linked lists to maintain references to active processes, threads, and other dynamic objects. A common strategy for rootkits to evade detection
GLib - Misplaced Pages Continue
2016-496: The System 360/370 machines, used a double linked list for their file system catalog. The directory structure was similar to Unix, where a directory could contain files and other directories and extend to any depth. Each record of a linked list is often called an 'element' or ' node '. The field of each node that contains the address of the next node is usually called the 'next link' or 'next pointer'. The remaining fields are known as
2079-411: The abstract stack data type. In type theory , the above definition is more simply regarded as an inductive type defined in terms of constructors: nil and cons . In algebraic terms, this can be represented as the transformation 1 + E × L → L . first and rest are then obtained by pattern matching on the cons constructor and separately handling the nil case. The list type forms
2142-479: The actual data referenced, which extends off the end of the referencing record. A good example that highlights the pros and cons of using dynamic arrays vs. linked lists is by implementing a program that resolves the Josephus problem . The Josephus problem is an election method that works by having a group of people stand in a circle. Starting at a predetermined person, one may count around the circle n times. Once
2205-409: The addresses of the last node of each piece. The operation consists in swapping the contents of the link fields of those two nodes. Applying the same operation to any two nodes in two distinct lists joins the two list into one. This property greatly simplifies some algorithms and data structures, such as the quad-edge and face-edge . The simplest representation for an empty circular list (when such
2268-409: The circle by directly referencing them by their position in the array. The list ranking problem concerns the efficient conversion of a linked list representation into an array. Although trivial for a conventional computer, solving this problem by a parallel algorithm is complicated and has been the subject of much research. A balanced tree has similar memory access patterns and space overhead to
2331-446: The complexity of the algorithms, not in their efficiency. A circular list, in particular, can usually be emulated by a linear list together with two variables that point to the first and last nodes, at no extra cost. Double-linked lists require more space per node (unless one uses XOR-linking ), and their elementary operations are more expensive; but they are often easier to manipulate because they allow fast and easy sequential access to
2394-820: The cost of an insertion due to reallocation would still be amortized O(1). This helps with appending elements at the array's end, but inserting into (or removing from) middle positions still carries prohibitive costs due to data moving to maintain contiguity. An array from which many elements are removed may also have to be resized in order to avoid wasting too much space. On the other hand, dynamic arrays (as well as fixed-size array data structures ) allow constant-time random access , while linked lists allow only sequential access to elements. Singly linked lists, in fact, can be easily traversed in only one direction. This makes linked lists unsuitable for applications where it's useful to look up an element by its index quickly, such as heapsort . Sequential access on arrays and dynamic arrays
2457-441: The empty list, and cons , which adds an item at the beginning of a list. A stream is the potentially infinite analog of a list. Implementation of the list data structure may provide some of the following operations : Lists are typically implemented either as linked lists (either singly or doubly linked) or as arrays , usually variable length or dynamic arrays . The standard way of implementing lists, originating with
2520-617: The first UNESCO International Conference on Information Processing) in 1959. The now-classic diagram consisting of blocks representing list nodes with arrows pointing to successive list nodes appears in "Programming the Logic Theory Machine" by Newell and Shaw in Proc. WJCC, February 1957. Newell and Simon were recognized with the ACM Turing Award in 1975 for having "made basic contributions to artificial intelligence,
2583-538: The first node (i.e., the "next link" pointer of the last node has the memory address of the first node). In the case of a circular doubly linked list, the first node also points to the last node of the list. In some implementations an extra 'sentinel' or 'dummy' node may be added before the first data record or after the last one. This convention simplifies and accelerates some list-handling algorithms, by ensuring that all links can be safely dereferenced and that every list (even one that contains no data elements) always has
GLib - Misplaced Pages Continue
2646-593: The first sector of a file, and succeeding portions of the file were located by traversing pointers. Systems using this technique included Flex (for the Motorola 6800 CPU), mini-Flex (same CPU), and Flex9 (for the Motorola 6809 CPU). A variant developed by TSC for and marketed by Smoke Signal Broadcasting in California, used doubly linked lists in the same manner. The TSS/360 operating system, developed by IBM for
2709-612: The fringe, and internal nodes storing the right-most child's index, used to guide the search), taking the time logarithmic in the list's size, but as long as it doesn't change much will provide the illusion of random access and enable swap, prefix and append operations in logarithmic time as well. Some languages do not offer a list data structure , but offer the use of associative arrays or some kind of table to emulate lists. For example, Lua provides tables. Although Lua stores lists that have numerical indices as arrays internally, they still appear as dictionaries. In Lisp , lists are
2772-480: The fundamental data type and can represent both program code and data. In most dialects, the list of the first three prime numbers could be written as (list 2 3 5) . In several dialects of Lisp, including Scheme , a list is a collection of pairs, consisting of a value and a pointer to the next pair (or null value), making a singly linked list. Unlike in an array , a list can expand and shrink. In computing, lists are easier to implement than sets. A finite set in
2835-485: The items in sequence, separated by commas , semicolons , and/or spaces , within a pair of delimiters such as parentheses '()', brackets '[]', braces '{}', or angle brackets '<>'. Some languages may allow list types to be indexed or sliced like array types , in which case the data type is more accurately described as an array. In type theory and functional programming , abstract lists are usually defined inductively by two operations: nil that yields
2898-453: The last and the first data nodes. With this convention, an empty list consists of the sentinel node alone, pointing to itself via the next-node link. The list handle should then be a pointer to the last data node, before the sentinel, if the list is not empty; or to the sentinel itself, if the list is empty. List (abstract data type) In computer science , a list or sequence is a collection of items that are finite in number and in
2961-433: The last node of the list, finding a node that contains a given datum, or locating the place where a new node should be inserted—may require iterating through most or all of the list elements. Linked lists were developed in 1955–1956, by Allen Newell , Cliff Shaw and Herbert A. Simon at RAND Corporation and Carnegie Mellon University as the primary data structure for their Information Processing Language (IPL). IPL
3024-571: The linked list approach. A later review article, "A Comparison of list-processing computer languages" by Bobrow and Raphael, appeared in Communications of the ACM in April 1964. Several operating systems developed by Technical Systems Consultants (originally of West Lafayette Indiana, and later of Chapel Hill, North Carolina) used singly linked lists as file structures. A directory entry pointed to
3087-417: The links to the different nodes). However, the linked list will be poor at finding the next person to remove and will need to search through the list until it finds that person. A dynamic array, on the other hand, will be poor at deleting nodes (or elements) as it cannot remove one node without individually shifting all the elements up the list by one. However, it is exceptionally easy to find the n th person in
3150-419: The list in both directions. In a doubly linked list, one can insert or delete a node in a constant number of operations given only that node's address. To do the same in a singly linked list, one must have the address of the pointer to that node, which is either the handle for the whole list (in case of the first node) or the link field in the previous node. Some algorithms require access in both directions. On
3213-443: The mathematical sense can be realized as a list with additional restrictions; that is, duplicate elements are disallowed and order is irrelevant. Sorting the list speeds up determining if a given item is already in the set, but in order to ensure the order, it requires more time to add new entry to the list. In efficient implementations, however, sets are implemented using self-balancing binary search trees or hash tables , rather than
SECTION 50
#17327823533833276-422: The next output node does not need special handling for empty lists. However, sentinel nodes use up extra space (especially in applications that use many short lists), and they may complicate other operations (such as the creation of a new empty list). However, if the circular list is used merely to simulate a linear list, one may avoid some of this complexity by adding a single sentinel node to every list, between
3339-511: The next. It is a data structure consisting of a collection of nodes which together represent a sequence . In its most basic form, each node contains data , and a reference (in other words, a link ) to the next node in the sequence. This structure allows for efficient insertion or removal of elements from any position in the sequence during iteration. More complex variants add additional links, allowing more efficient insertion or removal of nodes at arbitrary positions. A drawback of linked lists
3402-482: The other hand, doubly linked lists do not allow tail-sharing and cannot be used as persistent data structures . A circularly linked list may be a natural option to represent arrays that are naturally circular, e.g. the corners of a polygon , a pool of buffers that are used and released in FIFO ("first in, first out") order, or a set of processes that should be time-shared in round-robin order . In these applications,
3465-411: The performance of iteration. Moreover, arbitrarily many elements may be inserted into a linked list, limited only by the total memory available; while a dynamic array will eventually fill up its underlying array data structure and will have to reallocate—an expensive operation, one that may not even be possible if memory is fragmented, although the cost of reallocation can be averaged over insertions, and
3528-418: The procedures generally need extra arguments and more complicated base cases. Linear singly linked lists also allow tail-sharing , the use of a common final portion of sub-list as the terminal portion of two different lists. In particular, if a new node is added at the beginning of a list, the former list remains available as the tail of the new one—a simple example of a persistent data structure . Again, this
3591-527: The programming language Lisp , is to have each element of the list contain both its value and a pointer indicating the location of the next element in the list. This results in either a linked list or a tree , depending on whether the list has nested sublists. Some older Lisp implementations (such as the Lisp implementation of the Symbolics 3600) also supported "compressed lists" (using CDR coding ) which had
3654-571: The psychology of human cognition, and list processing". The problem of machine translation for natural language processing led Victor Yngve at Massachusetts Institute of Technology (MIT) to use linked lists as data structures in his COMIT programming language for computer research in the field of linguistics . A report on this language entitled "A programming language for mechanical translation" appeared in Mechanical Translation in 1958. Another early appearance of linked lists
3717-591: The size of the data. In contrast, a dynamic array requires only the space for the data itself (and a very small amount of control data). It can also be slow, and with a naïve allocator, wasteful, to allocate memory separately for each new element, a problem generally solved using memory pools . Some hybrid solutions try to combine the advantages of the two representations. Unrolled linked lists store several elements in each list node, increasing cache performance while decreasing memory overhead for references. CDR coding does both these as well, by replacing references with
3780-502: The source tree, and so can be thought of as discrete components: GLib, GObject, and GIO. These can be thought of as a software stack: GObject relies on GLib, and GIO provides higher-level functionality that uses both. GLib began as part of the GTK+ project, now named GTK. However, before releasing GTK+ version 2, the project's developers decided to separate code from GTK+ that was not for graphical user interfaces (GUIs), thus creating GLib as
3843-410: The term list may refer specifically to a linked list rather than an array. In class-based programming , lists are usually provided as instances of subclasses of a generic "list" class, and traversed via separate iterators . Many programming languages provide support for list data types , and have special syntax and semantics for lists and list operations. A list can often be constructed by writing
SECTION 60
#17327823533833906-575: Was by Hans Peter Luhn who wrote an internal IBM memorandum in January 1953 that suggested the use of linked lists in chained hash tables. LISP , standing for list processor, was created by John McCarthy in 1958 while he was at MIT and in 1960 he published its design in a paper in the Communications of the ACM , entitled "Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I". One of LISP's major data structures
3969-603: Was used by the authors to develop several early artificial intelligence programs, including the Logic Theory Machine, the General Problem Solver , and a computer chess program. Reports on their work appeared in IRE Transactions on Information Theory in 1956, and several conference proceedings from 1957 to 1959, including Proceedings of the Western Joint Computer Conference in 1957 and 1958, and Information Processing (Proceedings of
#382617