Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
LSH
lsh
Commits
4dc21724
Commit
4dc21724
authored
Oct 07, 2000
by
Niels Möller
Browse files
* src/queue.c: New struct-type string_queue, and corresponding
functions. Rev: src/queue.c:1.10 Rev: src/queue.h:1.10
parent
7c5963e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/queue.c
View file @
4dc21724
...
...
@@ -35,6 +35,7 @@
static
void
do_object_queue_mark
(
struct
lsh_queue
*
q
,
void
(
*
mark
)(
struct
lsh_object
*
o
));
static
void
do_object_queue_free
(
struct
lsh_queue
*
q
);
static
void
do_string_queue_free
(
struct
lsh_queue
*
q
);
#define GABA_DEFINE
#include "queue.h.x"
...
...
@@ -302,4 +303,90 @@ void object_queue_kill(struct object_queue *q)
do_object_queue_free
(
&
q
->
q
);
}
/* String queues */
static
struct
string_queue_node
*
make_string_queue_node
(
struct
lsh_string
*
s
)
{
struct
string_queue_node
*
n
;
NEW_SPACE
(
n
);
n
->
s
=
s
;
return
n
;
}
void
string_queue_init
(
struct
string_queue
*
q
)
{
lsh_queue_init
(
&
q
->
q
);
q
->
length
=
0
;
}
int
string_queue_is_empty
(
struct
string_queue
*
q
)
{
assert
(
EMPTYP
(
&
q
->
q
)
==
!
q
->
length
);
return
!
q
->
length
;
}
void
string_queue_add_head
(
struct
string_queue
*
q
,
struct
lsh_string
*
s
)
{
lsh_queue_add_head
(
&
q
->
q
,
&
make_string_queue_node
(
s
)
->
header
);
q
->
length
++
;
}
void
string_queue_add_tail
(
struct
string_queue
*
q
,
struct
lsh_string
*
s
)
{
lsh_queue_add_tail
(
&
q
->
q
,
&
make_string_queue_node
(
s
)
->
header
);
q
->
length
++
;
}
static
struct
lsh_string
*
string_queue_get_contents
(
struct
lsh_queue_node
*
l
)
{
struct
string_queue_node
*
n
=
(
struct
string_queue_node
*
)
l
;
struct
lsh_string
*
res
=
n
->
s
;
lsh_space_free
(
n
);
return
res
;
}
static
struct
lsh_string
*
string_queue_peek
(
struct
lsh_queue_node
*
n
)
{
return
(
(
struct
string_queue_node
*
)
n
)
->
s
;
}
struct
lsh_string
*
string_queue_remove_head
(
struct
string_queue
*
q
)
{
q
->
length
--
;
return
string_queue_get_contents
(
lsh_queue_remove_head
(
&
q
->
q
));
}
struct
lsh_string
*
string_queue_remove_tail
(
struct
string_queue
*
q
)
{
q
->
length
--
;
return
string_queue_get_contents
(
lsh_queue_remove_tail
(
&
q
->
q
));
}
struct
lsh_string
*
string_queue_peek_head
(
struct
string_queue
*
q
)
{
return
EMPTYP
(
&
q
->
q
)
?
NULL
:
string_queue_peek
(
q
->
q
.
head
);
}
struct
lsh_string
*
string_queue_peek_tail
(
struct
string_queue
*
q
)
{
return
EMPTYP
(
&
q
->
q
)
?
NULL
:
string_queue_peek
(
q
->
q
.
tailprev
);
}
static
void
do_string_queue_free
(
struct
lsh_queue
*
q
)
{
FOR_QUEUE
(
q
,
struct
string_queue_node
*
,
n
)
{
lsh_string_free
(
n
->
s
);
lsh_space_free
(
n
);
}
}
src/queue.h
View file @
4dc21724
...
...
@@ -128,4 +128,31 @@ struct object_list *queue_to_list_and_kill(struct object_queue *q);
#define FOR_OBJECT_QUEUE_REMOVE(q, n) \
do { (q)->length--; lsh_queue_remove(n##_this); } while(0)
/* String queue */
struct
string_queue_node
{
struct
lsh_queue_node
header
;
struct
lsh_string
*
s
;
};
/* GABA:
(struct
(name string_queue)
(vars
(length . UINT32)
(q indirect-special "struct lsh_queue"
#f do_string_queue_free)))
*/
void
string_queue_init
(
struct
string_queue
*
q
);
int
string_queue_is_empty
(
struct
string_queue
*
q
);
void
string_queue_add_head
(
struct
string_queue
*
q
,
struct
lsh_string
*
o
);
void
string_queue_add_tail
(
struct
string_queue
*
q
,
struct
lsh_string
*
o
);
struct
lsh_string
*
string_queue_remove_head
(
struct
string_queue
*
q
);
struct
lsh_string
*
string_queue_remove_tail
(
struct
string_queue
*
q
);
struct
lsh_string
*
string_queue_peek_head
(
struct
string_queue
*
q
);
struct
lsh_string
*
string_queue_peek_tail
(
struct
string_queue
*
q
);
#endif
/* LSH_QUEUE_H_INCLUDED */
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment