Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(797)

Side by Side Diff: src/IceRNG.h

Issue 1216963007: Doxygenize the documentation comments (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===- subzero/src/IceRNG.h - Random number generator -----------*- C++ -*-===// 1 //===- subzero/src/IceRNG.h - Random number generator -----------*- C++ -*-===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This file declares a random number generator. 10 // This file declares a random number generator.
(...skipping 15 matching lines...) Expand all
26 RandomNumberGenerator &operator=(const RandomNumberGenerator &) = delete; 26 RandomNumberGenerator &operator=(const RandomNumberGenerator &) = delete;
27 27
28 public: 28 public:
29 explicit RandomNumberGenerator(uint64_t Seed, llvm::StringRef Salt = ""); 29 explicit RandomNumberGenerator(uint64_t Seed, llvm::StringRef Salt = "");
30 uint64_t next(uint64_t Max); 30 uint64_t next(uint64_t Max);
31 31
32 private: 32 private:
33 uint64_t State; 33 uint64_t State;
34 }; 34 };
35 35
36 // This class adds additional random number generator utilities. The 36 /// This class adds additional random number generator utilities. The
37 // reason for the wrapper class is that we want to keep the 37 /// reason for the wrapper class is that we want to keep the
38 // RandomNumberGenerator interface identical to LLVM's. 38 /// RandomNumberGenerator interface identical to LLVM's.
39 class RandomNumberGeneratorWrapper { 39 class RandomNumberGeneratorWrapper {
40 RandomNumberGeneratorWrapper() = delete; 40 RandomNumberGeneratorWrapper() = delete;
41 RandomNumberGeneratorWrapper(const RandomNumberGeneratorWrapper &) = delete; 41 RandomNumberGeneratorWrapper(const RandomNumberGeneratorWrapper &) = delete;
42 RandomNumberGeneratorWrapper & 42 RandomNumberGeneratorWrapper &
43 operator=(const RandomNumberGeneratorWrapper &) = delete; 43 operator=(const RandomNumberGeneratorWrapper &) = delete;
44 44
45 public: 45 public:
46 uint64_t operator()(uint64_t Max) { return RNG.next(Max); } 46 uint64_t operator()(uint64_t Max) { return RNG.next(Max); }
47 bool getTrueWithProbability(float Probability); 47 bool getTrueWithProbability(float Probability);
48 explicit RandomNumberGeneratorWrapper(RandomNumberGenerator &RNG) 48 explicit RandomNumberGeneratorWrapper(RandomNumberGenerator &RNG)
49 : RNG(RNG) {} 49 : RNG(RNG) {}
50 50
51 private: 51 private:
52 RandomNumberGenerator &RNG; 52 RandomNumberGenerator &RNG;
53 }; 53 };
54 54
55 // RandomShuffle is an implementation of std::random_shuffle() that 55 /// RandomShuffle is an implementation of std::random_shuffle() that
56 // doesn't change across stdlib implementations. Adapted from a 56 /// doesn't change across stdlib implementations. Adapted from a
57 // sample implementation at cppreference.com. 57 /// sample implementation at cppreference.com.
58 template <class RandomIt, class RandomFunc> 58 template <class RandomIt, class RandomFunc>
59 void RandomShuffle(RandomIt First, RandomIt Last, RandomFunc &&RNG) { 59 void RandomShuffle(RandomIt First, RandomIt Last, RandomFunc &&RNG) {
60 for (auto i = Last - First - 1; i > 0; --i) 60 for (auto i = Last - First - 1; i > 0; --i)
61 std::swap(First[i], First[RNG(i + 1)]); 61 std::swap(First[i], First[RNG(i + 1)]);
62 } 62 }
63 63
64 } // end of namespace Ice 64 } // end of namespace Ice
65 65
66 #endif // SUBZERO_SRC_ICERNG_H 66 #endif // SUBZERO_SRC_ICERNG_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698