Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update madoka cpp #10

Merged
merged 4 commits into from Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -25,7 +25,8 @@
ext_modules=[
Extension('_madoka',
sources=['madoka_wrap.cxx'] + MADOKA_FILES,
language="c++"
language="c++",
extra_compile_args=["-std=c++11"]
),
],

Expand Down
8 changes: 4 additions & 4 deletions src/approx.h
Expand Up @@ -55,7 +55,7 @@ class Approx {
static const UInt8 SHIFT_TABLE[APPROX_MAX_EXPONENT + 1];
static const UInt32 MASK_TABLE[APPROX_MAX_EXPONENT + 1];

static UInt64 encode(UInt64 value) throw() {
static UInt64 encode(UInt64 value) noexcept {
value &= APPROX_VALUE_MASK;
const UInt64 exponent =
util::bit_scan_reverse(value | APPROX_SIGNIFICAND_MASK)
Expand All @@ -71,7 +71,7 @@ class Approx {
((value >> get_shift(exponent)) & APPROX_SIGNIFICAND_MASK);
}

static UInt64 decode(UInt64 approx) throw() {
static UInt64 decode(UInt64 approx) noexcept {
const UInt64 exponent =
(approx >> APPROX_EXPONENT_SHIFT) & APPROX_EXPONENT_MASK;

Expand All @@ -91,7 +91,7 @@ class Approx {
#endif // MADOKA_NOT_PREFER_BRANCH
}

static UInt64 decode(UInt64 approx, Random *random) throw() {
static UInt64 decode(UInt64 approx, Random *random) noexcept {
const UInt64 exponent =
(approx >> APPROX_EXPONENT_SHIFT) & APPROX_EXPONENT_MASK;

Expand All @@ -113,7 +113,7 @@ class Approx {
#endif // MADOKA_NOT_PREFER_BRANCH
}

static UInt64 inc(UInt64 approx, Random *random) throw() {
static UInt64 inc(UInt64 approx, Random *random) noexcept {
const UInt64 exponent =
(approx >> APPROX_EXPONENT_SHIFT) & APPROX_EXPONENT_MASK;

Expand Down
72 changes: 36 additions & 36 deletions src/croquis.h
Expand Up @@ -54,63 +54,63 @@ const UInt64 CROQUIS_DEFAULT_DEPTH = CROQUIS_HASH_SIZE;
template <typename T>
class Croquis {
public:
Croquis() throw() : file_(), header_(NULL), table_(NULL) {}
~Croquis() throw() {}
Croquis() noexcept : file_(), header_(NULL), table_(NULL) {}
~Croquis() noexcept {}

void create(UInt64 width = 0, UInt64 depth = 0, const char *path = NULL,
int flags = 0, UInt64 seed = 0) throw(Exception) {
int flags = 0, UInt64 seed = 0) {
Croquis new_croquis;
new_croquis.create_(width, depth, path, flags, seed);
new_croquis.swap(this);
}
void open(const char *path, int flags = 0) throw(Exception) {
void open(const char *path, int flags = 0) {
Croquis new_croquis;
new_croquis.open_(path, flags);
new_croquis.swap(this);
}
void close() throw() {
void close() noexcept {
Croquis().swap(this);
}

void load(const char *path, int flags = 0) throw(Exception) {
void load(const char *path, int flags = 0) {
Croquis new_croquis;
new_croquis.load_(path, flags);
new_croquis.swap(this);
}
void save(const char *path, int flags = 0) const throw(Exception) {
void save(const char *path, int flags = 0) const {
check_header();
file_.save(path, flags);
}

UInt64 width() const throw() {
UInt64 width() const noexcept {
return header().width();
}
UInt64 width_mask() const throw() {
UInt64 width_mask() const noexcept {
return header().width_mask();
}
UInt64 depth() const throw() {
UInt64 depth() const noexcept {
return header().depth();
}
T max_value() const throw() {
T max_value() const noexcept {
return std::numeric_limits<T>::max();
}
UInt64 value_size() const throw() {
UInt64 value_size() const noexcept {
return header().value_size();
}
UInt64 seed() const throw() {
UInt64 seed() const noexcept {
return header().seed();
}
UInt64 table_size() const throw() {
UInt64 table_size() const noexcept {
return header().table_size();
}
UInt64 file_size() const throw() {
UInt64 file_size() const noexcept {
return header().file_size();
}
int flags() const throw() {
int flags() const noexcept {
return file_.flags();
}

T get(const void *key_addr, std::size_t key_size) const throw() {
T get(const void *key_addr, std::size_t key_size) const noexcept {
T min_value = std::numeric_limits<T>::max();

const T *table = table_;
Expand All @@ -133,11 +133,11 @@ class Croquis {
return min_value;
}

T get__(UInt64 table_id, UInt64 cell_id) const throw() {
T get__(UInt64 table_id, UInt64 cell_id) const noexcept {
return table_[(width() * table_id) + cell_id];
}

void set(const void *key_addr, std::size_t key_size, T value) throw() {
void set(const void *key_addr, std::size_t key_size, T value) noexcept {
UInt64 cell_ids[CROQUIS_MAX_DEPTH + CROQUIS_HASH_SIZE - 1];
hash(key_addr, key_size, cell_ids);

Expand All @@ -151,12 +151,12 @@ class Croquis {
}
}

void set__(UInt64 table_id, UInt64 cell_id, T value) const throw() {
void set__(UInt64 table_id, UInt64 cell_id, T value) const noexcept {
T *table = table_;
table[(width() * table_id) + cell_id] = value;
}

T add(const void *key_addr, std::size_t key_size, T value) throw() {
T add(const void *key_addr, std::size_t key_size, T value) noexcept {
UInt64 cell_ids[CROQUIS_MAX_DEPTH + CROQUIS_HASH_SIZE - 1];
hash(key_addr, key_size, cell_ids);

Expand Down Expand Up @@ -184,30 +184,30 @@ class Croquis {
return new_value;
}

void clear() throw() {
void clear() noexcept {
std::memset(table_, 0, table_size());
}

void swap(Croquis *sketch) throw() {
void swap(Croquis *sketch) noexcept {
file_.swap(&sketch->file_);
util::swap(header_, sketch->header_);
util::swap(table_, sketch->table_);
}

void copy(Croquis &src, const char *path = NULL,
int flags = 0) throw(Exception) {
int flags = 0) {
create_(src.width(), src.depth(), path, flags, src.seed());
std::memcpy(table_, src.table_, static_cast<std::size_t>(src.table_size()));
}

void shrink(Croquis &src, UInt64 width = 0,
const char *path = NULL, int flags = 0) throw(Exception) {
const char *path = NULL, int flags = 0) {
Croquis<T> new_sketch;
new_sketch.shrink_(src, width, src.depth(), path, flags);
new_sketch.swap(this);
}

void merge(const Croquis &rhs) throw(Exception){
void merge(const Croquis &rhs){
MADOKA_THROW_IF(width() != rhs.width());
MADOKA_THROW_IF(depth() != rhs.depth());
MADOKA_THROW_IF(seed() != rhs.seed());
Expand All @@ -228,7 +228,7 @@ class Croquis {
}

double inner_product(const Croquis &rhs, double *lhs_square_length = NULL,
double *rhs_square_length = NULL) const throw(Exception){
double *rhs_square_length = NULL) const{
MADOKA_THROW_IF(width() != rhs.width());
MADOKA_THROW_IF(depth() != rhs.depth());
MADOKA_THROW_IF(seed() != rhs.seed());
Expand Down Expand Up @@ -269,15 +269,15 @@ class Croquis {
Header *header_;
T *table_;

const Header &header() const throw() {
const Header &header() const noexcept {
return *header_;
}
Header &header() throw() {
Header &header() noexcept {
return *header_;
}

void create_(UInt64 width, UInt64 depth, const char *path,
int flags, UInt64 seed) throw(Exception) {
int flags, UInt64 seed) {
if (width == 0) {
width = CROQUIS_DEFAULT_WIDTH;
}
Expand Down Expand Up @@ -311,21 +311,21 @@ class Croquis {
clear();
}

void open_(const char *path, int flags) throw(Exception) {
void open_(const char *path, int flags) {
file_.open(path, flags);
header_ = static_cast<Header *>(file_.addr());
table_ = reinterpret_cast<T *>(header_ + 1);
check_header();
}

void load_(const char *path, int flags) throw(Exception) {
void load_(const char *path, int flags) {
file_.load(path, flags);
header_ = static_cast<Header *>(file_.addr());
table_ = reinterpret_cast<T *>(header_ + 1);
check_header();
}

void check_header() const throw(Exception) {
void check_header() const {
MADOKA_THROW_IF(width() < CROQUIS_MIN_WIDTH);
MADOKA_THROW_IF(width() > CROQUIS_MAX_WIDTH);
MADOKA_THROW_IF((width_mask() != 0) && (width_mask() != (width() - 1)));
Expand All @@ -338,15 +338,15 @@ class Croquis {
}

void hash(const void *key_addr, std::size_t key_size,
UInt64 *cell_ids) const throw() {
UInt64 *cell_ids) const noexcept {
for (UInt64 i = 0; i < depth(); i += CROQUIS_HASH_SIZE) {
hash_(key_addr, key_size, seed() + i, cell_ids);
cell_ids += CROQUIS_HASH_SIZE;
}
}

void hash_(const void *key_addr, std::size_t key_size,
UInt64 seed, UInt64 cell_ids[CROQUIS_HASH_SIZE]) const throw() {
UInt64 seed, UInt64 cell_ids[CROQUIS_HASH_SIZE]) const noexcept {
UInt64 hash_values[2];
Hash()(key_addr, key_size, seed, hash_values);

Expand All @@ -367,7 +367,7 @@ class Croquis {
}

void shrink_(const Croquis &src, UInt64 width, UInt64 depth,
const char *path, int flags) throw(Exception) {
const char *path, int flags) {
if (width == 0) {
width = src.width();
}
Expand Down
12 changes: 6 additions & 6 deletions src/exception.h
Expand Up @@ -46,19 +46,19 @@ namespace madoka {

class Exception {
public:
Exception() throw() : what_("") {}
~Exception() throw() {}
Exception() noexcept : what_("") {}
~Exception() noexcept {}

explicit Exception(const char *what) throw() : what_(what) {}
explicit Exception(const char *what) noexcept : what_(what) {}

Exception(const Exception &exception) throw() : what_(exception.what_) {}
Exception(const Exception &exception) noexcept : what_(exception.what_) {}

Exception &operator=(const Exception &exception) throw() {
Exception &operator=(const Exception &exception) noexcept {
what_ = exception.what_;
return *this;
}

const char *what() const throw() {
const char *what() const noexcept {
return what_;
}

Expand Down