semigroup.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #include "semigroup.hpp"
  2. void
  3. Semigroup::init_N(){
  4. c=1;
  5. g=0;
  6. m=1;
  7. e=1;
  8. e_left=0;
  9. left=1;
  10. for(size_t x=0;x<size;++x){
  11. delta[x]=1+x/2;
  12. }
  13. for(size_t x=0;x<nin;++x){
  14. in64[x]=18446744073709551615UL;
  15. }
  16. }
  17. void
  18. Semigroup::son(const Semigroup& S,size_t x,size_t pos){
  19. c=x+1;
  20. g=S.g+1;
  21. int e_delta;
  22. if(x>S.m){
  23. m=S.m;
  24. e_delta=(S.delta[x+S.m]==2)?0:-1;
  25. }
  26. else{
  27. m=S.m+1;
  28. e_delta=1;
  29. }
  30. e=S.e+e_delta;
  31. e_left=S.e_left+pos;
  32. left=S.left+x-S.c;
  33. copy_delta(S);
  34. copy_in(S);
  35. size_t sx=x%32;
  36. size_t bz=0;
  37. v8x8 z;
  38. z.v64=0;
  39. epu64 w;
  40. for(size_t bx=x/32;bx<navx;++bx){
  41. uint64_t temp=in32[bz];
  42. z.v64+=(temp<<sx);
  43. w.data[0]=load_mask[z.v8[0]];
  44. w.data[1]=load_mask[z.v8[1]];
  45. w.data[2]=load_mask[z.v8[2]];
  46. w.data[3]=load_mask[z.v8[3]];
  47. avx[bx]=_mm256_sub_epi8(avx[bx],w.avx);
  48. z.v32[0]=z.v32[1];
  49. z.v32[1]=0;
  50. ++bz;
  51. }
  52. in64[x/64]^=(1UL<<(x%64));
  53. }
  54. void
  55. Semigroup::display() const{
  56. bool flag=false;
  57. cout<<'<';
  58. for(size_t x=1;x<size;++x){
  59. if(delta[x]==1){
  60. if(flag) cout<<',';
  61. flag=true;
  62. cout<<x;
  63. }
  64. }
  65. cout<<"> m = "<<m<<" g = "<<g<<" c = "<<c<<endl;;
  66. /*for(size_t x=0;x<80;++x){
  67. if(x<10) cout<<' ';
  68. cout<<(int)x<<'|';
  69. }
  70. cout<<endl;
  71. for(size_t x=0;x<80;++x){
  72. cout<<"--|";
  73. }
  74. cout<<endl;
  75. for(size_t x=0;x<80;++x){
  76. if(delta[x]<10) cout<<' ';
  77. cout<<(int)delta[x]<<'|';
  78. }
  79. cout<<endl;
  80. for(uint64_t x=0;x<80;++x){
  81. // cout<<x<<" "<<x/64<<" and "<<(1UL<<(x%64))<<endl;
  82. if((in64[x/64U]&(1UL<<(x%(64))))==0){
  83. cout<<" n|";
  84. }
  85. else{
  86. cout<<" y|";
  87. }
  88. }
  89. cout<<endl;*/
  90. }
  91. void
  92. Semigroup::copy(const Semigroup& S){
  93. c=S.c;
  94. m=S.m;
  95. g=S.g;
  96. e=S.e;
  97. e_left=S.e_left;
  98. left=S.left;
  99. copy_delta(S);
  100. copy_in(S);
  101. }
  102. void
  103. Semigroup::to_file(string filename) const{
  104. fstream file;
  105. file.open(filename.c_str(),ios::out|ios::binary|ios::trunc);
  106. file.write((char*)delta,size);
  107. file.write((char*)in64,nin*8);
  108. file.write((char*)&c,sizeof(size_t));
  109. file.write((char*)&m,sizeof(size_t));
  110. file.write((char*)&g,sizeof(size_t));
  111. file.write((char*)&e,sizeof(size_t));
  112. file.write((char*)&e_left,sizeof(size_t));
  113. file.write((char*)&left,sizeof(size_t));
  114. file.close();
  115. }
  116. void
  117. Semigroup::from_file(string filename){
  118. fstream file;
  119. file.open(filename.c_str(),ios::in|ios::binary);
  120. file.read((char*)delta,size);
  121. file.read((char*)in64,nin*8);
  122. file.read((char*)&c,sizeof(size_t));
  123. file.read((char*)&m,sizeof(size_t));
  124. file.read((char*)&g,sizeof(size_t));
  125. file.read((char*)&e,sizeof(size_t));
  126. file.read((char*)&e_left,sizeof(size_t));
  127. file.read((char*)&left,sizeof(size_t));
  128. file.close();
  129. }