Skip to content

Commit

Permalink
Re-apply clang-format to all files
Browse files Browse the repository at this point in the history
Some badly formatted code has managed to pass through our CI...
  • Loading branch information
akien-mga committed Aug 27, 2017
1 parent f3e302c commit 886c7d8
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 133 deletions.
40 changes: 20 additions & 20 deletions core/hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,41 @@
#ifndef HASH_MAP_H
#define HASH_MAP_H

#include "list.h"
#include "hashfuncs.h"
#include "list.h"
#include "math_funcs.h"
#include "os/memory.h"
#include "ustring.h"

struct HashMapHasherDefault {
static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); }
static _FORCE_INLINE_ uint32_t hash(const char *p_cstr) { return hash_djb2(p_cstr); }
static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) { return hash_one_uint64(p_int); }
static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); }
static _FORCE_INLINE_ uint32_t hash(const char *p_cstr) { return hash_djb2(p_cstr); }
static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) { return hash_one_uint64(p_int); }

static _FORCE_INLINE_ uint32_t hash(const int64_t p_int) { return hash(uint64_t(p_int)); }
static _FORCE_INLINE_ uint32_t hash(const float p_float) { return hash_djb2_one_float(p_float); }
static _FORCE_INLINE_ uint32_t hash(const double p_double){ return hash_djb2_one_float(p_double); }
static _FORCE_INLINE_ uint32_t hash(const int64_t p_int) { return hash(uint64_t(p_int)); }
static _FORCE_INLINE_ uint32_t hash(const float p_float) { return hash_djb2_one_float(p_float); }
static _FORCE_INLINE_ uint32_t hash(const double p_double) { return hash_djb2_one_float(p_double); }
static _FORCE_INLINE_ uint32_t hash(const uint32_t p_int) { return p_int; }
static _FORCE_INLINE_ uint32_t hash(const int32_t p_int) { return (uint32_t)p_int; }
static _FORCE_INLINE_ uint32_t hash(const int32_t p_int) { return (uint32_t)p_int; }
static _FORCE_INLINE_ uint32_t hash(const uint16_t p_int) { return p_int; }
static _FORCE_INLINE_ uint32_t hash(const int16_t p_int) { return (uint32_t)p_int; }
static _FORCE_INLINE_ uint32_t hash(const uint8_t p_int) { return p_int; }
static _FORCE_INLINE_ uint32_t hash(const int8_t p_int) { return (uint32_t)p_int; }
static _FORCE_INLINE_ uint32_t hash(const wchar_t p_wchar){ return (uint32_t)p_wchar; }
static _FORCE_INLINE_ uint32_t hash(const int16_t p_int) { return (uint32_t)p_int; }
static _FORCE_INLINE_ uint32_t hash(const uint8_t p_int) { return p_int; }
static _FORCE_INLINE_ uint32_t hash(const int8_t p_int) { return (uint32_t)p_int; }
static _FORCE_INLINE_ uint32_t hash(const wchar_t p_wchar) { return (uint32_t)p_wchar; }
//static _FORCE_INLINE_ uint32_t hash(const void* p_ptr) { return uint32_t(uint64_t(p_ptr))*(0x9e3779b1L); }
};

template <typename T>
struct HashMapComparatorDefault {
static bool compare(const T& p_lhs, const T& p_rhs) {
static bool compare(const T &p_lhs, const T &p_rhs) {
return p_lhs == p_rhs;
}

bool compare(const float& p_lhs, const float& p_rhs) {
bool compare(const float &p_lhs, const float &p_rhs) {
return (p_lhs == p_rhs) || (Math::is_nan(p_lhs) && Math::is_nan(p_rhs));
}

bool compare(const double& p_lhs, const double& p_rhs) {
bool compare(const double &p_lhs, const double &p_rhs) {
return (p_lhs == p_rhs) || (Math::is_nan(p_lhs) && Math::is_nan(p_rhs));
}
};
Expand All @@ -86,7 +86,7 @@ struct HashMapComparatorDefault {
*
*/

template <class TKey, class TData, class Hasher = HashMapHasherDefault, class Comparator=HashMapComparatorDefault<TKey>, uint8_t MIN_HASH_TABLE_POWER=3,uint8_t RELATIONSHIP=8>
template <class TKey, class TData, class Hasher = HashMapHasherDefault, class Comparator = HashMapComparatorDefault<TKey>, uint8_t MIN_HASH_TABLE_POWER = 3, uint8_t RELATIONSHIP = 8>
class HashMap {
public:
struct Pair {
Expand Down Expand Up @@ -208,7 +208,7 @@ class HashMap {
while (e) {

/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && Comparator::compare(e->pair.key,p_key) ) {
if (e->hash == hash && Comparator::compare(e->pair.key, p_key)) {

/* the pair exists in this hashtable, so just update data */
return e;
Expand Down Expand Up @@ -375,7 +375,7 @@ class HashMap {
while (e) {

/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && Comparator::compare(e->pair.key,p_custom_key) ) {
if (e->hash == hash && Comparator::compare(e->pair.key, p_custom_key)) {

/* the pair exists in this hashtable, so just update data */
return &e->pair.data;
Expand All @@ -401,7 +401,7 @@ class HashMap {
while (e) {

/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && Comparator::compare(e->pair.key,p_custom_key) ) {
if (e->hash == hash && Comparator::compare(e->pair.key, p_custom_key)) {

/* the pair exists in this hashtable, so just update data */
return &e->pair.data;
Expand Down Expand Up @@ -430,7 +430,7 @@ class HashMap {
while (e) {

/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && Comparator::compare(e->pair.key,p_key) ) {
if (e->hash == hash && Comparator::compare(e->pair.key, p_key)) {

if (p) {

Expand Down
18 changes: 9 additions & 9 deletions core/hashfuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
#ifndef HASHFUNCS_H
#define HASHFUNCS_H

#include "math_funcs.h"
#include "math_defs.h"
#include "math_funcs.h"
#include "typedefs.h"

/**
Expand Down Expand Up @@ -71,14 +71,14 @@ static inline uint32_t hash_djb2_one_32(uint32_t p_in, uint32_t p_prev = 5381) {
}

static inline uint32_t hash_one_uint64(const uint64_t p_int) {
uint64_t v=p_int;
uint64_t v = p_int;
v = (~v) + (v << 18); // v = (v << 18) - v - 1;
v = v ^ (v >> 31);
v = v * 21; // v = (v + (v << 2)) + (v << 4);
v = v ^ (v >> 11);
v = v + (v << 6);
v = v ^ (v >> 22);
return (int) v;
return (int)v;
}

static inline uint32_t hash_djb2_one_float(double p_in, uint32_t p_prev = 5381) {
Expand All @@ -88,17 +88,17 @@ static inline uint32_t hash_djb2_one_float(double p_in, uint32_t p_prev = 5381)
} u;

// Normalize +/- 0.0 and NaN values so they hash the same.
if (p_in==0.0f)
u.d=0.0;
if (p_in == 0.0f)
u.d = 0.0;
else if (Math::is_nan(p_in))
u.d=NAN;
u.d = NAN;
else
u.d=p_in;
u.d = p_in;

return ((p_prev<<5)+p_prev) + hash_one_uint64(u.i);
return ((p_prev << 5) + p_prev) + hash_one_uint64(u.i);
}

template<class T>
template <class T>
static inline uint32_t make_uint32_t(T p_in) {

union {
Expand Down
18 changes: 9 additions & 9 deletions core/io/stream_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,10 @@ void StreamPeerBuffer::_bind_methods() {
Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) {

if (p_bytes <= 0)
return OK;
return OK;

if (pointer + p_bytes > data.size()) {
data.resize(pointer + p_bytes);
data.resize(pointer + p_bytes);
}

DVector<uint8_t>::Write w = data.write();
Expand All @@ -436,20 +436,20 @@ Error StreamPeerBuffer::get_data(uint8_t *p_buffer, int p_bytes) {
int recv;
get_partial_data(p_buffer, p_bytes, recv);
if (recv != p_bytes)
return ERR_INVALID_PARAMETER;
return ERR_INVALID_PARAMETER;

return OK;
}
Error StreamPeerBuffer::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) {

if (pointer + p_bytes > data.size()) {
r_received = data.size() - pointer;
if (r_received <= 0) {
r_received = 0;
return OK; //you got 0
}
r_received = data.size() - pointer;
if (r_received <= 0) {
r_received = 0;
return OK; //you got 0
}
} else {
r_received = p_bytes;
r_received = p_bytes;
}

DVector<uint8_t>::Read r = data.read();
Expand Down
1 change: 0 additions & 1 deletion core/io/stream_peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ class StreamPeerBuffer : public StreamPeer {
Error put_data(const uint8_t *p_data, int p_bytes);
Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent);


Error get_data(uint8_t *p_buffer, int p_bytes);
Error get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received);

Expand Down
Loading

0 comments on commit 886c7d8

Please sign in to comment.