File: saveq.c

package info (click to toggle)
rscheme 0.7.2-1.1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 10,672 kB
  • ctags: 12,430
  • sloc: lisp: 37,104; ansic: 29,763; cpp: 2,630; sh: 1,677; makefile: 568; yacc: 202; lex: 175; perl: 33
file content (62 lines) | stat: -rw-r--r-- 1,482 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*-----------------------------------------------------------------*-C-*---
 * File:    handc/heapi/saveq.c
 *
 *          Copyright (C)1997 Donovan Kolbly <d.kolbly@rscheme.org>
 *          as part of the RScheme project, licensed for free use.
 *          See <http://www.rscheme.org/> for the latest information.
 *
 * File version:     1.6
 * File mod date:    1997.11.29 23:10:44
 * System build:     v0.7.2, 97.12.21
 *
 *------------------------------------------------------------------------*/

#include <stdlib.h>
#include <rscheme/smemory.h>
#include "saveq.h"

void hi_init_queue_n( SaveQueue *q, UINT_32 init_cap )
{
  q->count = 0;
  q->cap = init_cap;
  q->contents = (struct queue_entry *)
    malloc( init_cap * sizeof(struct queue_entry) );
  q->ptr = 0;
}

void hi_init_queue( SaveQueue *q )
{
  hi_init_queue_n( q, 32 );
}

void hi_enqueue_item2( SaveQueue *q, obj item, obj orig_class )
{
  if (q->count >= q->cap)
    {
      q->cap *= 2;
      q->contents = (struct queue_entry *)
	realloc( q->contents, q->cap * sizeof(struct queue_entry) );
    }
  q->contents[q->count].thing = item;
  q->contents[q->count].orig_class = orig_class;
  q->count++;
}

void hi_enqueue_item( SaveQueue *q, obj item )
{
  hi_enqueue_item2( q, item, CLASSOF_PTR(item) );
}

struct queue_entry *hi_dequeue_item( SaveQueue *q )
{
  if (q->ptr < q->count)
    return &q->contents[q->ptr++];
  else
    return NULL;
}


void hi_free_queue( SaveQueue *q )
{
  free( q->contents );
}