git-svn-id: svn://db.shs.com.ru/pip@840 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
57
main.cpp
57
main.cpp
@@ -28,20 +28,20 @@ PISystemMonitor sys_mon;
|
||||
class TestRec: public PIObject {
|
||||
PIOBJECT(TestRec)
|
||||
public:
|
||||
EVENT_HANDLER(void, reinitSpec) {piCout << "reinitSpec";int a = 10; (void*)&a;}
|
||||
EVENT_HANDLER(void, reinitSpec) {/*piCout << "reinitSpec";*/int a = 10; (void*)&a;}
|
||||
|
||||
EVENT_HANDLER(void, coeffsChanged) {piCout << "coeffsChanged";}
|
||||
EVENT_HANDLER(void, guiAboutSend) {piCout << "guiAboutSend";}
|
||||
EVENT_HANDLER(void, guiAfterSend) {piCout << "guiAfterSend";}
|
||||
EVENT_HANDLER(void, guiReceived) {piCout << "guiReceived";}
|
||||
|
||||
EVENT_HANDLER(void, playerReceived) {piCout << "playerReceived";int a = 10; (void*)&a;}
|
||||
EVENT_HANDLER(void, playerReceived) {/*piCout << "playerReceived";*/int a = 10; (void*)&a;}
|
||||
|
||||
EVENT_HANDLER(void, playerValuesReceived) {piCout << "playerValuesReceived";}
|
||||
EVENT_HANDLER(void, calculate) {piCout << "calculate";}
|
||||
EVENT_HANDLER(void, autostart) {piCout << "autostart";}
|
||||
|
||||
EVENT_HANDLER(void, syncOff) {piCout << "syncOff";int a = 10; (void*)&a;}
|
||||
EVENT_HANDLER(void, syncOff) {/*piCout << "syncOff";*/int a = 10; (void*)&a;}
|
||||
|
||||
EVENT_HANDLER(void, del) {piCout << "DEL";}
|
||||
};
|
||||
@@ -77,7 +77,12 @@ class CC: public CB {
|
||||
};
|
||||
|
||||
#define CONN(sn) CONNECTU(snd, sn, rec, sn)
|
||||
|
||||
uint HashLy(const void* d, int l) {
|
||||
uint hash = 0u;
|
||||
for(int i = 0; i < l; ++i)
|
||||
hash = (hash * 1664525u) + ((uchar*)d)[i] + 1013904223u;
|
||||
return hash;
|
||||
}
|
||||
int main(int argc, char * argv[]) {
|
||||
//sys_mon.startOnSelf();
|
||||
|
||||
@@ -106,7 +111,7 @@ int main(int argc, char * argv[]) {
|
||||
CONN(syncOff);
|
||||
|
||||
// 0.6 us on call
|
||||
/*for (int j = 0; j < 10; ++j) {
|
||||
for (int j = 0; j < 10; ++j) {
|
||||
tm.reset();
|
||||
for (int i = 0; i < 10000; ++i) {
|
||||
snd->reinitSpec();
|
||||
@@ -115,11 +120,45 @@ int main(int argc, char * argv[]) {
|
||||
}
|
||||
double el = tm.elapsed_m();
|
||||
piCout << el;
|
||||
}*/
|
||||
piCout << "****";
|
||||
PIPeer().dump();
|
||||
piCout << "----";
|
||||
}
|
||||
|
||||
/*piCout << "****";
|
||||
PIPeer().dump();
|
||||
piCout << "----";*/
|
||||
|
||||
/* PIString _s = "012345678901234567890123456789";
|
||||
CRC_32 crc = standardCRC_32();
|
||||
PIByteArray _sd = _s.toByteArray();
|
||||
double el;
|
||||
uint ret;
|
||||
|
||||
tm.reset();
|
||||
for (int i = 0; i < 1000000; ++i) {
|
||||
ret = crc.calculate(_sd.data(), _sd.size_s());
|
||||
}
|
||||
el = tm.elapsed_m();
|
||||
piCout << "";
|
||||
piCout << ret;
|
||||
piCout << "crc" << el;
|
||||
|
||||
tm.reset();
|
||||
for (int i = 0; i < 1000000; ++i) {
|
||||
ret = HashLy(_sd.data(), _sd.size_s());
|
||||
}
|
||||
el = tm.elapsed_m();
|
||||
piCout << "";
|
||||
piCout << ret;
|
||||
piCout << " ly" << el;
|
||||
|
||||
tm.reset();
|
||||
for (int i = 0; i < 1000000; ++i) {
|
||||
ret = murmur3_32((const uchar*)_sd.data(), _sd.size_s());
|
||||
}
|
||||
el = tm.elapsed_m();
|
||||
piCout << "";
|
||||
piCout << ret;
|
||||
piCout << "mur" << el;
|
||||
*/
|
||||
delete snd;
|
||||
delete rec;
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "piplatform.h"
|
||||
#include "pip_export.h"
|
||||
#include "pip_defs.h"
|
||||
#include "string.h"
|
||||
|
||||
//! Version of PIP in hex - 0x##(Major)##(Minor)##(Revision)
|
||||
#define PIP_VERSION ((PIP_VERSION_MAJOR << 16) | (PIP_VERSION_MINOR < 8) | PIP_VERSION_REVISION)
|
||||
@@ -459,6 +460,46 @@ uint letobe_i(uint v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF
|
||||
|
||||
#endif
|
||||
|
||||
/// \brief Generic hash function, impements murmur3/32 algorithm
|
||||
inline uint piHash(const uchar * data, uint len, uint seed = 0) {
|
||||
if (!data || len <= 0) return 0u;
|
||||
uint h = seed;
|
||||
if (len > 3) {
|
||||
uint i = len >> 2;
|
||||
do {
|
||||
uint k;
|
||||
memcpy(&k, data, sizeof(uint));
|
||||
data += sizeof(uint);
|
||||
k *= 0xcc9e2d51;
|
||||
k = (k << 15) | (k >> 17);
|
||||
k *= 0x1b873593;
|
||||
h ^= k;
|
||||
h = (h << 13) | (h >> 19);
|
||||
h = h * 5 + 0xe6546b64;
|
||||
} while (--i);
|
||||
}
|
||||
if (len & 3) {
|
||||
uint i = len & 3;
|
||||
uint k = 0;
|
||||
do {
|
||||
k <<= 8;
|
||||
k |= data[i - 1];
|
||||
} while (--i);
|
||||
k *= 0xcc9e2d51;
|
||||
k = (k << 15) | (k >> 17);
|
||||
k *= 0x1b873593;
|
||||
h ^= k;
|
||||
}
|
||||
h ^= len;
|
||||
h ^= h >> 16;
|
||||
h *= 0x85ebca6b;
|
||||
h ^= h >> 13;
|
||||
h *= 0xc2b2ae35;
|
||||
h ^= h >> 16;
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
#define piRoundf piRound<float>
|
||||
#define piRoundd piRound<double>
|
||||
#define piFloorf piFloor<float>
|
||||
|
||||
@@ -277,6 +277,11 @@ uint PIByteArray::checksumPlain32() const {
|
||||
}
|
||||
|
||||
|
||||
uint PIByteArray::hash() const {
|
||||
return piHash(data(), size_s());
|
||||
}
|
||||
|
||||
|
||||
PIString PIByteArray::toString(int base) const {
|
||||
PIString ret;
|
||||
int sz = size_s();
|
||||
|
||||
@@ -119,6 +119,9 @@ public:
|
||||
//! Returns plain 32-bit checksum
|
||||
uint checksumPlain32() const;
|
||||
|
||||
//! Returns hash
|
||||
uint hash() const;
|
||||
|
||||
void operator =(const PIDeque<uchar> & d) {resize(d.size()); memcpy(data(), d.data(), d.size());}
|
||||
|
||||
static PIByteArray fromUserInput(PIString str);
|
||||
|
||||
@@ -430,12 +430,6 @@ CRC_32 & PIObject::__meta_crc() {
|
||||
}
|
||||
|
||||
|
||||
uint PIObject::__string_id(const PIString & s) {
|
||||
if (s.isEmpty()) return 0;
|
||||
return __meta_crc().calculate(s.toByteArray());
|
||||
}
|
||||
|
||||
|
||||
void PIObject::callQueuedEvents() {
|
||||
mutex_queue.lock();
|
||||
PIVector<__QueuedEvent> qe = events_queue;
|
||||
@@ -629,6 +623,6 @@ bool dumpApplicationToFile(const PIString & path) {
|
||||
void PIObject::__MetaData::addScope(const PIString & s) {
|
||||
if (!scope_list.contains(s)) {
|
||||
scope_list << s;
|
||||
scope_id << __string_id(s);
|
||||
scope_id << s.hash();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,9 +199,9 @@
|
||||
typedef name __PIObject__; \
|
||||
public: \
|
||||
static const PIString __classNameS() {return PIStringAscii(#name);} \
|
||||
static const uint __classNameIDS() {static uint ret = __string_id(PIStringAscii(#name)); return ret;} \
|
||||
static const uint __classNameIDS() {static uint ret = PIStringAscii(#name).hash(); return ret;} \
|
||||
virtual const char * className() const {return #name;} \
|
||||
virtual const uint classNameID() const {static uint ret = __string_id(PIStringAscii(#name)); return ret;} \
|
||||
virtual const uint classNameID() const {static uint ret = PIStringAscii(#name).hash(); return ret;} \
|
||||
private: \
|
||||
virtual int ptrOffset() const {name * o = (name*)100; return int(llong((PIObject*)o) - llong(o));} \
|
||||
class __BaseInitializer__ { \
|
||||
@@ -437,11 +437,11 @@
|
||||
#define EVENT_VHANDLER EVENT_VHANDLER0
|
||||
|
||||
|
||||
#define EVENT0(name) EVENT_HANDLER0(void, name) {static uint eid = __string_id(PIStringAscii(#name)); PIObject::raiseEvent(this, eid);}
|
||||
#define EVENT1(name, a0, n0) EVENT_HANDLER1(void, name, a0, n0) {static uint eid = __string_id(PIStringAscii(#name)); PIObject::raiseEvent(this, eid, n0);}
|
||||
#define EVENT2(name, a0, n0, a1, n1) EVENT_HANDLER2(void, name, a0, n0, a1, n1) {static uint eid = __string_id(PIStringAscii(#name)); PIObject::raiseEvent(this, eid, n0, n1);}
|
||||
#define EVENT3(name, a0, n0, a1, n1, a2, n2) EVENT_HANDLER3(void, name, a0, n0, a1, n1, a2, n2) {static uint eid = __string_id(PIStringAscii(#name)); PIObject::raiseEvent(this, eid, n0, n1, n2);}
|
||||
#define EVENT4(name, a0, n0, a1, n1, a2, n2, a3, n3) EVENT_HANDLER4(void, name, a0, n0, a1, n1, a2, n2, a3, n3) {static uint eid = __string_id(PIStringAscii(#name)); PIObject::raiseEvent(this, eid, n0, n1, n2, n3);}
|
||||
#define EVENT0(name) EVENT_HANDLER0(void, name) {static uint eid = PIStringAscii(#name).hash(); PIObject::raiseEvent(this, eid);}
|
||||
#define EVENT1(name, a0, n0) EVENT_HANDLER1(void, name, a0, n0) {static uint eid = PIStringAscii(#name).hash(); PIObject::raiseEvent(this, eid, n0);}
|
||||
#define EVENT2(name, a0, n0, a1, n1) EVENT_HANDLER2(void, name, a0, n0, a1, n1) {static uint eid = PIStringAscii(#name).hash(); PIObject::raiseEvent(this, eid, n0, n1);}
|
||||
#define EVENT3(name, a0, n0, a1, n1, a2, n2) EVENT_HANDLER3(void, name, a0, n0, a1, n1, a2, n2) {static uint eid = PIStringAscii(#name).hash(); PIObject::raiseEvent(this, eid, n0, n1, n2);}
|
||||
#define EVENT4(name, a0, n0, a1, n1, a2, n2, a3, n3) EVENT_HANDLER4(void, name, a0, n0, a1, n1, a2, n2, a3, n3) {static uint eid = PIStringAscii(#name).hash(); PIObject::raiseEvent(this, eid, n0, n1, n2, n3);}
|
||||
#define EVENT EVENT0
|
||||
|
||||
#define RAISE_EVENT0(src, event) (src)->event();
|
||||
@@ -510,10 +510,10 @@ public:
|
||||
//! Returns object class name
|
||||
virtual const char * className() const {return "PIObject";}
|
||||
|
||||
virtual const uint classNameID() const {static uint ret = __string_id(PIStringAscii("PIObject")); return ret;}
|
||||
virtual const uint classNameID() const {static uint ret = PIStringAscii("PIObject").hash(); return ret;}
|
||||
|
||||
static const PIString __classNameS() {return PIStringAscii("PIObject");}
|
||||
static const uint __classNameIDS() {static uint ret = __string_id(PIStringAscii("PIObject")); return ret;}
|
||||
static const uint __classNameIDS() {static uint ret = PIStringAscii("PIObject").hash(); return ret;}
|
||||
|
||||
//! Returns parent object class name
|
||||
virtual const char * parentClassName() const {return "";}
|
||||
@@ -775,10 +775,9 @@ public:
|
||||
typedef PIPair<const void * , __MetaFunc> __EHPair;
|
||||
|
||||
static PIMutex & __meta_mutex();
|
||||
static PIMap<uint, __MetaData> & __meta_data(); // [__string_id(classname)]=__MetaData
|
||||
static PIMap<uint, __MetaData> & __meta_data(); // [hash(classname)]=__MetaData
|
||||
|
||||
static CRC_32 & __meta_crc();
|
||||
static uint __string_id(const PIString & s);
|
||||
|
||||
//! \brief Execute all posted events from CONNECTU_QUEUED connections
|
||||
void callQueuedEvents();
|
||||
@@ -814,7 +813,7 @@ private:
|
||||
slot = sl;
|
||||
signal = si;
|
||||
event = e;
|
||||
eventID = __string_id(e);
|
||||
eventID = e.hash();
|
||||
dest_o = d_o;
|
||||
dest = d;
|
||||
args_count = ac;
|
||||
|
||||
@@ -418,6 +418,12 @@ const char * PIString::dataAscii() const {
|
||||
}
|
||||
|
||||
|
||||
uint PIString::hash() const {
|
||||
buildData();
|
||||
return piHash(data_.data(), data_.size_s() - 1);
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIString::toUTF8() const {
|
||||
if (isEmpty()) return data_.resized(0);
|
||||
buildData(
|
||||
|
||||
@@ -470,6 +470,8 @@ public:
|
||||
* execution of this function.\n */
|
||||
const char * dataAscii() const;
|
||||
|
||||
//! Returns hash
|
||||
uint hash() const;
|
||||
|
||||
//! \brief Return \a PIByteArray contains \a data() of this string without terminating null-char
|
||||
PIByteArray toByteArray() const {buildData(); return data_.resized(data_.size_s() - 1);}
|
||||
|
||||
Reference in New Issue
Block a user