]> git.sesse.net Git - stockfish/commitdiff
Prefer size_t over int for array sizes
authorMarco Costalba <mcostalba@gmail.com>
Sun, 19 Aug 2012 09:20:15 +0000 (10:20 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 19 Aug 2012 10:01:46 +0000 (11:01 +0100)
Align to standard library conventions.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/benchmark.cpp
src/movegen.h
src/search.cpp
src/search.h
src/thread.cpp
src/thread.h

index 5800a37bb10484526c0aeb923d24c20bd2b0a0d8..c3a4191337d69c4d8f91f637e2c3839b8857eb78 100644 (file)
@@ -120,7 +120,7 @@ void benchmark(const Position& current, istream& is) {
 
       if (limitType == "perft")
       {
-          int64_t cnt = Search::perft(pos, limits.depth * ONE_PLY);
+          size_t cnt = Search::perft(pos, limits.depth * ONE_PLY);
           cerr << "\nPerft " << limits.depth  << " leaf nodes: " << cnt << endl;
           nodes += cnt;
       }
index 65d346b49696208aa07816e4e4cb04155c266f84..84d5d35ef70b07789f98e4149de0cf4ae3f95e41 100644 (file)
@@ -45,7 +45,7 @@ struct MoveList {
   void operator++() { cur++; }
   bool end() const { return cur == last; }
   Move move() const { return cur->move; }
-  int size() const { return int(last - mlist); }
+  size_t size() const { return last - mlist; }
 
 private:
   MoveStack mlist[MAX_MOVES];
index 8f1964dd6e9f8b426fc03a2189f30a068de6b7dc..a3ad7be13147b4cce2fb8e6d9cea2f2cd1c24045 100644 (file)
@@ -198,24 +198,23 @@ void Search::init() {
 /// Search::perft() is our utility to verify move generation. All the leaf nodes
 /// up to the given depth are generated and counted and the sum returned.
 
-int64_t Search::perft(Position& pos, Depth depth) {
+size_t Search::perft(Position& pos, Depth depth) {
 
-  StateInfo st;
-  int64_t cnt = 0;
-
-  MoveList<LEGAL> ml(pos);
-
-  // At the last ply just return the number of moves (leaf nodes)
+  // At the last ply just return the number of legal moves (leaf nodes)
   if (depth == ONE_PLY)
-      return ml.size();
+      return MoveList<LEGAL>(pos).size();
 
+  StateInfo st;
+  size_t cnt = 0;
   CheckInfo ci(pos);
-  for ( ; !ml.end(); ++ml)
+
+  for (MoveList<LEGAL> ml(pos); !ml.end(); ++ml)
   {
       pos.do_move(ml.move(), st, ci, pos.move_gives_check(ml.move(), ci));
       cnt += perft(pos, depth - ONE_PLY);
       pos.undo_move(ml.move());
   }
+
   return cnt;
 }
 
@@ -1541,7 +1540,7 @@ split_point_start: // At split points actual search starts from here
     int t = SearchTime.elapsed();
     int selDepth = 0;
 
-    for (int i = 0; i < Threads.size(); i++)
+    for (size_t i = 0; i < Threads.size(); i++)
         if (Threads[i].maxPly > selDepth)
             selDepth = Threads[i].maxPly;
 
index c573807b41bd01c1d9c28cf79464b94570e317da..d580b54695744fe79a62e6c777adbca4ddafc61c 100644 (file)
@@ -98,7 +98,7 @@ extern Position RootPosition;
 extern Time SearchTime;
 
 extern void init();
-extern int64_t perft(Position& pos, Depth depth);
+extern size_t perft(Position& pos, Depth depth);
 extern void think();
 
 } // namespace Search
index 0fbcc1fc65795395d7678c297da49267cee1ff10..0a8bacf7d09acebf34d40145697338b8fb970a10 100644 (file)
@@ -55,7 +55,7 @@ Thread::Thread(Fn fn) {
   lock_init(sleepLock);
   cond_init(sleepCond);
 
-  for (int j = 0; j < MAX_SPLITPOINTS_PER_THREAD; j++)
+  for (size_t j = 0; j < MAX_SPLITPOINTS_PER_THREAD; j++)
       lock_init(splitPoints[j].lock);
 
   if (!thread_create(handle, start_routine, this))
@@ -213,7 +213,7 @@ void ThreadPool::init() {
 
 ThreadPool::~ThreadPool() {
 
-  for (int i = 0; i < size(); i++)
+  for (size_t i = 0; i < size(); i++)
       delete threads[i];
 
   delete timer;
@@ -232,7 +232,7 @@ void ThreadPool::read_uci_options() {
   maxThreadsPerSplitPoint = Options["Max Threads per Split Point"];
   minimumSplitDepth       = Options["Min Split Depth"] * ONE_PLY;
   useSleepingThreads      = Options["Use Sleeping Threads"];
-  int requested           = Options["Threads"];
+  size_t requested        = Options["Threads"];
 
   assert(requested > 0);
 
@@ -253,7 +253,7 @@ void ThreadPool::read_uci_options() {
 
 void ThreadPool::wake_up() const {
 
-  for (int i = 0; i < size(); i++)
+  for (size_t i = 0; i < size(); i++)
   {
       threads[i]->maxPly = 0;
       threads[i]->do_sleep = false;
@@ -269,7 +269,7 @@ void ThreadPool::wake_up() const {
 
 void ThreadPool::sleep() const {
 
-  for (int i = 1; i < size(); i++) // Main thread will go to sleep by itself
+  for (size_t i = 1; i < size(); i++) // Main thread will go to sleep by itself
       threads[i]->do_sleep = true; // to avoid a race with start_searching()
 }
 
@@ -279,7 +279,7 @@ void ThreadPool::sleep() const {
 
 bool ThreadPool::available_slave_exists(Thread* master) const {
 
-  for (int i = 0; i < size(); i++)
+  for (size_t i = 0; i < size(); i++)
       if (threads[i]->is_available_to(master))
           return true;
 
@@ -344,7 +344,7 @@ Value ThreadPool::split(Position& pos, Stack* ss, Value alpha, Value beta,
   lock_grab(sp->lock);
   lock_grab(splitLock);
 
-  for (int i = 0; i < size() && !Fake; ++i)
+  for (size_t i = 0; i < size() && !Fake; ++i)
       if (threads[i]->is_available_to(master))
       {
           sp->slavesMask |= 1ULL << i;
index 73be23f108c509e8a23bd0c05c322a771d7b66c3..d1328daad91b9818859660e6adc18f0f83652b07 100644 (file)
@@ -67,14 +67,11 @@ struct SplitPoint {
 
 class Thread {
 
-  Thread(const Thread&);            // Only declared to disable the default ones
-  Thread& operator=(const Thread&); // that are not suitable in this case.
-
-  typedef void (Thread::* Fn) ();
+  typedef void (Thread::* Fn) (); // Pointer to member function
 
 public:
   Thread(Fn fn);
 ~Thread();
+ ~Thread();
 
   void wake_up();
   bool cutoff_occurred() const;
@@ -88,7 +85,7 @@ public:
   SplitPoint splitPoints[MAX_SPLITPOINTS_PER_THREAD];
   MaterialTable materialTable;
   PawnTable pawnTable;
-  int idx;
+  size_t idx;
   int maxPly;
   Lock sleepLock;
   WaitCondition sleepCond;
@@ -107,18 +104,15 @@ public:
 /// All the access to shared thread data is done through this class.
 
 class ThreadPool {
-  /* As long as the single ThreadPool object is defined as a global we don't
-     need to explicitly initialize to zero its data members because variables with
-     static storage duration are automatically set to zero before enter main()
-  */
+
 public:
-  void init(); // No c'tor becuase Threads is global and we need engine initialized
+  void init(); // No c'tor, Threads object is global and engine shall be fully initialized
   ~ThreadPool();
 
   Thread& operator[](int id) { return *threads[id]; }
   bool use_sleeping_threads() const { return useSleepingThreads; }
   int min_split_depth() const { return minimumSplitDepth; }
-  int size() const { return (int)threads.size(); }
+  size_t size() const { return threads.size(); }
   Thread* main_thread() { return threads[0]; }
 
   void wake_up() const;