|
1 |
| -using linkRep=unsigned long long; |
| 1 | +// hard code maximum number of nodes |
| 2 | +constexpr unsigned maxNodes=22, maxStars=2*maxNodes-1; |
| 3 | + |
| 4 | +//using linkRep=unsigned long long; |
| 5 | + |
| 6 | +#include "netcomplexity.h" |
| 7 | + |
| 8 | +class linkRep |
| 9 | +{ |
| 10 | +public: |
| 11 | + using Impl=/*long long*/ unsigned; |
| 12 | +private: |
| 13 | + constexpr static unsigned size=maxNodes*(maxNodes-1)/(16*sizeof(Impl))+1; |
| 14 | + Impl data[linkRep::size]; |
| 15 | + CLASSDESC_ACCESS(linkRep); |
| 16 | +public: |
| 17 | + linkRep()=default; |
| 18 | + linkRep(unsigned long long x) { |
| 19 | + static_assert(sizeof(data)>=sizeof(x)); |
| 20 | + memcpy(data,&x,sizeof(x)); |
| 21 | + memset(((char*)data)+sizeof(x),0,sizeof(data)-sizeof(x)); |
| 22 | + } |
| 23 | + const linkRep& operator|=(const linkRep& x) { |
| 24 | + for (unsigned i=0; i<size; ++i) data[i]|=x.data[i]; |
| 25 | + return *this; |
| 26 | + } |
| 27 | + linkRep operator|(linkRep x) {return x|=*this;} |
| 28 | + const linkRep& operator&=(const linkRep& x) { |
| 29 | + for (unsigned i=0; i<size; ++i) data[i]&=x.data[i]; |
| 30 | + return *this; |
| 31 | + } |
| 32 | + linkRep operator&(linkRep x) {return x&=*this;} |
| 33 | + |
| 34 | + linkRep operator~() const { |
| 35 | + linkRep r; |
| 36 | + for (unsigned i=0; i<size; ++i) r.data[i]=~data[i]; |
| 37 | + return r; |
| 38 | + } |
| 39 | + linkRep operator<<(int n) { |
| 40 | + linkRep r; |
| 41 | + auto d=div(n, int(8*sizeof(Impl))); |
| 42 | + for (unsigned i=0; i<size-d.quot; ++i) |
| 43 | + r.data[i+d.quot]=data[i]<<d.rem; |
| 44 | + return r; |
| 45 | + } |
| 46 | + operator const void*() const { |
| 47 | + for (unsigned i=0; i<size; ++i) |
| 48 | + if (data[i]) return data; |
| 49 | + return nullptr; |
| 50 | + } |
| 51 | + |
| 52 | + bool operator<(const linkRep& x) const { |
| 53 | + for (unsigned i=0; i<size; ++i) |
| 54 | + { |
| 55 | + if (data[i]<x.data[i]) return true; |
| 56 | + if (data[i]>x.data[i]) return false; |
| 57 | + } |
| 58 | + return false; |
| 59 | + } |
| 60 | + std::vector<linkRep::Impl> dataAsVector() const { |
| 61 | + return std::vector<Impl>(data,data+size); |
| 62 | + } |
| 63 | + void dataFromVector(const std::vector<linkRep::Impl>& x) { |
| 64 | + memcpy(data,x.data(),std::min(size_t(size),x.size())*sizeof(linkRep::Impl)); |
| 65 | + } |
| 66 | +}; |
| 67 | + |
| 68 | +// Convert to/from a JSON array for Python conversion |
| 69 | +#define CLASSDESC_json_pack___linkRep |
| 70 | +#define CLASSDESC_json_unpack___linkRep |
| 71 | + |
| 72 | +#include "json_pack_base.h" |
| 73 | +namespace classdesc_access |
| 74 | +{ |
| 75 | + template <> struct access_json_pack<linkRep> { |
| 76 | + template <class _CD_ARG_TYPE> |
| 77 | + void operator()(classdesc::json_pack_t& targ, const classdesc::string& desc,_CD_ARG_TYPE& arg) |
| 78 | + { |
| 79 | + std::vector<linkRep::Impl> tmp=arg.dataAsVector(); |
| 80 | + targ<<tmp; |
| 81 | + } |
| 82 | + }; |
| 83 | + |
| 84 | + template <> struct access_json_unpack<linkRep> { |
| 85 | + template <class _CD_ARG_TYPE> |
| 86 | + void operator()(classdesc::json_pack_t& targ, const classdesc::string& desc,_CD_ARG_TYPE& arg) |
| 87 | + { |
| 88 | + std::vector<linkRep::Impl> tmp; |
| 89 | + targ>>tmp; |
| 90 | + arg.dataFromVector(tmp); |
| 91 | + } |
| 92 | + }; |
| 93 | +} |
| 94 | + |
| 95 | +static_assert(sizeof(linkRep)*8 > (maxNodes*(maxNodes-1))/2); |
2 | 96 |
|
3 | 97 | #include <map>
|
4 | 98 | #include <unordered_map>
|
|
0 commit comments