class shared_managed_population {
public:
pair interval_to_process(void) {
const int slice = disclosures.size() / thread_count
const int start = (slice*thread_number - 1) + 1
const int end = max(start + slice, disclosures.size())
return make_pair(start, end);
}
private:
vector disclosures;
int thread_number;
int thread_count;
};
shared_managed_population object
class shared_managed_population {
public:
pair interval_to_process(void) {
return interval_for_thread(
thread_number, thread_count, disclosures.size());
}
private:
pair interval_for_thread(
int thread_no, int thread_cnt, int collection_size) {
const int slice = collection_size / thread_cnt
const int start = (slice*thread_no - 1) + 1
const int end = max(start + slice, collection_size)
return make_pair(start, end);
}
vector disclosures;
int thread_number;
int thread_count;
};
interval_to_process doesn't do anything - nothing to test
interval_for_thread works through parameters - easy to test
This page last modified on 2 July 2001.