source: proiecte/swift/trunk/lib/hoard-371/src/heaplayers/freesllist.h @ 176

Last change on this file since 176 was 176, checked in by (none), 14 years ago
  • imported repo from "guagal"
File size: 1.1 KB
Line 
1// -*- C++ -*-
2
3#ifndef _FREESLLIST_H_
4#define _FREESLLIST_H_
5
6#include <assert.h>
7
8/**
9 * @class FreeSLList
10 * @brief A "memory neutral" singly-linked list,
11 *
12 * Uses the free space in objects to store
13 * the pointers.
14 */
15
16
17class FreeSLList {
18public:
19
20  inline void clear (void) {
21    head.next = NULL;
22  }
23
24  class Entry;
25 
26  /// Get the head of the list.
27  inline Entry * get (void) {
28    const Entry * e = head.next;
29    if (e == NULL) {
30      return NULL;
31    }
32    head.next = e->next;
33    return const_cast<Entry *>(e);
34  }
35
36  inline Entry * remove (void) {
37    const Entry * e = head.next;
38    if (e == NULL) {
39      return NULL;
40    }
41    head.next = e->next;
42    return const_cast<Entry *>(e);
43  }
44 
45  inline void insert (void * e) {
46    Entry * entry = reinterpret_cast<Entry *>(e);
47    entry->next = head.next;
48    head.next = entry;
49  }
50
51  class Entry {
52  public:
53    Entry (void)
54      : next (NULL)
55    {}
56    Entry * next;
57#if 1
58  private:
59    Entry (const Entry&);
60    Entry& operator=(const Entry&);
61#endif
62  };
63 
64private:
65  Entry head;
66};
67
68
69#endif
70
71
72
73
Note: See TracBrowser for help on using the repository browser.