source: mainline/uspace/dist/src/sysel/lib/list.sy@ 051bc69a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 051bc69a was 051bc69a, checked in by Jiri Svoboda <jiri@…>, 16 years ago

Update SBI to rev. 244.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1--
2-- Copyright (c) 2010 Jiri Svoboda
3-- All rights reserved.
4--
5-- Redistribution and use in source and binary forms, with or without
6-- modification, are permitted provided that the following conditions
7-- are met:
8--
9-- o Redistributions of source code must retain the above copyright
10-- notice, this list of conditions and the following disclaimer.
11-- o Redistributions in binary form must reproduce the above copyright
12-- notice, this list of conditions and the following disclaimer in the
13-- documentation and/or other materials provided with the distribution.
14-- o The name of the author may not be used to endorse or promote products
15-- derived from this software without specific prior written permission.
16--
17-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18-- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19-- OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20-- IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21-- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22-- NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27--
28
29-- Doubly-linked list.
30class List/t is
31 var head : ListNode/t;
32
33 -- New empty list.
34 new() is
35 head = new ListNode/t();
36 head.prev = head;
37 head.next = head;
38 end
39
40 -- Append new entry at the end of the list.
41 fun Append(data : t) is
42 var n : ListNode/t;
43 var ntl : ListNode/t;
44
45 ntl = head.prev;
46
47 n = new ListNode/t();
48 n.data = data;
49
50 n.prev = ntl;
51 n.next = head;
52 n.head = head;
53
54 ntl.next = n;
55 head.prev = n;
56 end
57
58 -- Return first node in the list or @c nil if there is none.
59 prop First : ListNode/t is
60 get is
61 return get_first();
62 end
63 end
64
65 -- Return first node in the list or @c nil if there is none.
66 fun get_first() : ListNode/t is
67 if head.next == head then
68 return nil;
69 else
70 return head.next;
71 end
72 end
73end
74
75class ListNode/t is
76 var data : t;
77
78 var prev : ListNode/t;
79 var next : ListNode/t;
80 var head : ListNode/t;
81
82 -- Data stored in this node.
83 prop Data : t is
84 get is
85 return data;
86 end
87 end
88
89 -- Previous node in list.
90 prop Prev : ListNode/t is
91 get is
92 return get_prev();
93 end
94 end
95
96 -- Next node in list.
97 prop Next : ListNode/t is
98 get is
99 return get_next();
100 end
101 end
102
103 -- Remove node from list.
104 fun Remove() is
105 var p : ListNode/t;
106 var n : ListNode/t;
107
108 p = prev; n = next;
109 p.next = n;
110 n.prev = p;
111
112 prev = nil;
113 next = nil;
114 end
115
116 -- Get next node.
117 fun get_next() : ListNode/t is
118 if next != head then
119 return next;
120 else
121 return nil;
122 end
123 end
124
125 -- Get previous node.
126 fun get_prev() : ListNode/t is
127 if prev != head then
128 return next;
129 else
130 return nil;
131 end
132 end
133
134end
Note: See TracBrowser for help on using the repository browser.