-registering same system multiple times only replace pointer for callback

-added export attributes (required by windows to make DLL library, not work at now due to DMD bugs)
-interface D files to import
This commit is contained in:
Mergul 2018-09-18 13:28:04 +02:00
parent cb0f56b0fb
commit d0fcdba6cd
20 changed files with 1322 additions and 105 deletions

View file

@ -11,7 +11,7 @@ private enum HASH_EMPTY = 0;
private enum HASH_DELETED = 0x1;
private enum HASH_FILLED_MARK = ulong(1) << 8 * ulong.sizeof - 1;
ulong defaultHashFunc(T)(auto ref T t) {
export ulong defaultHashFunc(T)(auto ref T t) {
static if (isIntegral!(T)) {
return hashInt(t);
} else {
@ -20,7 +20,7 @@ ulong defaultHashFunc(T)(auto ref T t) {
}
// Can turn bad hash function to good one
ulong hashInt(ulong x) nothrow @nogc @safe {
export ulong hashInt(ulong x) nothrow @nogc @safe {
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
x = x ^ (x >> 31);
@ -48,27 +48,27 @@ struct HashMap(KeyPar, ValuePar, alias hashFunc = defaultHashFunc) {
size_t length; // Used to compute loadFactor
size_t markerdDeleted;
void clear() {
export void clear() {
elements.clear();
length = 0;
markerdDeleted = 0;
}
void reset() {
export void reset() {
elements.reset();
length = 0;
markerdDeleted = 0;
}
bool isIn(ref Key el) {
export bool isIn(ref Key el) {
return getIndex(el) != getIndexEmptyValue;
}
bool isIn(Key el) {
export bool isIn(Key el) {
return getIndex(el) != getIndexEmptyValue;
}
Value* getPtr()(auto ref Key k) {
export Value* getPtr()(auto ref Key k) {
size_t index = getIndex(k);
if (index == getIndexEmptyValue) {
return null;
@ -77,18 +77,18 @@ struct HashMap(KeyPar, ValuePar, alias hashFunc = defaultHashFunc) {
}
}
ref Value get()(auto ref Key k) {
export ref Value get()(auto ref Key k) {
size_t index = getIndex(k);
assert(index != getIndexEmptyValue);
return elements[index].keyValue.value;
}
deprecated("Use get with second parameter.") auto ref Value getDefault()(
deprecated("Use get with second parameter.") export auto ref Value getDefault()(
auto ref Key k, auto ref Value defaultValue) {
return get(k, defaultValue);
}
auto ref Value get()(auto ref Key k, auto ref Value defaultValue) {
export auto ref Value get()(auto ref Key k, auto ref Value defaultValue) {
size_t index = getIndex(k);
if (index == getIndexEmptyValue) {
return defaultValue;
@ -97,7 +97,7 @@ struct HashMap(KeyPar, ValuePar, alias hashFunc = defaultHashFunc) {
}
}
ref Value getInsertDefault()(auto ref Key k, auto ref Value defaultValue) {
export ref Value getInsertDefault()(auto ref Key k, auto ref Value defaultValue) {
size_t index = getIndex(k);
if (index == getIndexEmptyValue) {
add(k, defaultValue);
@ -108,7 +108,7 @@ struct HashMap(KeyPar, ValuePar, alias hashFunc = defaultHashFunc) {
}
bool tryRemove(Key el) {
export bool tryRemove(Key el) {
size_t index = getIndex(el);
if (index == getIndexEmptyValue) {
return false;
@ -119,20 +119,20 @@ struct HashMap(KeyPar, ValuePar, alias hashFunc = defaultHashFunc) {
return true;
}
void remove(Key el) {
export void remove(Key el) {
bool ok = tryRemove(el);
assert(ok);
}
ref Value opIndex()(auto ref Key key) {
export ref Value opIndex()(auto ref Key key) {
return get(key);
}
void opIndexAssign()(auto ref Value value, auto ref Key key) {
export void opIndexAssign()(auto ref Value value, auto ref Key key) {
add(key, value);
}
void add()(auto ref Key key, auto ref Value value) {
export void add()(auto ref Key key, auto ref Value value) {
size_t index = getIndex(key);
if (index != getIndexEmptyValue) {
elements[index].keyValue.value = value;
@ -170,11 +170,11 @@ struct HashMap(KeyPar, ValuePar, alias hashFunc = defaultHashFunc) {
//int numA;
//int numB;
size_t getIndex(Key el) {
export size_t getIndex(Key el) {
return getIndex(el);
}
size_t getIndex(ref Key el) {
export size_t getIndex(ref Key el) {
mixin(doNotInline);
immutable size_t groupsLength = elements.length;
@ -203,14 +203,14 @@ struct HashMap(KeyPar, ValuePar, alias hashFunc = defaultHashFunc) {
}
float getLoadFactor(size_t forElementsNum) {
export float getLoadFactor(size_t forElementsNum) {
if (elements.length == 0) {
return 1;
}
return cast(float) forElementsNum / (elements.length);
}
void rehash() {
export void rehash() {
mixin(doNotInline);
// Get all elements
Vector!KeyVal allElements;
@ -239,7 +239,7 @@ struct HashMap(KeyPar, ValuePar, alias hashFunc = defaultHashFunc) {
}
// foreach support
int opApply(DG)(scope DG dg) {
export int opApply(DG)(scope DG dg) {
int result;
foreach (ref Bucket gr; elements) {
if ((gr.hash & HASH_FILLED_MARK) == 0) {
@ -262,7 +262,7 @@ struct HashMap(KeyPar, ValuePar, alias hashFunc = defaultHashFunc) {
return result;
}
int byKey(scope int delegate(Key k) dg) {
export int byKey(scope int delegate(Key k) dg) {
int result;
foreach (ref Key k; this) {
result = dg(k);
@ -272,7 +272,7 @@ struct HashMap(KeyPar, ValuePar, alias hashFunc = defaultHashFunc) {
return result;
}
int byValue(scope int delegate(ref Value k) dg) {
export int byValue(scope int delegate(ref Value k) dg) {
int result;
foreach (ref Value v; this) {
result = dg(v);
@ -282,7 +282,7 @@ struct HashMap(KeyPar, ValuePar, alias hashFunc = defaultHashFunc) {
return result;
}
int byKeyValue(scope int delegate(ref Key k, ref Value v) dg) {
export int byKeyValue(scope int delegate(ref Key k, ref Value v) dg) {
int result;
foreach (ref Key k, ref Value v; this) {
result = dg(k, v);
@ -297,7 +297,7 @@ struct HashMap(KeyPar, ValuePar, alias hashFunc = defaultHashFunc) {
/**
* Preety print
*/
void toString(scope void delegate(const(char)[]) sink, FormatSpec!char fmt) {
export void toString(scope void delegate(const(char)[]) sink, FormatSpec!char fmt) {
formatValue(sink, '[', fmt);
foreach (ref k, ref v; &byKeyValue) {
formatValue(sink, k, fmt);