1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:27:34 +00:00

Coding style fixes in AK.

This commit is contained in:
Andreas Kling 2019-01-19 22:53:05 +01:00
parent b413e234e1
commit b75ee4aacb
12 changed files with 126 additions and 126 deletions

View file

@ -63,8 +63,8 @@ public:
bool operator==(const Iterator& other) const { return m_node == other.m_node; }
Iterator& operator++() { m_node = m_node->next; return *this; }
T& operator*() { return m_node->value; }
bool isEnd() const { return !m_node; }
static Iterator universalEnd() { return Iterator(nullptr); }
bool is_end() const { return !m_node; }
static Iterator universal_end() { return Iterator(nullptr); }
private:
friend class DoublyLinkedList;
explicit Iterator(DoublyLinkedList::Node* node) : m_node(node) { }
@ -72,7 +72,7 @@ public:
};
Iterator begin() { return Iterator(m_head); }
Iterator end() { return Iterator::universalEnd(); }
Iterator end() { return Iterator::universal_end(); }
class ConstIterator {
public:
@ -80,8 +80,8 @@ public:
bool operator==(const ConstIterator& other) const { return m_node == other.m_node; }
ConstIterator& operator++() { m_node = m_node->next; return *this; }
const T& operator*() const { return m_node->value; }
bool isEnd() const { return !m_node; }
static ConstIterator universalEnd() { return ConstIterator(nullptr); }
bool is_end() const { return !m_node; }
static ConstIterator universal_end() { return ConstIterator(nullptr); }
private:
friend class DoublyLinkedList;
explicit ConstIterator(const DoublyLinkedList::Node* node) : m_node(node) { }
@ -89,7 +89,7 @@ public:
};
ConstIterator begin() const { return ConstIterator(m_head); }
ConstIterator end() const { return ConstIterator::universalEnd(); }
ConstIterator end() const { return ConstIterator::universal_end(); }
ConstIterator find(const T& value) const
{

View file

@ -23,7 +23,7 @@ bool FileSystemPath::canonicalize(bool resolve_symbolic_links)
continue;
if (part == "..") {
if (!canonical_parts.is_empty())
canonical_parts.takeLast();
canonical_parts.take_last();
continue;
}
if (!part.is_empty())

View file

@ -59,73 +59,73 @@ public:
public:
bool operator!=(const Iterator& other) const
{
if (m_isEnd && other.m_isEnd)
if (m_is_end && other.m_is_end)
return false;
return &m_table != &other.m_table
|| m_isEnd != other.m_isEnd
|| m_bucketIndex != other.m_bucketIndex
|| m_bucketIterator != other.m_bucketIterator;
|| m_is_end != other.m_is_end
|| m_bucket_index != other.m_bucket_index
|| m_bucket_iterator != other.m_bucket_iterator;
}
bool operator==(const Iterator& other) const { return !(*this != other); }
T& operator*()
{
#ifdef HASHTABLE_DEBUG
kprintf("retrieve { bucketIndex: %u, isEnd: %u }\n", m_bucketIndex, m_isEnd);
kprintf("retrieve { bucket_index: %u, is_end: %u }\n", m_bucket_index, m_is_end);
#endif
return *m_bucketIterator;
return *m_bucket_iterator;
}
Iterator& operator++()
{
skipToNext();
skip_to_next();
return *this;
}
void skipToNext()
void skip_to_next()
{
#ifdef HASHTABLE_DEBUG
unsigned pass = 0;
#endif
while (!m_isEnd) {
while (!m_is_end) {
#ifdef HASHTABLE_DEBUG
++pass;
kprintf("skipToNext pass %u, m_bucketIndex=%u\n", pass, m_bucketIndex);
kprintf("skip_to_next pass %u, m_bucket_index=%u\n", pass, m_bucket_index);
#endif
if (m_bucketIterator.isEnd()) {
++m_bucketIndex;
if (m_bucketIndex >= m_table.capacity()) {
m_isEnd = true;
if (m_bucket_iterator.is_end()) {
++m_bucket_index;
if (m_bucket_index >= m_table.capacity()) {
m_is_end = true;
return;
}
m_bucketIterator = m_table.m_buckets[m_bucketIndex].chain.begin();
m_bucket_iterator = m_table.m_buckets[m_bucket_index].chain.begin();
} else {
++m_bucketIterator;
++m_bucket_iterator;
}
if (!m_bucketIterator.isEnd())
if (!m_bucket_iterator.is_end())
return;
}
}
private:
friend class HashTable;
explicit Iterator(HashTable& table, bool isEnd, typename DoublyLinkedList<T>::Iterator bucketIterator = DoublyLinkedList<T>::Iterator::universalEnd(), unsigned bucketIndex = 0)
explicit Iterator(HashTable& table, bool is_end, typename DoublyLinkedList<T>::Iterator bucket_iterator = DoublyLinkedList<T>::Iterator::universal_end(), unsigned bucket_index = 0)
: m_table(table)
, m_bucketIndex(bucketIndex)
, m_isEnd(isEnd)
, m_bucketIterator(bucketIterator)
, m_bucket_index(bucket_index)
, m_is_end(is_end)
, m_bucket_iterator(bucket_iterator)
{
if (!isEnd && !m_table.is_empty() && !(m_bucketIterator != DoublyLinkedList<T>::Iterator::universalEnd())) {
if (!is_end && !m_table.is_empty() && !(m_bucket_iterator != DoublyLinkedList<T>::Iterator::universal_end())) {
#ifdef HASHTABLE_DEBUG
kprintf("bucket iterator init!\n");
#endif
m_bucketIterator = m_table.m_buckets[0].chain.begin();
if (m_bucketIterator.isEnd())
skipToNext();
m_bucket_iterator = m_table.m_buckets[0].chain.begin();
if (m_bucket_iterator.is_end())
skip_to_next();
}
}
HashTable& m_table;
unsigned m_bucketIndex { 0 };
bool m_isEnd { false };
typename DoublyLinkedList<T>::Iterator m_bucketIterator;
unsigned m_bucket_index { 0 };
bool m_is_end { false };
typename DoublyLinkedList<T>::Iterator m_bucket_iterator;
};
Iterator begin() { return Iterator(*this, is_empty()); }
@ -135,75 +135,75 @@ public:
public:
bool operator!=(const ConstIterator& other) const
{
if (m_isEnd && other.m_isEnd)
if (m_is_end && other.m_is_end)
return false;
return &m_table != &other.m_table
|| m_isEnd != other.m_isEnd
|| m_bucketIndex != other.m_bucketIndex
|| m_bucketIterator != other.m_bucketIterator;
|| m_is_end != other.m_is_end
|| m_bucket_index != other.m_bucket_index
|| m_bucket_iterator != other.m_bucket_iterator;
}
bool operator==(const ConstIterator& other) const { return !(*this != other); }
const T& operator*() const
{
#ifdef HASHTABLE_DEBUG
kprintf("retrieve { bucketIndex: %u, isEnd: %u }\n", m_bucketIndex, m_isEnd);
kprintf("retrieve { bucket_index: %u, is_end: %u }\n", m_bucket_index, m_is_end);
#endif
return *m_bucketIterator;
return *m_bucket_iterator;
}
ConstIterator& operator++()
{
skipToNext();
skip_to_next();
return *this;
}
void skipToNext()
void skip_to_next()
{
#ifdef HASHTABLE_DEBUG
unsigned pass = 0;
#endif
while (!m_isEnd) {
while (!m_is_end) {
#ifdef HASHTABLE_DEBUG
++pass;
kprintf("skipToNext pass %u, m_bucketIndex=%u\n", pass, m_bucketIndex);
kprintf("skip_to_next pass %u, m_bucket_index=%u\n", pass, m_bucket_index);
#endif
if (m_bucketIterator.isEnd()) {
++m_bucketIndex;
if (m_bucketIndex >= m_table.capacity()) {
m_isEnd = true;
if (m_bucket_iterator.is_end()) {
++m_bucket_index;
if (m_bucket_index >= m_table.capacity()) {
m_is_end = true;
return;
}
const DoublyLinkedList<T>& chain = m_table.m_buckets[m_bucketIndex].chain;
m_bucketIterator = chain.begin();
const DoublyLinkedList<T>& chain = m_table.m_buckets[m_bucket_index].chain;
m_bucket_iterator = chain.begin();
} else {
++m_bucketIterator;
++m_bucket_iterator;
}
if (!m_bucketIterator.isEnd())
if (!m_bucket_iterator.is_end())
return;
}
}
private:
friend class HashTable;
ConstIterator(const HashTable& table, bool isEnd, typename DoublyLinkedList<T>::ConstIterator bucketIterator = DoublyLinkedList<T>::ConstIterator::universalEnd(), unsigned bucketIndex = 0)
ConstIterator(const HashTable& table, bool is_end, typename DoublyLinkedList<T>::ConstIterator bucket_iterator = DoublyLinkedList<T>::ConstIterator::universal_end(), unsigned bucket_index = 0)
: m_table(table)
, m_bucketIndex(bucketIndex)
, m_isEnd(isEnd)
, m_bucketIterator(bucketIterator)
, m_bucket_index(bucket_index)
, m_is_end(is_end)
, m_bucket_iterator(bucket_iterator)
{
if (!isEnd && !m_table.is_empty() && !(m_bucketIterator != DoublyLinkedList<T>::ConstIterator::universalEnd())) {
if (!is_end && !m_table.is_empty() && !(m_bucket_iterator != DoublyLinkedList<T>::ConstIterator::universal_end())) {
#ifdef HASHTABLE_DEBUG
kprintf("const bucket iterator init!\n");
#endif
const DoublyLinkedList<T>& chain = m_table.m_buckets[0].chain;
m_bucketIterator = chain.begin();
if (m_bucketIterator.isEnd())
skipToNext();
m_bucket_iterator = chain.begin();
if (m_bucket_iterator.is_end())
skip_to_next();
}
}
const HashTable& m_table;
unsigned m_bucketIndex { 0 };
bool m_isEnd { false };
typename DoublyLinkedList<T>::ConstIterator m_bucketIterator;
unsigned m_bucket_index { 0 };
bool m_is_end { false };
typename DoublyLinkedList<T>::ConstIterator m_bucket_iterator;
};
ConstIterator begin() const { return ConstIterator(*this, is_empty()); }
@ -222,8 +222,8 @@ public:
void remove(Iterator);
private:
Bucket& lookup(const T&, unsigned* bucketIndex = nullptr);
const Bucket& lookup(const T&, unsigned* bucketIndex = nullptr) const;
Bucket& lookup(const T&, unsigned* bucket_index = nullptr);
const Bucket& lookup(const T&, unsigned* bucket_index = nullptr) const;
void rehash(unsigned capacity);
void insert(const T&);
void insert(T&&);
@ -274,28 +274,28 @@ void HashTable<T, TraitsForT>::set(const T& value)
template<typename T, typename TraitsForT>
void HashTable<T, TraitsForT>::rehash(unsigned newCapacity)
void HashTable<T, TraitsForT>::rehash(unsigned new_capacity)
{
newCapacity *= 2;
new_capacity *= 2;
#ifdef HASHTABLE_DEBUG
kprintf("rehash to %u buckets\n", newCapacity);
kprintf("rehash to %u buckets\n", new_capacity);
#endif
auto* newBuckets = new Bucket[newCapacity];
auto* oldBuckets = m_buckets;
unsigned oldCapacity = m_capacity;
m_buckets = newBuckets;
m_capacity = newCapacity;
auto* new_buckets = new Bucket[new_capacity];
auto* old_buckets = m_buckets;
unsigned old_capacity = m_capacity;
m_buckets = new_buckets;
m_capacity = new_capacity;
#ifdef HASHTABLE_DEBUG
kprintf("reinsert %u buckets\n", oldCapacity);
kprintf("reinsert %u buckets\n", old_capacity);
#endif
for (unsigned i = 0; i < oldCapacity; ++i) {
for (auto& value : oldBuckets[i].chain) {
for (unsigned i = 0; i < old_capacity; ++i) {
for (auto& value : old_buckets[i].chain) {
insert(move(value));
}
}
delete [] oldBuckets;
delete [] old_buckets;
}
template<typename T, typename TraitsForT>
@ -338,11 +338,11 @@ auto HashTable<T, TraitsForT>::find(const T& value) -> Iterator
{
if (is_empty())
return end();
unsigned bucketIndex;
auto& bucket = lookup(value, &bucketIndex);
auto bucketIterator = bucket.chain.find(value);
if (bucketIterator != bucket.chain.end())
return Iterator(*this, false, bucketIterator, bucketIndex);
unsigned bucket_index;
auto& bucket = lookup(value, &bucket_index);
auto bucket_iterator = bucket.chain.find(value);
if (bucket_iterator != bucket.chain.end())
return Iterator(*this, false, bucket_iterator, bucket_index);
return end();
}
@ -351,11 +351,11 @@ auto HashTable<T, TraitsForT>::find(const T& value) const -> ConstIterator
{
if (is_empty())
return end();
unsigned bucketIndex;
auto& bucket = lookup(value, &bucketIndex);
auto bucketIterator = bucket.chain.find(value);
if (bucketIterator != bucket.chain.end())
return ConstIterator(*this, false, bucketIterator, bucketIndex);
unsigned bucket_index;
auto& bucket = lookup(value, &bucket_index);
auto bucket_iterator = bucket.chain.find(value);
if (bucket_iterator != bucket.chain.end())
return ConstIterator(*this, false, bucket_iterator, bucket_index);
return end();
}
@ -363,12 +363,12 @@ template<typename T, typename TraitsForT>
void HashTable<T, TraitsForT>::remove(Iterator it)
{
ASSERT(!is_empty());
m_buckets[it.m_bucketIndex].chain.remove(it.m_bucketIterator);
m_buckets[it.m_bucket_index].chain.remove(it.m_bucket_iterator);
--m_size;
}
template<typename T, typename TraitsForT>
typename HashTable<T, TraitsForT>::Bucket& HashTable<T, TraitsForT>::lookup(const T& value, unsigned* bucketIndex)
typename HashTable<T, TraitsForT>::Bucket& HashTable<T, TraitsForT>::lookup(const T& value, unsigned* bucket_index)
{
unsigned hash = TraitsForT::hash(value);
#ifdef HASHTABLE_DEBUG
@ -376,13 +376,13 @@ typename HashTable<T, TraitsForT>::Bucket& HashTable<T, TraitsForT>::lookup(cons
TraitsForT::dump(value);
kprintf(" is %u\n", hash);
#endif
if (bucketIndex)
*bucketIndex = hash % m_capacity;
if (bucket_index)
*bucket_index = hash % m_capacity;
return m_buckets[hash % m_capacity];
}
template<typename T, typename TraitsForT>
const typename HashTable<T, TraitsForT>::Bucket& HashTable<T, TraitsForT>::lookup(const T& value, unsigned* bucketIndex) const
const typename HashTable<T, TraitsForT>::Bucket& HashTable<T, TraitsForT>::lookup(const T& value, unsigned* bucket_index) const
{
unsigned hash = TraitsForT::hash(value);
#ifdef HASHTABLE_DEBUG
@ -390,8 +390,8 @@ const typename HashTable<T, TraitsForT>::Bucket& HashTable<T, TraitsForT>::looku
TraitsForT::dump(value);
kprintf(" is %u\n", hash);
#endif
if (bucketIndex)
*bucketIndex = hash % m_capacity;
if (bucket_index)
*bucket_index = hash % m_capacity;
return m_buckets[hash % m_capacity];
}

View file

@ -61,8 +61,8 @@ public:
bool operator!=(const Iterator& other) { return m_node != other.m_node; }
Iterator& operator++() { m_node = m_node->next; return *this; }
T& operator*() { return m_node->value; }
bool isEnd() const { return !m_node; }
static Iterator universalEnd() { return Iterator(nullptr); }
bool is_end() const { return !m_node; }
static Iterator universal_end() { return Iterator(nullptr); }
private:
friend class SinglyLinkedList;
explicit Iterator(SinglyLinkedList::Node* node) : m_node(node) { }
@ -70,15 +70,15 @@ public:
};
Iterator begin() { return Iterator(m_head); }
Iterator end() { return Iterator::universalEnd(); }
Iterator end() { return Iterator::universal_end(); }
class ConstIterator {
public:
bool operator!=(const ConstIterator& other) { return m_node != other.m_node; }
ConstIterator& operator++() { m_node = m_node->next; return *this; }
const T& operator*() const { return m_node->value; }
bool isEnd() const { return !m_node; }
static ConstIterator universalEnd() { return ConstIterator(nullptr); }
bool is_end() const { return !m_node; }
static ConstIterator universal_end() { return ConstIterator(nullptr); }
private:
friend class SinglyLinkedList;
explicit ConstIterator(const SinglyLinkedList::Node* node) : m_node(node) { }
@ -86,7 +86,7 @@ public:
};
ConstIterator begin() const { return ConstIterator(m_head); }
ConstIterator end() const { return ConstIterator::universalEnd(); }
ConstIterator end() const { return ConstIterator::universal_end(); }
ConstIterator find(const T& value) const
{

View file

@ -77,7 +77,7 @@ public:
Vector(const Vector& other)
{
ensureCapacity(other.size());
ensure_capacity(other.size());
for (size_t i = 0; i < other.size(); ++i)
unchecked_append(other[i]);
}
@ -137,7 +137,7 @@ public:
const T& last() const { return at(size() - 1); }
T& last() { return at(size() - 1); }
T takeLast()
T take_last()
{
ASSERT(!is_empty());
T value = move(last());
@ -163,7 +163,7 @@ public:
{
if (this != &other) {
clear();
ensureCapacity(other.size());
ensure_capacity(other.size());
for (const auto& v : other)
unchecked_append(v);
}
@ -173,7 +173,7 @@ public:
void append(Vector<T>&& other)
{
Vector<T> tmp = move(other);
ensureCapacity(size() + tmp.size());
ensure_capacity(size() + tmp.size());
for (auto&& v : tmp) {
unchecked_append(move(v));
}
@ -194,32 +194,32 @@ public:
void append(T&& value)
{
ensureCapacity(size() + 1);
ensure_capacity(size() + 1);
new (m_impl->slot(m_impl->m_size)) T(move(value));
++m_impl->m_size;
}
void append(const T& value)
{
ensureCapacity(size() + 1);
ensure_capacity(size() + 1);
new (m_impl->slot(m_impl->m_size)) T(value);
++m_impl->m_size;
}
void append(const T* values, size_t count)
{
ensureCapacity(size() + count);
ensure_capacity(size() + count);
for (size_t i = 0; i < count; ++i)
new (m_impl->slot(m_impl->m_size + i)) T(values[i]);
m_impl->m_size += count;
}
void ensureCapacity(size_t neededCapacity)
void ensure_capacity(size_t neededCapacity)
{
if (capacity() >= neededCapacity)
return;
size_t newCapacity = paddedCapacity(neededCapacity);
auto newImpl = VectorImpl<T, Allocator>::create(newCapacity);
size_t new_capacity = padded_capacity(neededCapacity);
auto newImpl = VectorImpl<T, Allocator>::create(new_capacity);
if (m_impl) {
newImpl->m_size = m_impl->m_size;
for (size_t i = 0; i < size(); ++i) {
@ -236,7 +236,7 @@ public:
ASSERT(new_size >= size());
if (!new_size)
return;
ensureCapacity(new_size);
ensure_capacity(new_size);
for (size_t i = size(); i < new_size; ++i)
new (m_impl->slot(i)) T;
m_impl->m_size = new_size;
@ -273,7 +273,7 @@ public:
ConstIterator end() const { return ConstIterator(*this, size()); }
//private:
static size_t paddedCapacity(size_t capacity)
static size_t padded_capacity(size_t capacity)
{
return max(size_t(4), capacity + (capacity / 4) + 4);
}

View file

@ -126,7 +126,7 @@ int main(int c, char** v)
strings.append("f");
strings.append("g");
auto g = strings.takeLast();
auto g = strings.take_last();
for (unsigned i = 0; i < strings.size(); ++i) {
printf("[%u]: '%s'\n", i, strings[i].characters());