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