1
XDRX-API / Re: [XDrX-PlugIn(165)] Use a hash table to quickly delete completely overlapping ent
« Last post by xdcad on Today at 02:56:16 AM »Yes, since arx interprets the list, it’s not reliable to hash.
Example '(220 220 220 220)
'(220 220 220 220)
ARX's resbuf will be parsed into 3D points, but restype=220, not RT3DPOINT,
So when you calculate the hash value, don’t you include the restype to make it unique?
Code - C++: [Select]
- size_t XdDbUtils::CalculateHash(const AcGePoint3d& point) {
- size_t hash = 0;
- hash ^= std::hash<double>{}(point.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
- hash ^= std::hash<double>{}(point.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
- hash ^= std::hash<double>{}(point.z) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
- return hash;
- }
Code - C++: [Select]
- int XDGetHash()
- {
- resbuf* rb = ads_getargs();
- size_t hash = 0;
- while(rb)
- {
- int restype = XdRbUtils::dxfCodeToDataType(rb->restype);
- hash ^= XdDbUtils::CalculateHash(rb->restype);
- switch (rb->restype)
- {
- case RTENAME:
- {
- AcDbObjectId id;
- if (acdbGetObjectId(id, rb->resval.rlname) == eOk)
- {
- AcDbEntity* pEnt;
- if (acdbOpenObject(pEnt, id, kForRead) == eOk)
- {
- int param = 511;
- if (rb->rbnext && rb->rbnext->restype == RTSHORT)
- {
- param = rb->rbnext->resval.rint;
- }
- hash ^= XdDbUtils::CalculateHash(pEnt, param);
- pEnt->close();
- }
- }
- }
- break;
- case RT3DPOINT:
- {
- hash ^= XdDbUtils::CalculateHash(asPnt3d(rb->resval.rpoint));
- }
- break;
- case RTSTR:
- {
- hash ^= XdDbUtils::CalculateHash(rb->resval.rstring);
- }
- break;
- case RTREAL:
- {
- hash ^= XdDbUtils::CalculateHash(rb->resval.rreal);
- }
- break;
- case RTSHORT:
- {
- hash ^= XdDbUtils::CalculateHash(rb->resval.rint);
- }
- break;
- case RTLONG:
- {
- hash ^= XdDbUtils::CalculateHash(rb->resval.rlong);
- }
- break;
- default:
- break;
- }
- rb = rb->rbnext;
- }
- // 将哈希值转换为字符串
- std::string hashString = std::to_string(hash);
- ads_retstr(CMyString::StringToTCHAR(hashString));
- return RSRSLT;
- }