Qt 4.8
Classes | Public Types | Public Functions | Static Public Functions | Public Variables | Static Public Variables | List of all members
QMapData Struct Reference

#include <qmap.h>

Classes

struct  Node
 

Public Types

enum  { LastLevel = 11, Sparseness = 3 }
 

Public Functions

void continueFreeData (int offset)
 
Nodenode_create (Node *update[], int offset)
 
Nodenode_create (Node *update[], int offset, int alignment)
 Creates a new node inside the data structure. More...
 
void node_delete (Node *update[], int offset, Node *node)
 

Static Public Functions

static QMapDatacreateData ()
 
static QMapDatacreateData (int alignment)
 

Public Variables

QMapDatabackward
 
QMapDataforward [QMapData::LastLevel+1]
 
uint insertInOrder: 1
 
uint randomBits
 
QBasicAtomicInt ref
 
uint reserved: 29
 
uint sharable: 1
 
int size
 
uint strictAlignment: 1
 
int topLevel
 

Static Public Variables

static QMapData shared_null
 

Detailed Description

Definition at line 61 of file qmap.h.

Enumerations

◆ anonymous enum

anonymous enum
Enumerator
LastLevel 
Sparseness 

Definition at line 67 of file qmap.h.

Functions

◆ continueFreeData()

void QMapData::continueFreeData ( int  offset)

Definition at line 82 of file qmap.cpp.

Referenced by QMap< int, QFrameInfo >::freeData().

83 {
84  Node *e = reinterpret_cast<Node *>(this);
85  Node *cur = e->forward[0];
86  Node *prev;
87  while (cur != e) {
88  prev = cur;
89  cur = cur->forward[0];
90  if (strictAlignment)
91  qFreeAligned(reinterpret_cast<char *>(prev) - offset);
92  else
93  qFree(reinterpret_cast<char *>(prev) - offset);
94  }
95  delete this;
96 }
Q_CORE_EXPORT void qFree(void *ptr)
Definition: qmalloc.cpp:58
uint strictAlignment
Definition: qmap.h:77
Q_CORE_EXPORT void qFreeAligned(void *ptr)
Definition: qmalloc.cpp:118

◆ createData() [1/2]

QMapData * QMapData::createData ( )
static

Definition at line 59 of file qmap.cpp.

Referenced by QMap< int, QFrameInfo >::detach_helper(), and QMap< int, QFrameInfo >::operator==().

60 {
61  return createData(0);
62 }
static QMapData * createData()
Definition: qmap.cpp:59

◆ createData() [2/2]

QMapData * QMapData::createData ( int  alignment)
static

Definition at line 64 of file qmap.cpp.

65 {
66  QMapData *d = new QMapData;
67  Q_CHECK_PTR(d);
68  Node *e = reinterpret_cast<Node *>(d);
69  e->backward = e;
70  e->forward[0] = e;
71  d->ref = 1;
72  d->topLevel = 0;
73  d->size = 0;
74  d->randomBits = 0;
75  d->insertInOrder = false;
76  d->sharable = true;
77  d->strictAlignment = alignment > 8;
78  d->reserved = 0;
79  return d;
80 }
double d
Definition: qnumeric_p.h:62
int size
Definition: qmap.h:73
uint randomBits
Definition: qmap.h:74
QBasicAtomicInt ref
Definition: qmap.h:71
int topLevel
Definition: qmap.h:72
uint strictAlignment
Definition: qmap.h:77
uint sharable
Definition: qmap.h:76
uint insertInOrder
Definition: qmap.h:75
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853
Definition: qmap.h:61
uint reserved
Definition: qmap.h:78

◆ node_create() [1/2]

QMapData::Node * QMapData::node_create ( Node update[],
int  offset 
)

Definition at line 98 of file qmap.cpp.

Referenced by QMap< int, QFrameInfo >::node_create().

99 {
100  return node_create(update, offset, 0);
101 }
Node * node_create(Node *update[], int offset)
Definition: qmap.cpp:98

◆ node_create() [2/2]

QMapData::Node * QMapData::node_create ( Node update[],
int  offset,
int  alignment 
)

Creates a new node inside the data structure.

update is an array with pointers to the node after which the new node should be inserted. Because of the strange skip list data structure there could be several pointers to this node on different levels. offset is an amount of bytes that needs to reserved just before the QMapData::Node structure.

alignment dictates the alignment for the data.

Warning
This function is not part of the public interface.
Since
4.6

Definition at line 117 of file qmap.cpp.

118 {
119  int level = 0;
120  uint mask = (1 << Sparseness) - 1;
121 
122  while ((randomBits & mask) == mask && level < LastLevel) {
123  ++level;
124  mask <<= Sparseness;
125  }
126 
127  if (level > topLevel) {
128  Node *e = reinterpret_cast<Node *>(this);
129  level = ++topLevel;
130  e->forward[level] = e;
131  update[level] = e;
132  }
133 
134  ++randomBits;
135  if (level == 3 && !insertInOrder)
136  randomBits = qrand();
137 
138  void *concreteNode = strictAlignment ?
139  qMallocAligned(offset + sizeof(Node) + level * sizeof(Node *), alignment) :
140  qMalloc(offset + sizeof(Node) + level * sizeof(Node *));
141  Q_CHECK_PTR(concreteNode);
142 
143  Node *abstractNode = reinterpret_cast<Node *>(reinterpret_cast<char *>(concreteNode) + offset);
144 
145  abstractNode->backward = update[0];
146  update[0]->forward[0]->backward = abstractNode;
147 
148  for (int i = level; i >= 0; i--) {
149  abstractNode->forward[i] = update[i]->forward[i];
150  update[i]->forward[i] = abstractNode;
151  update[i] = abstractNode;
152  }
153  ++size;
154  return abstractNode;
155 }
Q_CORE_EXPORT void * qMallocAligned(size_t size, size_t alignment)
Definition: qmalloc.cpp:68
Q_CORE_EXPORT void * qMalloc(size_t size)
Definition: qmalloc.cpp:53
int size
Definition: qmap.h:73
Q_CORE_EXPORT int qrand()
uint randomBits
Definition: qmap.h:74
int topLevel
Definition: qmap.h:72
uint strictAlignment
Definition: qmap.h:77
unsigned int uint
Definition: qglobal.h:996
uint insertInOrder
Definition: qmap.h:75
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853

◆ node_delete()

void QMapData::node_delete ( Node update[],
int  offset,
Node node 
)

Definition at line 157 of file qmap.cpp.

Referenced by QMap< int, QFrameInfo >::node_create().

158 {
159  node->forward[0]->backward = node->backward;
160 
161  for (int i = 0; i <= topLevel; ++i) {
162  if (update[i]->forward[i] != node)
163  break;
164  update[i]->forward[i] = node->forward[i];
165  }
166  --size;
167  if (strictAlignment)
168  qFreeAligned(reinterpret_cast<char *>(node) - offset);
169  else
170  qFree(reinterpret_cast<char *>(node) - offset);
171 }
Q_CORE_EXPORT void qFree(void *ptr)
Definition: qmalloc.cpp:58
int size
Definition: qmap.h:73
int topLevel
Definition: qmap.h:72
uint strictAlignment
Definition: qmap.h:77
QMapData * forward[QMapData::LastLevel+1]
Definition: qmap.h:70
Q_CORE_EXPORT void qFreeAligned(void *ptr)
Definition: qmalloc.cpp:118

Properties

◆ backward

QMapData* QMapData::backward

Definition at line 69 of file qmap.h.

◆ forward

QMapData* QMapData::forward[QMapData::LastLevel+1]

Definition at line 70 of file qmap.h.

Referenced by QMap< int, QFrameInfo >::freeData(), and node_delete().

◆ insertInOrder

uint QMapData::insertInOrder

Definition at line 75 of file qmap.h.

Referenced by createData(), and node_create().

◆ randomBits

uint QMapData::randomBits

Definition at line 74 of file qmap.h.

Referenced by createData(), node_create(), and node_delete().

◆ ref

QBasicAtomicInt QMapData::ref

Definition at line 71 of file qmap.h.

Referenced by createData(), node_delete(), and QMap< int, QFrameInfo >::operator=().

◆ reserved

uint QMapData::reserved

Definition at line 78 of file qmap.h.

Referenced by createData().

◆ sharable

uint QMapData::sharable

Definition at line 76 of file qmap.h.

Referenced by createData().

◆ shared_null

QMapData QMapData::shared_null
static
Initial value:
= {
{ &shared_null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
Q_BASIC_ATOMIC_INITIALIZER(1), 0, 0, 0, false, true, false, 0
}

Definition at line 91 of file qmap.h.

◆ size

int QMapData::size

Definition at line 73 of file qmap.h.

Referenced by createData(), node_create(), and node_delete().

◆ strictAlignment

uint QMapData::strictAlignment

Definition at line 77 of file qmap.h.

Referenced by continueFreeData(), createData(), node_create(), and node_delete().

◆ topLevel

int QMapData::topLevel

Definition at line 72 of file qmap.h.

Referenced by createData(), node_create(), and node_delete().


The documentation for this struct was generated from the following files: