Subversion Repositories HelenOS-doc

Rev

Rev 73 | Rev 77 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 73 Rev 74
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<chapter id="ds">
2
<chapter id="ds">
3
  <?dbhtml filename="ds.html"?>
3
  <?dbhtml filename="ds.html"?>
4
 
4
 
5
  <title>Data structures</title>
5
  <title>Data structures</title>
6
 
6
 
7
  <para>There is lots of data that either flows through various HelenOS
7
  <para>There is lots of data that either flows through various HelenOS
8
  subsystems or is stored directly by them. Each subsystem uses its own data
8
  subsystems or is stored directly by them. Each subsystem uses its own data
9
  structures to represent the data. These data structures need to be kept
9
  structures to represent the data. These data structures need to be kept
10
  somewhere. In order to work efficiently, HelenOS, and especially its kernel,
10
  somewhere. In order to work efficiently, HelenOS, and especially its kernel,
11
  deploys several house keeping data types that are designed to faciliate
11
  deploys several house keeping data types that are designed to faciliate
12
  managing other data structures. Most of them serve like generic
12
  managing other data structures. Most of them serve like generic
13
  containers.</para>
13
  containers.</para>
14
 
14
 
15
  <section>
15
  <section>
16
    <title>Lists</title>
16
    <title>Lists</title>
17
 
17
 
18
    <indexterm>
18
    <indexterm>
19
      <primary>linked list</primary>
19
      <primary>linked list</primary>
20
    </indexterm>
20
    </indexterm>
21
 
21
 
22
    <para>HelenOS uses doubly-circularly-linked lists to bind related data
22
    <para>HelenOS uses doubly-circularly-linked lists to bind related data
23
    together. Lists are composed of an independent sentinel node called head
23
    together. Lists are composed of an independent sentinel node called head
24
    and links that are always part of the object that is to be put into the
24
    and links that are always part of the object that is to be put into the
25
    list. Adding items to a list thus doesn't require any further memory
25
    list. Adding items to a list thus doesn't require any further memory
26
    allocations. Head and each link then contains forward and backward
26
    allocations. Head and each link then contains forward and backward
27
    pointer. An empty list is composed of a sole head whose both pointers
27
    pointer. An empty list is composed of a sole head whose both pointers
28
    reference the head itself. The expense of two times bigger memory
28
    reference the head itself. The expense of two times bigger memory
29
    consumption as compared to memory consumption of singly linked lists is
29
    consumption as compared to memory consumption of singly linked lists is
30
    justified by constant insertion and removal times at random positions
30
    justified by constant insertion and removal times at random positions
31
    within the list.</para>
31
    within the list.</para>
32
 
32
 
33
    <para>Lists are frequently used to implement FIFO behaviour (e.g.
33
    <para>Lists are frequently used to implement FIFO behaviour (e.g.
34
    scheduler run queues or synchronization wait queues). Contrary to the FIFO
34
    scheduler run queues or synchronization wait queues). Contrary to the FIFO
35
    type, which is also supported by HelenOS, they don't take up any unused
35
    type, which is also supported by HelenOS, they don't take up any unused
36
    space and are more general. On the other hand, they are slower than
36
    space and are more general. On the other hand, they are slower than
37
    in-array FIFOs and can be hardly used to implement buffers.</para>
37
    in-array FIFOs and can be hardly used to implement buffers.</para>
38
  </section>
38
  </section>
39
 
39
 
40
  <section>
40
  <section>
41
    <title>FIFO queues</title>
41
    <title>FIFO queues</title>
42
 
42
 
43
    <indexterm>
43
    <indexterm>
44
      <primary>FIFO queue</primary>
44
      <primary>FIFO queue</primary>
45
    </indexterm>
45
    </indexterm>
46
 
46
 
47
    <para>FIFO queues are implemented as either statically or dynamically
47
    <para>FIFO queues are implemented as either statically or dynamically
48
    allocated arrays<footnote>
48
    allocated arrays<footnote>
49
        <para>Depending on the array size.</para>
49
        <para>Depending on the array size.</para>
50
      </footnote> of some generic type with two indices. The first index
50
      </footnote> of some generic type with two indices. The first index
51
    points to the head of the FIFO queue and the other points to the tail
51
    points to the head of the FIFO queue and the other points to the tail
52
    thereof. There can be as many items in the FIFO as is the number of
52
    thereof. There can be as many items in the FIFO as is the number of
53
    elements in the array and no more. The indices are taken modulo size of
53
    elements in the array and no more. The indices are taken modulo size of
54
    the queue because as a consequence of insertions and deletions, the tail
54
    the queue because as a consequence of insertions and deletions, the tail
55
    can have numericaly lower index than the head.</para>
55
    can have numericaly lower index than the head.</para>
56
 
56
 
57
    <para>FIFO queues are used, for example, in ASID management code to store
57
    <para>FIFO queues are used, for example, in ASID management code to store
58
    inactive ASIDs or in userspace keyboard driver to buffer read
58
    inactive ASIDs or in userspace keyboard driver to buffer read
59
    characters.</para>
59
    characters.</para>
60
 
60
 
61
    <figure>
61
    <figure>
62
      <mediaobject id="fifo" xreflabel="">
62
      <mediaobject id="fifo" xreflabel="">
63
        <imageobject role="html">
63
        <imageobject role="html">
64
          <imagedata fileref="images/fifo.png" format="PNG" />
64
          <imagedata fileref="images/fifo.png" format="PNG" />
65
        </imageobject>
65
        </imageobject>
66
 
66
 
67
        <imageobject role="fop">
67
        <imageobject role="fop">
68
          <imagedata fileref="images.vector/fifo.svg" format="SVG" />
68
          <imagedata fileref="images.vector/fifo.svg" format="SVG" />
69
        </imageobject>
69
        </imageobject>
70
      </mediaobject>
70
      </mediaobject>
71
 
71
 
72
      <title>FIFO queue showing the wrap around the end of the array.</title>
72
      <title>FIFO queue showing the wrap around the end of the array.</title>
73
    </figure>
73
    </figure>
74
  </section>
74
  </section>
75
 
75
 
76
  <section>
76
  <section id="hashtables">
77
    <title>Hash tables</title>
77
    <title>Hash tables</title>
78
 
78
 
79
    <indexterm>
79
    <indexterm>
80
      <primary>hash table</primary>
80
      <primary>hash table</primary>
81
    </indexterm>
81
    </indexterm>
82
 
82
 
83
    <para>The kernel, as well as userspace, provides hash table data type
83
    <para>The kernel, as well as userspace, provides hash table data type
84
    which uses separate chaining. The hash table type is very generic in that
84
    which uses separate chaining. The hash table type is very generic in that
85
    it forces the user to supply methods for computing the hash index,
85
    it forces the user to supply methods for computing the hash index,
86
    comparing items against a set of keys and the item removal callback
86
    comparing items against a set of keys and the item removal callback
87
    function. Besides these virtual operations, the hash table is composed of
87
    function. Besides these virtual operations, the hash table is composed of
88
    a dynamically allocated array of list heads that represent each chain,
88
    a dynamically allocated array of list heads that represent each chain,
89
    number of chains and the maximal number of keys.</para>
89
    number of chains and the maximal number of keys.</para>
90
  </section>
90
  </section>
91
 
91
 
92
  <section>
92
  <section>
93
    <title>Bitmaps</title>
93
    <title>Bitmaps</title>
94
 
94
 
95
    <indexterm>
95
    <indexterm>
96
      <primary>bitmap</primary>
96
      <primary>bitmap</primary>
97
    </indexterm>
97
    </indexterm>
98
 
98
 
99
    <para>Several bitmap operations such as clearing or setting consecutive
99
    <para>Several bitmap operations such as clearing or setting consecutive
100
    bit sequences as well as copying portions of one bitmap into another one
100
    bit sequences as well as copying portions of one bitmap into another one
101
    are supported.</para>
101
    are supported.</para>
102
  </section>
102
  </section>
103
 
103
 
104
  <section>
104
  <section>
105
    <title>B+trees</title>
105
    <title>B+trees</title>
106
 
106
 
107
    <indexterm>
107
    <indexterm>
108
      <primary>B-tree</primary>
108
      <primary>B-tree</primary>
109
    </indexterm>
109
    </indexterm>
110
 
110
 
111
    <para>HelenOS makes use of a variant of B-tree called B+tree. B+trees, in
111
    <para>HelenOS makes use of a variant of B-tree called B+tree. B+trees, in
112
    HelenOS implementation, are 3-4-5 balanced trees. They are characteristic
112
    HelenOS implementation, are 3-4-5 balanced trees. They are characteristic
113
    by the fact that values are kept only in the leaf-level nodes and that
113
    by the fact that values are kept only in the leaf-level nodes and that
114
    these nodes are linked together in a list. This data structure has
114
    these nodes are linked together in a list. This data structure has
115
    logaritmic search, insertion and deletion times and, thanks to the
115
    logaritmic search, insertion and deletion times and, thanks to the
116
    leaf-level list, provides fantastic means of walking the nodes containing
116
    leaf-level list, provides fantastic means of walking the nodes containing
117
    data. Moreover, B+trees can be used for easy storing, resizing and merging
117
    data. Moreover, B+trees can be used for easy storing, resizing and merging
118
    of disjunctive intervals.</para>
118
    of disjunctive intervals.</para>
119
 
119
 
120
    <figure>
120
    <figure>
121
      <mediaobject id="btree" xreflabel="">
121
      <mediaobject id="btree" xreflabel="">
122
        <imageobject role="html">
122
        <imageobject role="html">
123
          <imagedata fileref="images/btree.png" format="PNG" />
123
          <imagedata fileref="images/btree.png" format="PNG" />
124
        </imageobject>
124
        </imageobject>
125
 
125
 
126
        <imageobject role="fop">
126
        <imageobject role="fop">
127
          <imagedata fileref="images.vector/btree.svg" format="SVG" />
127
          <imagedata fileref="images.vector/btree.svg" format="SVG" />
128
        </imageobject>
128
        </imageobject>
129
      </mediaobject>
129
      </mediaobject>
130
 
130
 
131
      <title>B+tree containing keys ranging from 1 to 12.</title>
131
      <title>B+tree containing keys ranging from 1 to 12.</title>
132
    </figure>
132
    </figure>
133
  </section>
133
  </section>
134
</chapter>
134
</chapter>