mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-02-24 07:02:27 +01:00
byuu says: Changelog: - added Cocoa target: higan can now be compiled for OS X Lion [Cydrak, byuu] - SNES/accuracy profile hires color blending improvements - fixes Marvelous text [AWJ] - fixed a slight bug in SNES/SA-1 VBR support caused by a typo - added support for multi-pass shaders that can load external textures (requires OpenGL 3.2+) - added game library path (used by ananke->Import Game) to Settings->Advanced - system profiles, shaders and cheats database can be stored in "all users" shared folders now (eg /usr/share on Linux) - all configuration files are in BML format now, instead of XML (much easier to read and edit this way) - main window supports drag-and-drop of game folders (but not game files / ZIP archives) - audio buffer clears when entering a modal loop on Windows (prevents audio repetition with DirectSound driver) - a substantial amount of code clean-up (probably the biggest refactoring to date) One highly desired target for this release was to default to the optimal drivers instead of the safest drivers, but because AMD drivers don't seem to like my OpenGL 3.2 driver, I've decided to postpone that. AMD has too big a market share. Hopefully with v093 officially released, we can get some public input on what AMD doesn't like.
138 lines
2.9 KiB
C++
138 lines
2.9 KiB
C++
#ifndef NALL_HASHSET_HPP
|
|
#define NALL_HASHSET_HPP
|
|
|
|
//hashset
|
|
//
|
|
//search: O(1) average; O(n) worst
|
|
//insert: O(1) average; O(n) worst
|
|
//remove: O(1) average; O(n) worst
|
|
//
|
|
//requirements:
|
|
// unsigned T::hash() const;
|
|
// bool T::operator==(const T&) const;
|
|
|
|
namespace nall {
|
|
|
|
template<typename T>
|
|
struct hashset {
|
|
protected:
|
|
T** pool = nullptr;
|
|
unsigned length = 8; //length of pool
|
|
unsigned count = 0; //number of objects inside of the pool
|
|
|
|
public:
|
|
hashset() {}
|
|
hashset(unsigned length) : length(bit::round(length)) {}
|
|
hashset(const hashset& source) { operator=(source); }
|
|
hashset(hashset&& source) { operator=(std::move(source)); }
|
|
~hashset() { reset(); }
|
|
|
|
hashset& operator=(const hashset& source) {
|
|
reset();
|
|
if(source.pool) {
|
|
for(unsigned n = 0; n < source.count; n++) {
|
|
insert(*source.pool[n]);
|
|
}
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
hashset& operator=(hashset&& source) {
|
|
reset();
|
|
pool = source.pool;
|
|
length = source.length;
|
|
count = source.count;
|
|
source.pool = nullptr;
|
|
source.length = 8;
|
|
source.count = 0;
|
|
return *this;
|
|
}
|
|
|
|
unsigned capacity() const { return length; }
|
|
unsigned size() const { return count; }
|
|
bool empty() const { return count == 0; }
|
|
|
|
void reset() {
|
|
if(pool) {
|
|
for(unsigned n = 0; n < length; n++) {
|
|
if(pool[n]) {
|
|
delete pool[n];
|
|
pool[n] = nullptr;
|
|
}
|
|
}
|
|
delete pool;
|
|
pool = nullptr;
|
|
}
|
|
length = 8;
|
|
count = 0;
|
|
}
|
|
|
|
void reserve(unsigned size) {
|
|
//ensure all items will fit into pool (with <= 50% load) and amortize growth
|
|
size = bit::round(max(size, count << 1));
|
|
T** copy = new T*[size]();
|
|
|
|
if(pool) {
|
|
for(unsigned n = 0; n < length; n++) {
|
|
if(pool[n]) {
|
|
unsigned hash = (*pool[n]).hash() & (size - 1);
|
|
while(copy[hash]) if(++hash >= size) hash = 0;
|
|
copy[hash] = pool[n];
|
|
pool[n] = nullptr;
|
|
}
|
|
}
|
|
}
|
|
|
|
delete pool;
|
|
pool = copy;
|
|
length = size;
|
|
}
|
|
|
|
optional<T&> find(const T& value) {
|
|
if(!pool) return false;
|
|
|
|
unsigned hash = value.hash() & (length - 1);
|
|
while(pool[hash]) {
|
|
if(value == *pool[hash]) return {true, *pool[hash]};
|
|
if(++hash >= length) hash = 0;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
optional<T&> insert(const T& value) {
|
|
if(!pool) pool = new T*[length]();
|
|
|
|
//double pool size when load is >= 50%
|
|
if(count >= (length >> 1)) reserve(length << 1);
|
|
count++;
|
|
|
|
unsigned hash = value.hash() & (length - 1);
|
|
while(pool[hash]) if(++hash >= length) hash = 0;
|
|
pool[hash] = new T(value);
|
|
|
|
return {true, *pool[hash]};
|
|
}
|
|
|
|
bool remove(const T& value) {
|
|
if(!pool) return false;
|
|
|
|
unsigned hash = value.hash() & (length - 1);
|
|
while(pool[hash]) {
|
|
if(value == *pool[hash]) {
|
|
delete pool[hash];
|
|
pool[hash] = nullptr;
|
|
count--;
|
|
return true;
|
|
}
|
|
if(++hash >= length) hash = 0;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|