Qt 4.8
Public Functions | Private Functions | Properties | Static Private Attributes | List of all members
QInt64Set Class Reference

Public Functions

void clear ()
 
bool contains (quint64 key) const
 
void insert (quint64 key)
 
bool isValid () const
 
 QInt64Set (int capacity=64)
 
 ~QInt64Set ()
 

Private Functions

bool rehash (int capacity)
 

Properties

quint64m_array
 
int m_capacity
 
int m_count
 

Static Private Attributes

static const quint64 UNUSED = quint64(-1)
 

Detailed Description

Definition at line 1137 of file qtriangulator.cpp.

Constructors and Destructors

◆ QInt64Set()

QInt64Set::QInt64Set ( int  capacity = 64)
inline

Definition at line 1158 of file qtriangulator.cpp.

1159 {
1160  m_capacity = primeForCount(capacity);
1161  m_array = new quint64[m_capacity];
1162  if (m_array)
1163  clear();
1164  else
1165  m_capacity = 0;
1166 }
static int primeForCount(int count)
unsigned __int64 quint64
Definition: qglobal.h:943
quint64 * m_array

◆ ~QInt64Set()

QInt64Set::~QInt64Set ( )
inline

Definition at line 1141 of file qtriangulator.cpp.

1141 {if (m_array) delete[] m_array;}
quint64 * m_array

Functions

◆ clear()

void QInt64Set::clear ( )
inline

Definition at line 1229 of file qtriangulator.cpp.

1230 {
1231  Q_ASSERT_X(m_array, "QInt64Hash<T>::clear", "Hash set not allocated.");
1232  for (int i = 0; i < m_capacity; ++i)
1233  m_array[i] = UNUSED;
1234  m_count = 0;
1235 }
static const quint64 UNUSED
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
quint64 * m_array

◆ contains()

bool QInt64Set::contains ( quint64  key) const

Definition at line 1213 of file qtriangulator.cpp.

1214 {
1215  Q_ASSERT_X(m_array, "QInt64Hash<T>::contains", "Hash set not allocated.");
1216  int index = int(key % m_capacity);
1217  for (int i = 0; i < m_capacity; ++i) {
1218  index += i;
1219  if (index >= m_capacity)
1220  index -= m_capacity;
1221  if (m_array[index] == key)
1222  return true;
1223  if (m_array[index] == UNUSED)
1224  return false;
1225  }
1226  return false;
1227 }
static const quint64 UNUSED
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
int key
quint16 index
quint64 * m_array

◆ insert()

void QInt64Set::insert ( quint64  key)

Definition at line 1192 of file qtriangulator.cpp.

1193 {
1194  if (m_count > 3 * m_capacity / 4)
1196  Q_ASSERT_X(m_array, "QInt64Hash<T>::insert", "Hash set not allocated.");
1197  int index = int(key % m_capacity);
1198  for (int i = 0; i < m_capacity; ++i) {
1199  index += i;
1200  if (index >= m_capacity)
1201  index -= m_capacity;
1202  if (m_array[index] == key)
1203  return;
1204  if (m_array[index] == UNUSED) {
1205  ++m_count;
1206  m_array[index] = key;
1207  return;
1208  }
1209  }
1210  Q_ASSERT_X(0, "QInt64Hash<T>::insert", "Hash set full.");
1211 }
static const quint64 UNUSED
static int primeForCount(int count)
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
int key
quint16 index
bool rehash(int capacity)
quint64 * m_array

◆ isValid()

bool QInt64Set::isValid ( ) const
inline

Definition at line 1142 of file qtriangulator.cpp.

1142 {return m_array;}
quint64 * m_array

◆ rehash()

bool QInt64Set::rehash ( int  capacity)
private

Definition at line 1168 of file qtriangulator.cpp.

1169 {
1170  quint64 *oldArray = m_array;
1171  int oldCapacity = m_capacity;
1172 
1173  m_capacity = capacity;
1174  m_array = new quint64[m_capacity];
1175  if (m_array) {
1176  clear();
1177  if (oldArray) {
1178  for (int i = 0; i < oldCapacity; ++i) {
1179  if (oldArray[i] != UNUSED)
1180  insert(oldArray[i]);
1181  }
1182  delete[] oldArray;
1183  }
1184  return true;
1185  } else {
1186  m_capacity = oldCapacity;
1187  m_array = oldArray;
1188  return false;
1189  }
1190 }
static const quint64 UNUSED
void insert(quint64 key)
unsigned __int64 quint64
Definition: qglobal.h:943
quint64 * m_array

Properties

◆ m_array

quint64* QInt64Set::m_array
private

Definition at line 1151 of file qtriangulator.cpp.

◆ m_capacity

int QInt64Set::m_capacity
private

Definition at line 1152 of file qtriangulator.cpp.

◆ m_count

int QInt64Set::m_count
private

Definition at line 1153 of file qtriangulator.cpp.

◆ UNUSED

const quint64 QInt64Set::UNUSED = quint64(-1)
staticprivate

Definition at line 1149 of file qtriangulator.cpp.


The documentation for this class was generated from the following file: