summaryrefslogtreecommitdiff
path: root/mysys/queues.c
diff options
context:
space:
mode:
authormonty@mashka.mysql.fi <>2003-01-18 19:31:38 +0200
committermonty@mashka.mysql.fi <>2003-01-18 19:31:38 +0200
commit88cd4126e40d776611c73994ea91916f10b320a7 (patch)
tree464dcaca9cc63777f76692b3635b591fac0d6d39 /mysys/queues.c
parent529e4a76c5b60e41b2bf9b80d6036d92a765df13 (diff)
downloadmariadb-git-88cd4126e40d776611c73994ea91916f10b320a7.tar.gz
Simple code cleanups, ignore generated files
Diffstat (limited to 'mysys/queues.c')
-rw-r--r--mysys/queues.c72
1 files changed, 61 insertions, 11 deletions
diff --git a/mysys/queues.c b/mysys/queues.c
index fe642131d74..f077b38ca0b 100644
--- a/mysys/queues.c
+++ b/mysys/queues.c
@@ -24,7 +24,26 @@
#include <queues.h>
-/* Init queue */
+/*
+ Init queue
+
+ SYNOPSIS
+ init_queue()
+ queue Queue to initialise
+ max_elements Max elements that will be put in queue
+ offset_to_key Offset to key in element stored in queue
+ Used when sending pointers to compare function
+ max_at_top Set to 1 if you want biggest element on top.
+ compare Compare function for elements, takes 3 arguments.
+ first_cmp_arg First argument to compare function
+
+ NOTES
+ Will allocate max_element pointers for queue array
+
+ RETURN
+ 0 ok
+ 1 Could not allocate memory
+*/
int init_queue(QUEUE *queue, uint max_elements, uint offset_to_key,
pbool max_at_top, int (*compare) (void *, byte *, byte *),
@@ -43,15 +62,32 @@ int init_queue(QUEUE *queue, uint max_elements, uint offset_to_key,
DBUG_RETURN(0);
}
+
/*
- Reinitialize queue for new usage; Note that you can't currently resize
- the number of elements! If you need this, fix it :)
+ Reinitialize queue for other usage (deletes all elements)
+
+ SYNOPSIS
+ reinit_queue()
+ queue Queue to initialise
+ max_elements Max elements that will be put in queue
+ offset_to_key Offset to key in element stored in queue
+ Used when sending pointers to compare function
+ max_at_top Set to 1 if you want biggest element on top.
+ compare Compare function for elements, takes 3 arguments.
+ first_cmp_arg First argument to compare function
+
+ NOTES
+ You can't currently resize the number of elements! If you need this,
+ fix it :)
+
+ RETURN
+ 0 ok
+ EE_OUTOFMEMORY Wrong max_elements
*/
-
int reinit_queue(QUEUE *queue, uint max_elements, uint offset_to_key,
- pbool max_at_top, int (*compare) (void *, byte *, byte *),
- void *first_cmp_arg)
+ pbool max_at_top, int (*compare) (void *, byte *, byte *),
+ void *first_cmp_arg)
{
DBUG_ENTER("reinit_queue");
if (queue->max_elements < max_elements)
@@ -66,6 +102,21 @@ int reinit_queue(QUEUE *queue, uint max_elements, uint offset_to_key,
DBUG_RETURN(0);
}
+
+/*
+ Delete queue
+
+ SYNOPSIS
+ delete_queue()
+ queue Queue to delete
+
+ IMPLEMENTATION
+ Just free allocated memory.
+
+ NOTES
+ Can be called safely multiple times
+*/
+
void delete_queue(QUEUE *queue)
{
DBUG_ENTER("delete_queue");
@@ -116,7 +167,7 @@ byte *queue_remove(register QUEUE *queue, uint idx)
return 0;
#endif
{
- byte *element=queue->root[++idx]; /* Intern index starts from 1 */
+ byte *element=queue->root[++idx]; /* Intern index starts from 1 */
queue->root[idx]=queue->root[queue->elements--];
_downheap(queue,idx);
return element;
@@ -126,8 +177,7 @@ byte *queue_remove(register QUEUE *queue, uint idx)
/* Fix when element on top has been replaced */
#ifndef queue_replaced
-void queue_replaced(queue)
-QUEUE *queue;
+void queue_replaced(QUEUE *queue)
{
_downheap(queue,1);
}
@@ -169,8 +219,8 @@ void _downheap(register QUEUE *queue, uint idx)
static int queue_fix_cmp(QUEUE *queue, void **a, void **b)
{
return queue->compare(queue->first_cmp_arg,
- (char*) (*a)+queue->offset_to_key,
- (char*) (*b)+queue->offset_to_key);
+ (byte*) (*a)+queue->offset_to_key,
+ (byte*) (*b)+queue->offset_to_key);
}
/*