23 using namespace basis;
29 span_manager::span_manager(
int packs)
34 : _implementation(new
bit_vector(*to_copy._implementation))
41 if (
this == &to_copy)
return *
this;
42 *_implementation = *to_copy._implementation;
58 if (
negative(recd_to))
return _implementation->
bits() - 1;
65 int zeros_start_at = _implementation->
find_first(0);
74 if (zeros_start_at >= 0) {
81 for (
int outer_loop = zeros_start_at + 2;
82 outer_loop < _implementation->
bits(); ) {
85 if (_implementation->
on(outer_loop)) {
87 ones_to_here = outer_loop;
88 int inner_loop = outer_loop + 1;
89 while (inner_loop < _implementation->bits()) {
90 if (_implementation->
on(inner_loop)) ones_to_here=inner_loop;
97 if ( (max_spans >= 0) && (to_make.
length() >= 2 * max_spans) )
99 outer_loop = ones_to_here + 1;
102 int inner_loop = outer_loop + 1;
103 ones_to_here = _implementation->
bits();
104 while (inner_loop < _implementation->bits()) {
105 if (!_implementation->
on(inner_loop)) inner_loop++;
108 ones_to_here = inner_loop;
113 outer_loop = ones_to_here;
120 for (
int i = 0; i < new_spans.
length(); i += 2) {
121 if ( (new_spans.
get(i) >= _implementation->
bits())
122 || (new_spans.
get(i+1) >= _implementation->
bits()) )
124 for (
int j = new_spans.
get(i); j <= new_spans.
get(i+1); j++)
125 _implementation->
light(j);
133 int ones_start_at = _implementation->
find_first(1);
142 if (ones_start_at >= 0) {
148 for (
int outer_loop = ones_start_at + 2;
149 outer_loop < _implementation->
bits(); ) {
152 if (!_implementation->
on(outer_loop)) {
154 zeros_to_here = outer_loop;
155 int inner_loop = outer_loop + 1;
156 while (inner_loop < _implementation->bits()) {
157 if (!_implementation->
on(inner_loop)) zeros_to_here=inner_loop;
165 if ( (max_spans >= 0) && (to_make.
length() >= 2 * max_spans) )
return;
166 outer_loop = zeros_to_here + 1;
169 inner_loop = outer_loop + 1;
170 zeros_to_here = _implementation->
bits();
171 while (inner_loop < _implementation->bits()) {
172 if (_implementation->
on(inner_loop))
176 zeros_to_here = inner_loop;
181 outer_loop = zeros_to_here;
186 astring span_manager::funky_print(
const int_array &to_spew,
int rec_seq)
const
188 astring to_return(astring::SPRINTF,
"through %d, [", rec_seq);
189 for (
int i = 0; i < to_spew.
length(); i += 2) {
190 to_return +=
astring(astring::SPRINTF,
" %d-%d", to_spew.
get(i),
201 astring to_return(
"received ");
void reset(int number=0, const contents *initial_contents=NULL_POINTER)
Resizes this array and sets the contents from an array of contents.
array & concatenate(const array &to_concatenate)
Appends the array "to_concatenate" onto "this" and returns "this".
const contents & get(int index) const
Accesses individual objects stored in "this" at the "index" position.
int length() const
Returns the current reported length of the allocated C array.
Provides a dynamically resizable ASCII character string.
A simple object that wraps a templated array of ints.
Manages lists of numbers representing the completion of some activity.
bool update(const basis::int_array &new_spans)
updates the span information.
int received_sequence() const
returns the highest chunk number at which all chunks are ready.
const structures::bit_vector & vector() const
observes the held bit_vector that represents the spans.
void make_missing_list(basis::int_array &spans, int max_spans=-1) const
creates a list representing the spans that are not ready yet.
void make_received_list(basis::int_array &spans, int max_spans=-1) const
Creates a list for the received spans that are ready.
span_manager(int number_of_items)
span_manager & operator=(const span_manager &to_copy)
basis::astring print_received_list() const
prints out the span list for received blocks into a string.
basis::astring print_missing_list() const
prints out the span list for missing blocks into a string.
void reset(int number_of_items)
sets up the span manager with a new configuration.
int missing_sequence() const
returns the number of the chunk where the first item is missing.
An array of bits with operations for manipulating and querying individual bits.
bool on(int position) const
returns true if the bit at "position" is set.
int find_first(bool to_find) const
Seeks the first occurrence of "to_find".
int bits() const
returns the number of bits in the vector.
void light(int position)
sets the value of the bit at "position".
void resize(int size)
Changes the size of the bit_vector to "size" bits.
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
bool negative(const type &a)
negative returns true if "a" is less than zero.
Provides access to the operating system's socket methods.
A dynamic container class that holds any kind of object via pointers.