API 参考(主要接口与签名)
以下列出 STAR_CPP.h 中常用的公共接口签名与简要说明,按类组织。
IO
IO(const std::string& input_name, const std::string& output_name = "")~IO()template<typename T> void input(const T& data)template<typename T> void output(const T& data)template<typename T> IO& operator<<(const T& data)std::string get_input_filename() conststd::string get_output_filename() conststd::string read_output_all()void write_atomic(const std::string& filename, const std::string& data)void writeline(const std::string& line)void bind_input_stream(std::istream& in)void bind_output_stream(std::ostream& out)void createof(const std::string& executable_path)
Random
Random()/Random(unsigned seed)void seed(unsigned s)unsigned get_seed()int randint(int min, int max)double random(double min = 0.0, double max = 1.0)std::string randstr(int length, const std::string& charset)std::vector<int> randperm(int n)template<typename T> T choice(const std::vector<T>& container)double normal(double mean = 0.0, double stddev = 1.0)int poisson(double mean)bool bernoulli(double p = 0.5)template<typename T> T weighted_choice(const std::vector<T>& container, const std::vector<double>& weights)template<typename T> std::vector<T> sample_no_replace(const std::vector<T>& container, size_t k)template<typename T, typename InputIt> std::vector<T> reservoir_sample(InputIt begin, InputIt end, size_t k)
Graph
static std::vector<std::pair<int,int>> random_tree(int n, int seed = 0)static std::vector<std::pair<int,int>> random_graph(int n, int m, bool directed = false, int seed = 0)static std::vector<std::tuple<int,int,double>> random_weighted_graph(int n, int m, double minw = 0.0, double maxw = 1.0, int seed = 0)static std::vector<std::pair<int,int>> erdos_renyi(int n, double p, int seed = 0)static std::string to_edge_list_string(const std::vector<std::pair<int,int>>& edges)static std::vector<int> bfs(int n, const std::vector<std::pair<int,int>>& edges, int start = 1)static std::pair<int,std::vector<int>> connected_components(int n, const std::vector<std::pair<int,int>>& edges)
Sequence
static std::vector<int> random_array(int n, int min_val, int max_val, int seed = 0)static std::vector<int> increasing_array(...)static std::vector<int> decreasing_array(...)static std::vector<int> nearly_sorted(int n, int min_val, int max_val, double fraction = 0.05, int seed = 0)static std::vector<int> block_reversed(int n, int min_val, int max_val, int blocks = 4, int seed = 0)static std::vector<int> geometric_sequence(int n, int start, int ratio)static std::vector<std::string> random_string_array(int n, int len, const std::string& charset, int seed=0)
Tools
class Timer { void reset(); double elapsed_seconds() const; }struct Stats { void add(double x); double get_mean() const; double get_variance() const; }