mawinkle 6 anos atrás
pai
commit
ea985e4dff
7 arquivos alterados com 58 adições e 9 exclusões
  1. 0 0
      BigInt.hpp
  2. 51 2
      BigInt64.hpp
  3. 0 0
      server.cpp
  4. 0 0
      socketio.hpp
  5. 0 0
      socketio_posix.cpp
  6. 0 0
      socketio_win32.cpp
  7. 7 7
      test.cpp

+ 0 - 0
BigInt.hpp


+ 51 - 2
BigInt64.hpp

@@ -288,12 +288,13 @@ struct BigInt{
 		if(c < 0)return bitshiftRight(-c);
 		unsigned int sh = c % 64;
 		unsigned int jmp = c / 64;
-		if((unsigned int)jmp >= size() * sizeof(uint64_t)){std::fill(begin(),end(),0);return *this;}
+		if((unsigned int)jmp >= size()){std::fill(begin(),end(),0);return *this;}
 		auto it1 = begin(); 
 		auto it2 = it1 + jmp;
 		auto beforeEnd = end() - 1;
 		while(it2 != beforeEnd){
 			*it1 = (*it2 << sh);
+			if(sh)
 			*it1 |= (*(it2 + 1) >> (64 - sh));
 			++it1;++it2;
 		}
@@ -310,12 +311,13 @@ struct BigInt{
 		if(c < 0)return bitshiftLeft(-c);
 		unsigned int sh = c % 64;
 		unsigned int jmp = c / 64;
-		if((unsigned int)jmp >= size() * sizeof(uint64_t)){std::fill(begin(),end(),0);return *this;}
+		if((unsigned int)jmp >= size()){std::fill(begin(),end(),0);return *this;}
 		auto it1 = rbegin(); 
 		auto it2 = it1 + jmp;
 		auto beforeRend = rend() - 1;
 		while(it2 != beforeRend){
 			*it1 = (*it2 >> sh);
+			if(sh)
 			*it1 |= (*(it2 + 1) << (64 - sh));
 			++it1;++it2;
 		}
@@ -327,7 +329,51 @@ struct BigInt{
 		}
 		return *this;
 	}
+	BigInt operator<<(int c)const{
+		BigInt ret = *this;
+		ret.bitshiftLeft(c);
+		return ret;
+	}
 	
+	BigInt operator>>(int c)const{
+		BigInt ret = *this;
+		ret.bitshiftRight(c);
+		return ret;
+	}
+	
+	BigInt& operator<<=(int c){
+		return bitshiftLeft(c);
+	}
+	BigInt& operator>>=(int c){
+		return bitshiftRight(c);
+	}
+	int bitDifference(const BigInt& o){
+		int pos1(-1),pos2(-1);
+		auto it1 = begin();
+		auto it2 = o.begin();
+		while(it1 != end()){
+			if(*it1 == 0)
+				pos1 += 64;
+			else{
+				pos1 += __builtin_clzll(*it1);
+				break;
+			}
+			++it1;
+		}
+		if(pos1 == -1)pos1 = size() * 64;
+		while(it2 != end()){
+			if(*it2 == 0)
+				pos2 += 64;
+			else{
+				pos2 += __builtin_clzll(*it2);
+				break;
+			}
+			++it2;
+		}
+		if(pos1 == -1)pos1 = o.size() * 64;
+		int sizediff = ((signed int)size()) - ((signed int)o.size());
+		return pos2 - pos1 + sizediff * 64;
+	}
 	inline BigInt& chunkshiftLeft(int c){
 		if(c < 0)return chunkshiftRight(-c);
 		if((unsigned int)c >= size()){std::fill(begin(),end(),0);return *this;}
@@ -411,6 +457,9 @@ struct BigInt{
 		}
 		return *this;
 	}
+	inline BigInt moda(){
+		
+	}
 	inline BigInt mult(const BigInt& o)const{
 		BigInt result(size() + o.size() + 1,0);
 		BigInt temp(size() + o.size() + 1,0);

+ 0 - 0
server.cpp


+ 0 - 0
socketio.hpp


+ 0 - 0
socketio_posix.cpp


+ 0 - 0
socketio_win32.cpp


+ 7 - 7
test.cpp

@@ -29,13 +29,13 @@ std::ostream& operator<< <char>(std::ostream& out, std::vector<char> o){
 int main(){
 	xoshiro_256 gen(42);
 	for(int i = 0;i < 100;i++)gen();
-	BigInt a(gen, 2);
-	a[0] >>= 30;
-	BigInt x(2);
-	std::cout << x.rawString() << std::endl;
-	x.bitshiftLeft(64);
-	//x.bitshiftRight(25);
-	std::cout << x.rawString() << std::endl;// << ", " << a.rawString() << std::endl;
+	BigInt a(8);
+	//a[0] >>= 30;
+	BigInt x(4,0);
+	x.adda(a);
+	x.bitshiftRight(1);
+	std::cout << x.bitDifference(a) << std::endl;
+	
 	//std::cout << a.toString() << std::endl;
 	a.bitshiftLeft(1);
 	//std::cout << a.toString() << std::endl;