SheafSystem  0.0.0.0
interval_index_space_state.cc
Go to the documentation of this file.
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
20 
21 #include "SheafSystem/interval_index_space_state.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/interval_index_space_handle.h"
24 #include "SheafSystem/interval_index_space_iterator.h"
25 #include "SheafSystem/deep_size.h"
26 #include "SheafSystem/hub_index_space_handle.h"
27 #include "SheafSystem/scoped_index.h"
28 
29 // ===========================================================
30 // SPACE FACTORY FACET
31 // ===========================================================
32 
33 // PUBLIC MEMBER FUNCTIONS
34 
38  const std::string& xname,
39  bool xis_persistent,
40  bool xmerge_mode)
41 {
42  // Preconditions:
43 
44  require(!xname.empty());
45  require(!xid_spaces.contains(xname));
46 
47  // Body:
48 
50  lstate->new_state(xid_spaces, xname, xis_persistent);
51 
52  lstate->_merge_mode = xmerge_mode;
53 
54  interval_index_space_handle result(*lstate);
55 
56  // Postconditions:
57 
58  ensure(&result.id_spaces() == &xid_spaces);
59  ensure(xid_spaces.contains(xname));
60  ensure(result.conforms_to_state(xname));
61 
62  ensure(result.is_persistent() == xis_persistent);
63  ensure(result.name() == xname);
64 
65  ensure(result.merge_mode() == xmerge_mode);
66 
67  // Exit:
68 
69  return result;
70 }
71 
75  pod_index_type xid,
76  const std::string& xname,
77  bool xis_persistent,
78  bool xmerge_mode)
79 {
80  // Preconditions:
81 
82  require(!xid_spaces.contains(xid));
83  require(xid_spaces.is_explicit_interval(xid));
84  require(!xname.empty());
85  require(!xid_spaces.contains(xname));
86 
87  // Body:
88 
90  lstate->new_state(xid_spaces, xid, xname, xis_persistent);
91 
92  lstate->_merge_mode = xmerge_mode;
93 
94  interval_index_space_handle result(*lstate);
95 
96  // Postconditions:
97 
98  ensure(&result.id_spaces() == &xid_spaces);
99  ensure(xid_spaces.contains(xname));
100  ensure(result.conforms_to_state(xname));
101 
102  ensure(result.index() == xid);
103  ensure(result.is_persistent() == xis_persistent);
104  ensure(result.name() == xname);
105 
106  ensure(result.merge_mode() == xmerge_mode);
107 
108  // Exit:
109 
110  return result;
111 }
112 
113 // PROTECTED MEMBER FUNCTIONS
114 
115 // PRIVATE MEMBER FUNCTIONS
116 
117 
118 // ===========================================================
119 // INTERVAL_INDEX_SPACE_STATE FACET
120 // ===========================================================
121 
122 // PUBLIC MEMBER FUNCTIONS
123 
124 // PROTECTED MEMBER FUNCTIONS
125 
126 void
129  pod_type xdomain_end,
130  pod_type xrange_begin,
131  pod_type xrange_end,
132  std::map<pod_type, pod_type>& xmap,
133  bool xmerge_mode)
134 {
135  // Preconditions:
136 
137  // Body:
138 
139  // The map contains n entries {e(i) = (domain, range), 0 <= i < n}
140  // and two implicit entries e(-1) = (min_pod_index, invalid) and
141  // e(n) = (max_pod_index, invalid).
142  // These entries partition the domain id space into n+1 intervals:
143  //
144  // I(0) = [e(-1), e(0)-1],
145  // I(1) = [e(0), e(1)-1],
146  // ... ,
147  // I(i) = [e(i-1), e(i)-1],
148  // ... ,
149  // I(n) = [e(n-1), e(n)].
150  //
151  // An interval I(i) contains a domain id d if and only if e(i-1) <= d < e(i).
152  //
153  // The value of the map at an index p is calculated by finding
154  // e(i) = lower_bound(p) and interpolating back from e(i).domain to p;
155  // see function map_value for the details.
156  //
157  // We will refer to the interval defined by [xdomain_begin, xdomain_end]
158  // as the "new interval". The existing interval that contains xdomain_begin
159  // will be referred to as the "left interval". Similarly, the existing interval
160  // that contains xdomain_end will be referred to as the "right interval".
161  //
162  // The policy is that the new interval takes precedence over any existing
163  // intervals, so typically the left interval is truncated on the right by inserting
164  // a new entry (xdomain_begin, old map_value(xdomain_begin)) and the right
165  // interval is truncated on the left inserting a new entry (xdomain_end, xrange_end).
166  // Any existing entries that lie completely with the new interval are erased.
167  //
168  // Two special conditions complicate this typical case:
169  // (1) either xdomain_begin or xdomain_end falls on an existing entry, and/or
170  // (2) the new interval extends an existing interval.
171  // Condition (1) requires dealing with the existing record and
172  // changes how to detect condition (2). Condition (2) requires merging
173  // intervals by either not inserting records or erasing them.
174  //
175  // If xdomain_begin-1 != e(i) for any i, then the new interval "right extends"
176  // the left interval if xrange_begin == old map_value(xdomain_begin-1)+1 and we don't
177  // want to insert an entry for xdomain_begin because it doesn't terminate
178  // the left interval or begin the new interval.
179  //
180  // If xdomain_begin-1 == e(i) for some i, then the new interval right extends the
181  // left interval if xrange_begin-1 == e(i).range. Not only do we not want to insert
182  // a new entry, we want to erase the existing record because it no longer
183  // terminates the left interval or begins a new interval.
184  //
185  // Simlarly, if xdomain_end != e(i) for any i, the new interval "left extends"
186  // the right interval if xrange_end == map_value(xdomain_end) and we don't want
187  // to insert an entry for xdomain_end because it doesn't terminate the new
188  // interval or begin the right interval.
189  //
190  // If xdomain_end == e(i) for some i, then the condition that the new interval
191  // left extends the right interval is xrange_end == e(i).range. But since
192  // xdomain_end then just duplicates the existing entry, we don't need to do anything.
193 
194  // Put the beginning of the interval.
195 
196  pod_type left_of_xrange_begin =
197  is_valid(xrange_begin) ? xrange_begin - 1 : xrange_begin;
198 
199  map_type::iterator litr = xmap.find(xdomain_begin - 1);
200  if(litr != xmap.end())
201  {
202  // Begin-1 == end of left interval.
203 
204  pod_type lold_range_end = litr->second;
205 
206  if(xmerge_mode && (lold_range_end == left_of_xrange_begin))
207  {
208  // New interval right extends left interval;
209  // remove the end of the existing interval.
210 
211  xmap.erase(litr);
212  }
213  else
214  {
215  // New interval right truncates the left interval.
216  // do nothing.
217  }
218  }
219  else
220  {
221  // Begin is not the end of an existing interval.
222 
223  pod_type lold_range_begin = map_value(xdomain_begin, xmap);
224  if(xmerge_mode && (lold_range_begin == xrange_begin))
225  {
226  // New interval right extends left interval;
227  // do nothing.
228  }
229  else
230  {
231  // New interval right truncates left interval.
232 
233  xmap[xdomain_begin-1] =
234  is_valid(lold_range_begin) ? lold_range_begin - 1 : lold_range_begin;
235  }
236  }
237 
238  // Put the end of the interval.
239 
240  pod_type lold_range_end = map_value(xdomain_end, xmap);
241 
242  litr = xmap.find(xdomain_end);
243  if(litr != xmap.end())
244  {
245  // End == end of left interval.
246 
247  if(xmerge_mode && (xrange_end == litr->second))
248  {
249  // New entry duplicates existing entry;
250  // do nothing.
251  }
252  else
253  {
254  // Make entry to terminate new interval;
255  // erase existing entry.
256 
257  xmap.erase(litr);
258 
259  lold_range_end = map_value(xdomain_end, xmap);
260  if(xmerge_mode && (xrange_end == lold_range_end))
261  {
262  // New entry left extends right interval;
263  // do nothing.
264  }
265  else
266  {
267  // New entry left truncates right interval.
268 
269  xmap[xdomain_end] = xrange_end;
270  }
271  }
272  }
273  else
274  {
275  // End is not beginning of right interval.
276 
277  if(xmerge_mode && (xrange_end == lold_range_end))
278  {
279  // New interval left extends right interval;
280  // do nothing.
281  }
282  else
283  {
284  // Make entry to terminate new interval;
285  // truncates right interval.
286 
287  xmap[xdomain_end] = xrange_end;
288  }
289  }
290 
291  // Clear any existing entries within the interval.
292 
293  litr = xmap.lower_bound(xdomain_begin);
294  while(litr != xmap.end() && litr->first < xdomain_end)
295  {
296  xmap.erase(litr);
297  litr = xmap.lower_bound(xdomain_begin);
298  }
299 
300  // Postconditions:
301 
302  // Exit:
303 
304  return;
305 }
306 
309 map_value(pod_type xid, const std::map<pod_type, pod_type>& xmap)
310 {
311  // Preconditions:
312 
313  // Body:
314 
315  pod_type result;
316 
317  map_type::const_iterator itr = xmap.lower_bound(xid);
318  if(itr != xmap.end() && is_valid(itr->second))
319  {
320  // Xid is in a mapped interval;
321  // difference between result and domain end of interval
322  // same as difference between xid and range end of interval.
323 
324  result = itr->second - (itr->first - xid);
325  }
326  else
327  {
328  // Xid is not in a mapped interval;
329  // result is invalid.
330 
331  result = invalid_pod_index();
332  }
333 
334  // Postconditions:
335 
336  // Exit
337 
338  return result;
339 }
340 
344 {
345  // Preconditions:
346 
347  // Body:
348 
349  _merge_mode = true;
350  _capacity = 0;
351 
352  // Postconditions:
353 
354  ensure(invariant());
355  ensure(is_empty());
356  ensure(merge_mode());
357  ensure(capacity() == 0);
358 
359  // Exit:
360 
361  return;
362 }
363 
366 {
367  // Preconditions:
368 
369  // Body:
370 
371  // nothing to do.
372 
373  // Postconditions:
374 
375  // Exit:
376 
377  return;
378 }
379 
380 // PRIVATE MEMBER FUNCTIONS
381 
382 
383 // ===========================================================
384 // MUTABLE INDEX SPACE FACET
385 // ===========================================================
386 
387 // PUBLIC MEMBER FUNCTIONS
388 
389 void
392  pod_type xend,
393  const scoped_index& xhub_begin,
394  const scoped_index& xhub_end)
395 {
396  // Preconditions:
397 
398  require(xhub_begin.in_scope());
399  require(xhub_end.in_scope());
400  require(precondition_of(insert_interval(xbegin, xend.
401  xhub_begin.hub_pod(),
402  xhub_end.hub_pod())));
403 
404  // Body:
405 
406  insert_interval(xbegin, xend,
407  xhub_begin.hub_pod(), xhub_end.hub_pod());
408 
409  // Postconditions:
410 
411  ensure(postcondition_of(insert_interval(xbegin, xend,
412  xhub_begin.hub_pod(),
413  xhub_end.hub_pod())));
414 
415  // Exit:
416 
417  return;
418 }
419 
420 void
423  pod_type xend,
424  pod_type xhub_begin,
425  pod_type xhub_end)
426 {
427  // Preconditions:
428 
429  require(xhub_begin <= xhub_end);
430  require(xbegin <= xend);
431  require((xhub_end - xhub_begin) == (xend - xbegin));
432 
433  // Body:
434 
435  // Define old variables.
436 
437  define_old_variable(pod_type old_ct = ct());
438 
439  pod_type old_invalid_entry_ct = invalid_entry_ct(xhub_begin, xhub_end);
440 
441  // Insert the interval.
442 
443  map_rep_insert_interval(xbegin, xend, xhub_begin, xhub_end);
444 
445  // If this is the first interval, initialize the extrema.
446 
447  if(_ct == 0)
448  {
449  // First interval, initialize the extrema.
450 
451  _begin = xbegin;
452  _end = xend + 1;
453  }
454  else
455  {
456  // Not the first interval, update the extrema.
457 
458  if(xbegin < _begin)
459  {
460  _begin = xbegin;
461  }
462 
463  if(xend >= _end)
464  {
465  _end = xend + 1;
466  }
467  }
468 
469  // Update the count.
470 
471  _ct += old_invalid_entry_ct;
472 
473  // Postconditions:
474 
475  ensure(ct() >= old_ct);
476  ensure_for_range(pod_type i=xhub_begin, i<=xhub_end, ++i, pod(i) == xbegin+(i-xhub_begin));
477  ensure_for_range(pod_type i=xbegin, i<=xend, ++i, hub_pod(i) == xhub_begin+(i-xbegin));
478 
479  // Exit:
480 
481  return;
482 }
483 
484 void
486 push_interval(const scoped_index& xhub_begin, const scoped_index& xhub_end)
487 {
488  // Preconditions:
489 
490  require(xhub_begin.in_scope());
491  require(xhub_end.in_scope());
492  require(precondition_of(push_interval(xhub_begin.hub_pod(),
493  xhub_end.hub_pod())));
494 
495  // Body:
496 
497  push_interval(xhub_begin.hub_pod(), xhub_end.hub_pod());
498 
499  // Postconditions:
500 
501  ensure(postcondition_of(push_interval(xhub_begin.hub_pod(),
502  xhub_end.hub_pod())));
503 
504  // Exit:
505 
506  return;
507 }
508 
509 void
511 push_interval(pod_type xhub_begin, pod_type xhub_end)
512 {
513  // Preconditions:
514 
515  require(xhub_begin <= xhub_end);
516 
517  // Body:
518 
519  // Define old variables.
520 
521  define_old_variable(pod_type old_ct = ct());
522 
523  pod_type old_next_id = next_id();
524 
525  insert_interval(old_next_id, old_next_id + (xhub_end - xhub_begin),
526  xhub_begin, xhub_end);
527 
528  // Postconditions:
529 
530  ensure(ct() == old_ct + (xhub_end - xhub_begin + 1));
531  ensure(next_id() == old_next_id + (xhub_end - xhub_begin + 1));
532  ensure_for_range(pod_type i=xhub_begin, i<=xhub_end, ++i, pod(i) == old_next_id+(i-xhub_begin));
533 
534  // Exit:
535 
536  return;
537 }
538 
541 remove_interval(const scoped_index& xhub_begin,
542  const scoped_index& xhub_end)
543 {
544  // Preconditions:
545 
546  require(xhub_begin.in_scope());
547  require(xhub_end.in_scope());
548  require(precondition_of(remove_hub_interval(xhub_begin.hub_pod(),
549  xhub_end.hub_pod())));
550 
551  // Body:
552 
553  size_type result = remove_hub_interval(xhub_begin.hub_pod(),
554  xhub_end.hub_pod());
555 
556  // Postconditions:
557 
558  ensure(postcondition_of(remove_hub_interval(xhub_begin.hub_pod(),
559  xhub_end.hub_pod())));
560 
561  // Exit:
562 
563  return result;
564 }
565 
568 remove_hub_interval(pod_type xhub_begin, pod_type xhub_end)
569 {
570  // Preconditions:
571 
572  require(xhub_begin <= xhub_end);
573 
574  // Body:
575 
576  // Remove the interval.
577 
578  size_type result = map_rep_remove_interval(xhub_begin, xhub_end, true);
579 
580  // Update the count.
581 
582  _ct -= result;
583 
584  // Update the extrema.
585 
587 
588  // Postconditions:
589 
590  ensure_for_range(pod_type i=xhub_begin, i<=xhub_end, ++i, !contains_hub(i));
591 
592  // Exit
593 
594  return result;
595 }
596 
600 {
601  // Preconditions:
602 
603  require(xbegin <= xend);
604 
605  // Body:
606 
607  // Remove the interval.
608 
609  size_type result = map_rep_remove_interval(xbegin, xend, false);
610 
611  // Update the count.
612 
613  _ct -= result;
614 
615  // Update the extrema.
616 
618 
619  // Postconditions:
620 
621  ensure_for_range(pod_type i=xbegin, i<=xend, ++i, !contains(i));
622 
623  // Exit
624 
625  return result;
626 }
627 
630 interval_begin(const scoped_index& xid) const
631 {
632  // Preconditions:
633 
634  require(xid.in_scope());
635  require(precondition_of(interval_begin(xid.hub_pod())));
636 
637  // Body:
638 
639  pod_type result = interval_begin(xid.hub_pod());
640 
641  // Postconditions:
642 
643  ensure(postcondition_of(interval_begin(xid.hub_pod())));
644 
645  // Exit:
646 
647  return result;
648 }
649 
652 interval_begin(pod_type xhub_id) const
653 {
654  // Preconditions:
655 
656  // Body:
657 
658  pod_type result;
659 
660  to_domain_type::const_iterator itr = _to_domain.lower_bound(xhub_id);
661  if(itr != _to_domain.end() && is_valid(itr->second))
662  {
663  // Xhub_id is in a mapped interval; begin of the interval
664  // is the preceeding entry in the map + 1.
665 
666  --itr;
667  result = itr->first + 1;
668  }
669  else
670  {
671  // Xhub_id is not in a mapped interval;
672  // result is invalid.
673 
674  result = invalid_pod_index();
675  }
676 
677  // Postconditions:
678 
679  ensure(!is_valid(result) || contains_hub(result));
680 
681  // Exit:
682 
683  return result;
684 }
685 
688 interval_end(const scoped_index& xid) const
689 {
690  // Preconditions:
691 
692  require(xid.in_scope());
693  require(precondition_of(interval_end(xid.hub_pod())));
694 
695  // Body:
696 
697  pod_type result = interval_end(xid.hub_pod());
698 
699  // Postconditions:
700 
701  ensure(postcondition_of(interval_end(xid.hub_pod())));
702 
703  // Exit:
704 
705  return result;
706 }
707 
710 interval_end(pod_type xhub_id) const
711 {
712  // Preconditions:
713 
714  // Body:
715 
716  pod_type result;
717 
718  to_domain_type::const_iterator itr = _to_domain.lower_bound(xhub_id);
719  if(itr != _to_domain.end() && is_valid(itr->second))
720  {
721  // Xhub_id is in a mapped interval;
722 
723  result = itr->first;
724  }
725  else
726  {
727  // Xhub_id is not in a mapped interval;
728  // result is invalid.
729 
730  result = invalid_pod_index();
731  }
732 
733  // Postconditions:
734 
735  ensure(!is_valid(result) || contains_hub(result));
736 
737  // Exit:
738 
739  return result;
740 }
741 
742 bool
744 merge_mode() const
745 {
746  // Preconditions:
747 
748  // Body:
749 
750  bool result = _merge_mode;
751 
752  // Postcondtions:
753 
754  ensure(is_basic_query);
755 
756  // Exit:
757 
758  return result;
759 }
760 
761 void
763 put_merge_mode(bool xvalue)
764 {
765  // Preconditions:
766 
767  // Body:
768 
769  _merge_mode = xvalue;
770 
771  // Postconditions:
772 
773  ensure(merge_mode() == xvalue);
774 
775  // Exit:
776 
777  return;
778 }
779 
780 // PROTECTED MEMBER FUNCTIONS
781 
784 invalid_entry_ct(pod_type xhub_begin, pod_type xhub_end) const
785 {
786  // Preconditions:
787 
788  // Body:
789 
790  size_type result = xhub_end - xhub_begin + 1;
791 
792  pod_type lold_range_id = xhub_begin - 1;
793 
794  to_domain_type::const_iterator itr = _to_domain.lower_bound(xhub_begin);
795 
796  while(itr != _to_domain.end() && itr->first <= xhub_end)
797  {
798  if(is_valid(itr->second))
799  {
800  // The existing interval is populated, calculate the number of entries
801  // in the input interval.
802 
803  if(itr->first < xhub_end)
804  {
805  // The existing interval is completely in the input interval;
806  // Add the entire existing interval.
807 
808  result -= (itr->first - lold_range_id);
809  }
810  else
811  {
812  // The existing interval is only partly in the input interval;
813  // Add the remaining input interval.
814 
815  result -= (xhub_end - lold_range_id);
816  break;
817  }
818  }
819 
820  // Advance the iterator.
821 
822  lold_range_id = itr->first;
823  ++itr;
824  }
825 
826  // Preconditions:
827 
828  ensure(result >= 0);
829 
830  // Exit:
831 
832  return result;
833 }
834 
835 // PRIVATE MEMBER FUNCTIONS
836 
837 
838 // ===========================================================
839 // MUTABLE INDEX SPACE FACET
840 // ===========================================================
841 
842 // PUBLIC MEMBER FUNCTIONS
843 
844 // PROTECTED MEMBER FUNCTIONS
845 
846 // PRIVATE MEMBER FUNCTIONS
847 
848 
849 // ===========================================================
850 // GATHERED_INSERTION_INDEX_SPACE FACET
851 // ===========================================================
852 
853 // PUBLIC MEMBER FUNCTIONS
854 
855 void
858 {
859  // Preconditions:
860 
861  // Body:
862 
863  if(_ct == 0)
864  {
865  // The map is empty; invalidate the extrema.
866 
868  }
869  else
870  {
871  // Extract the extrema from the map.
872 
873  // Begin is the entry in _to_range
874  // before the first entry with a valid domain.
875 
876  to_range_type::const_iterator itr = _to_range.begin();
877  while(itr != _to_range.end())
878  {
879  if(is_valid(itr->second))
880  {
881  --itr;
882  _begin = itr->first + 1;
883  break;
884  }
885  ++itr;
886  }
887 
888  // End is last entry in _to_range with valid range.
889 
890  to_range_type::reverse_iterator ritr = _to_range.rbegin();
891  while(ritr != _to_range.rend())
892  {
893  if(is_valid(ritr->second))
894  {
895  _end = ritr->first + 1;
896  break;
897  }
898  ++ritr;
899  }
900  }
901 
902  // Postconditions:
903 
904  // Exit
905 
906  return;
907 }
908 
909 void
911 reserve(size_type xcapacity)
912 {
913  // Preconditions:
914 
915  // Body:
916 
917  _capacity = xcapacity;
918 
919  // Postconditions:
920 
921  ensure(invariant());
922  ensure(capacity() >= xcapacity);
923 
924  // Exit:
925 
926  return;
927 }
928 
931 capacity() const
932 {
933  // Preconditions:
934 
935  // Body:
936 
937  size_type result = _capacity;
938 
939  // Postconditions:
940 
941  ensure(is_basic_query);
942 
943  // Exit:
944 
945  return result;
946 }
947 
948 // PROTECTED MEMBER FUNCTIONS
949 
950 // PRIVATE MEMBER FUNCTIONS
951 
952 
953 // ===========================================================
954 // MAP REPRESENTATION FACET
955 // ===========================================================
956 
957 // PUBLIC MEMBER FUNCTIONS
958 
959 void
961 print_map_rep(std::ostream& xos) const
962 {
963  // Preconditions:
964 
965  // Body:
966 
967  using namespace std;
968 
969  xos << "_to_range: " << endl;
970 
971  for(map_type::const_iterator litr=_to_range.begin(); litr!=_to_range.end(); ++litr)
972  {
973  xos << " (" << litr->first << ", " << litr->second << ")";
974  }
975  xos << endl;
976 
977  xos << "_to_domain: " << endl;
978 
979  for(map_type::const_iterator litr=_to_domain.begin(); litr!=_to_domain.end(); ++litr)
980  {
981  xos << " (" << litr->first << ", " << litr->second << ")";
982  }
983  xos << endl;
984 
985  // Postconditions:
986 
987  ensure(is_basic_query);
988 
989  // Exit:
990 
991  return;
992 }
993 
994 // PROTECTED MEMBER FUNCTIONS
995 
996 void
999  pod_type xdomain_end,
1000  pod_type xrange_begin,
1001  pod_type xrange_end)
1002 {
1003  // Preconditions:
1004 
1005  require(xrange_begin <= xrange_end);
1006  require(xdomain_begin <= xdomain_end);
1007  require((xrange_end - xrange_begin) == (xdomain_end - xdomain_begin));
1008 
1009  // Body:
1010 
1011  insert_map_interval(xdomain_begin, xdomain_end,
1012  xrange_begin, xrange_end,
1014 
1015  insert_map_interval(xrange_begin, xrange_end,
1016  xdomain_begin, xdomain_end,
1018 
1019  // Postconditions:
1020 
1021  ensure_for_range(pod_type i=0, i<xrange_end-xrange_begin+1, ++i, pod(xrange_begin+i) == xdomain_begin+i);
1022  ensure_for_range(pod_type i=0, i<xdomain_end-xdomain_begin+1, ++i, hub_pod(xdomain_begin+i) == xrange_begin+i);
1023 
1024  // Exit:
1025 
1026  return;
1027 }
1028 
1031 map_rep_remove_interval(pod_type xbegin, pod_type xend, bool xis_range_id)
1032 {
1033  // Preconditions:
1034 
1035  require(xbegin <= xend);
1036 
1037  // Body:
1038 
1039  pod_type lbegin = xis_range_id ? xbegin : map_value(xbegin, _to_range);
1040  pod_type lend = xis_range_id ? xend : map_value(xend, _to_range);
1041 
1042  size_type result = 0;
1043 
1044  // Remove any mapped intervals included in [lbegin, lend)
1045  // from the _to_range direction.
1046 
1047  const pod_type linvalid = invalid_pod_index();
1048 
1049  pod_type lrange_begin = lbegin;
1050  pod_type lmapped_range_end = map_value(lend, _to_domain);
1051 
1052  to_domain_type::iterator litr = _to_domain.lower_bound(lrange_begin);
1053  while((lrange_begin <= lend) && (litr != _to_domain.end()))
1054  {
1055  pod_type lrange_end;
1056  pod_type ldomain_end;
1057 
1058  if(litr->first <= lend)
1059  {
1060  // Found interval completely contained
1061  // in [lbegin, lend].
1062 
1063  lrange_end = litr->first;
1064  ldomain_end = litr->second;
1065  }
1066  else
1067  {
1068  // Found interval only partly contained
1069  // in [lbegin, lend].
1070 
1071  lrange_end = lend;
1072  ldomain_end = lmapped_range_end;
1073  }
1074 
1075  if(is_valid(ldomain_end))
1076  {
1077  // Found an included mapped interval;
1078  // remove it from the _to_range map.
1079 
1080  pod_type ldomain_begin = ldomain_end - (lrange_end - lrange_begin);
1081 
1082  insert_map_interval(ldomain_begin, ldomain_end, linvalid, linvalid, _to_range, _merge_mode);
1083 
1084  // Add the number of ids removed from this mapped interval.
1085 
1086  result += lrange_end - lrange_begin + 1;
1087  }
1088 
1089  lrange_begin = lrange_end + 1;
1090  litr = _to_domain.lower_bound(lrange_begin);
1091  }
1092 
1093  // Remove [lbegin, lend] from the _to_domain direction.
1094 
1095  insert_map_interval(lbegin, lend, linvalid, linvalid, _to_domain, _merge_mode);
1096 
1097  // Postconditions:
1098 
1099  // Exit
1100 
1101  return result;
1102 }
1103 
1104 void
1107 {
1108  // Preconditions:
1109 
1110  require(!contains_hub(xrange_id));
1111  require(!contains(xdomain_id));
1112 
1113  // Body:
1114 
1115  map_rep_insert_interval(xdomain_id, xdomain_id, xrange_id, xrange_id);
1116 
1117  // Not finished inserting entry; do not ensure invariant.
1118 
1119  ensure(contains(xdomain_id, xrange_id));
1120 
1121  // Exit
1122 
1123  return;
1124 }
1125 
1126 void
1129 {
1130  // Preconditions:
1131 
1132  require(!contains_hub(xrange_id));
1133 
1134  // Body:
1135 
1136  pod_type old_next_id = next_id();
1137 
1138  map_rep_insert_interval(old_next_id, old_next_id, xrange_id, xrange_id);
1139 
1140  // Postconditions:
1141 
1142  // Not finished pushing back; do not ensure invariant.
1143 
1144  ensure(contains(old_next_id, xrange_id));
1145 
1146  // Exit
1147 
1148  return;
1149 }
1150 
1151 void
1154 {
1155  // Preconditions:
1156 
1157  require(allocated_iterator(xitr));
1158  require(!contains_hub(xrange_id));
1159 
1160  // Body:
1161 
1162  define_old_variable(pod_type old_itr_pod = xitr.pod());
1163  define_old_variable(pod_type old_itr_hub_pod = xitr.hub_pod());
1164 
1166 
1167  not_implemented();
1168 
1169  // Postconditions:
1170 
1171  // Not finished inserting entry, do not ensure invariant.
1172 
1173  ensure(contains(old_itr_pod, xrange_id));
1174  ensure(xitr.pod() == old_itr_pod+1);
1175  ensure(xitr.hub_pod() == old_itr_hub_pod);
1176 
1177  // Exit:
1178 
1179  return;
1180 }
1181 
1184 map_rep_remove_entry(pod_type xid, bool xis_range_id)
1185 {
1186  // Preconditions:
1187 
1188  // Body:
1189 
1190  pod_type lid = xis_range_id ? xid : map_value(xid, _to_range);
1191 
1192  size_type result = map_rep_remove_interval(lid, lid, true);
1193 
1194  // Postconditions:
1195 
1196  // Not finished removing entry; do not ensure invariant.
1197 
1198  ensure(xis_range_id ? !contains_hub(xid) : !contains(xid));
1199 
1200  // Exit
1201 
1202  return result;
1203 }
1204 
1205 void
1208 {
1209  // Preconditions:
1210 
1211  require(allocated_iterator(xitr));
1212  require(!xitr.is_done());
1213  require(contains(xitr.pod()));
1214 
1215  // Body:
1216 
1217  define_old_variable(pod_type old_itr_id = xitr.pod());
1218  define_old_variable(pod_type old_itr_hub_id = xitr.hub_pod());
1219 
1221 
1222  not_implemented();
1223 
1224  // Postconditions:
1225 
1226  ensure(!contains(old_itr_id));
1227  ensure(!contains(old_itr_hub_id));
1228  ensure(xitr.is_done() || xitr.pod() > old_itr_id);
1229 
1230  // Exit:
1231 
1232  return;
1233 }
1234 
1235 void
1238 {
1239  // Preconditions:
1240 
1241  // Body:
1242 
1243  _to_range.clear();
1244  _to_domain.clear();
1245 
1246  // Postconditions:
1247 
1248  // Not finished clearing; do not ensure invariant.
1249  // Map rep is empty, but _ct not reset, so can't ensure is_empty.
1250 
1251  ensure(unexecutable("map rep is empty"));
1252 
1253  // Exit:
1254 
1255  return;
1256 }
1257 
1258 void
1261 {
1262  // Preconditions:
1263 
1264  // Body:
1265 
1271 
1272  // Clear the domain map.
1273 
1274  _to_domain.clear();
1275 
1276  // Get the first entry.
1277 
1278  to_range_type::iterator litr = _to_range.begin();
1279  assertion(!is_valid(litr->second));
1280 
1281  // Add the first entry.
1282 
1283  pod_type ldomain_end = -1;
1284  pod_type lrange_end = litr->second;
1285 
1286  _to_domain[lrange_end] = invalid_pod_index();
1287  _to_range[ldomain_end] = invalid_pod_index();
1288 
1289  // Start the iteration.
1290 
1291  pod_type lold_domain_end;
1292  pod_type lct;
1293  pod_type lrange_begin;
1294 
1295  while(litr != _to_range.end())
1296  {
1297  lrange_end = litr->second;
1298 
1299  if(is_valid(lrange_end))
1300  {
1301  lct = (litr->first - lold_domain_end);
1302  ldomain_end += lct;
1303 
1304  _to_domain[lrange_end] = ldomain_end;
1305  _to_range[ldomain_end] = lrange_end;
1306 
1307  lrange_begin = (lrange_end - lct);
1308 
1309  if(_to_domain.find(lrange_begin) == _to_domain.end())
1310  {
1311  // There is no entry at range begin, add an invalid entry.
1312 
1313  _to_domain[lrange_begin] = invalid_pod_index();
1314  }
1315  }
1316 
1317  lold_domain_end = litr->first;
1318 
1319  // Copy the iterator.
1320 
1321  to_range_type::iterator lerase_itr = litr;
1322 
1323  // Advance the iterator.
1324 
1325  litr++;
1326 
1327  // Erase the old entry.
1328 
1329  if(ldomain_end != lold_domain_end)
1330  _to_range.erase(lerase_itr);
1331  }
1332 
1333  // Postconditions:
1334 
1335  ensure(unexecutable("map rep is gathered"));
1336 
1337  // Exit:
1338 
1339  return;
1340 }
1341 
1342 // PRIVATE MEMBER FUNCTIONS
1343 
1344 
1345 // ===========================================================
1346 // EXPLICIT_INDEX_SPACE_STATE FACET
1347 // ===========================================================
1348 
1349 // PUBLIC MEMBER FUNCTIONS
1350 
1351 bool
1354 {
1355  // Preconditions:
1356 
1357  require(is_ancestor_of(&xother));
1358 
1359  // Body:
1360 
1361  const interval_index_space_state& lother =
1362  dynamic_cast<const interval_index_space_state&>(xother);
1363 
1365  result = result && (_to_range == lother._to_range);
1366  result = result && (_to_domain == lother._to_domain);
1367  result = result && (_merge_mode == lother._merge_mode);
1368  result = result && (_capacity == lother._capacity);
1369 
1370  // Postconditions:
1371 
1372  // Exit
1373 
1374  return result;
1375 }
1376 
1379 deep_size(bool xinclude_shallow) const
1380 {
1381  // Preconditions:
1382 
1383  // Body:
1384 
1385  size_type result = sheaf::deep_size(*this, xinclude_shallow);
1386 
1387  // Postconditions:
1388 
1389  ensure(result >= 0);
1390 
1391  // Exit:
1392 
1393  return result;
1394 }
1395 
1396 // PROTECTED MEMBER FUNCTIONS
1397 
1401 {
1402  // Preconditions:
1403 
1404  require(is_ancestor_of(&xother));
1405 
1406  // Body:
1407 
1408  const interval_index_space_state& lother =
1409  dynamic_cast<const interval_index_space_state&>(xother);
1410 
1411  _to_domain = lother._to_domain;
1412  _to_range = lother._to_range;
1413  _merge_mode = lother._merge_mode;
1414  _capacity = lother._capacity;
1415 
1416  (void) scattered_insertion_index_space_state::operator=(xother);
1417 
1418  // Postconditions:
1419 
1420  ensure(invariant());
1421  ensure((*this) == xother);
1422 
1423  // Exit
1424 
1425  return *this;
1426 }
1427 
1428 // PRIVATE MEMBER FUNCTIONS
1429 
1430 
1431 // ===========================================================
1432 // INDEX SPACE FACET
1433 // ===========================================================
1434 
1435 // PUBLIC MEMBER FUNCTIONS
1436 
1437 bool
1439 contains(pod_type xid) const
1440 {
1441  // Preconditions:
1442 
1443  // Body:
1444 
1445  to_range_type::const_iterator itr = _to_range.lower_bound(xid);
1446 
1447  bool result = (itr != _to_range.end()) && is_valid(itr->second);
1448 
1449  // Postconditions:
1450 
1451  ensure(is_basic_query);
1452 
1453  // Exit
1454 
1455  return result;
1456 }
1457 
1458 bool
1461 {
1462  // Preconditions:
1463 
1464  // Body:
1465 
1466  to_domain_type::const_iterator itr = _to_domain.lower_bound(xhub_id);
1467 
1468  bool result = (itr != _to_domain.end()) && is_valid(itr->second);
1469 
1470  // Postconditions:
1471 
1472  ensure(is_basic_query);
1473 
1474  // Exit
1475 
1476  return result;
1477 }
1478 
1481 pod(pod_type xhub_id) const
1482 {
1483  // Preconditions:
1484 
1485  // Body:
1486 
1487  pod_type result = map_value(xhub_id, _to_domain);
1488 
1489  // Postconditions:
1490 
1491  ensure(!is_valid(result) || contains(result));
1492 
1493  // Exit
1494 
1495  return result;
1496 }
1497 
1501 {
1502  // Preconditions:
1503 
1504  // Body:
1505 
1506  pod_type result = map_value(xid, _to_range);
1507 
1508  // Postconditions:
1509 
1510  ensure(!is_valid(result) || contains_unglued_hub(result));
1511 
1512  // Exit:
1513 
1514  return result;
1515 }
1516 
1517 // PROTECTED MEMBER FUNCTIONS
1518 
1519 // PRIVATE MEMBER FUNCTIONS
1520 
1521 
1522 // ===========================================================
1523 // HANDLE POOL FACET
1524 // ===========================================================
1525 
1526 // PUBLIC MEMBER FUNCTIONS
1527 
1531 {
1532  // Preconditions:
1533 
1534  // Body:
1535 
1536  size_type result = handles().ct();
1537 
1538  // Postconditions:
1539 
1540  ensure(result >= 0);
1541 
1542  // Exit:
1543 
1544  return result;
1545 }
1546 
1550 {
1551  // Preconditions:
1552 
1553  // Body:
1554 
1555  size_type result = sheaf::deep_size(handles(), true);
1556 
1557  // Postconditions:
1558 
1559  ensure(result >= 0);
1560 
1561  // Exit:
1562 
1563  return result;
1564 }
1565 
1569 {
1570  // Preconditions:
1571 
1572  // Body:
1573 
1574  interval_index_space_handle& result = handles().get();
1575  attach(result);
1576 
1577  // Postconditions:
1578 
1579  ensure(result.is_attached());
1580 
1581  // Exit:
1582 
1583  return result;
1584 }
1585 
1586 void
1589 {
1590  // Preconditions:
1591 
1592  require(allocated_id_space(xid_space));
1593 
1594  // Body:
1595 
1596  // Detach the handle.
1597 
1598  xid_space.detach();
1599 
1600  // Release the handle to the pool.
1601 
1602  handles().release(reinterpret_cast<interval_index_space_handle&>(xid_space));
1603 
1604  // Postconditions:
1605 
1606  ensure(is_basic_query);
1607 
1608  // Exit:
1609 
1610  return;
1611 }
1612 
1613 bool
1616 {
1617  // Preconditions:
1618 
1619  // Body:
1620 
1621  const interval_index_space_handle* lid_space =
1622  dynamic_cast<const interval_index_space_handle*>(&xid_space);
1623 
1624  bool result = (lid_space != 0) && handles().allocated(*lid_space);
1625 
1626  // Postconditions:
1627 
1628  ensure(is_basic_query);
1629 
1630  // Exit:
1631 
1632  return result;
1633 }
1634 
1635 // PROTECTED MEMBER FUNCTIONS
1636 
1637 // PRIVATE MEMBER FUNCTIONS
1638 
1640 sheaf::interval_index_space_state::
1641 handles()
1642 {
1643  // Preconditions:
1644 
1645  // Body:
1646 
1648 
1649  // Postconditions:
1650 
1651  ensure(is_basic_query);
1652 
1653  // Exit:
1654 
1655  return result;
1656 }
1657 
1658 
1659 // ===========================================================
1660 // ITERATOR POOL FACET
1661 // ===========================================================
1662 
1663 // PUBLIC MEMBER FUNCTIONS
1664 
1668 {
1669  // Preconditions:
1670 
1671  // Body:
1672 
1673  size_type result = iterators().ct();
1674 
1675  // Postconditions:
1676 
1677  ensure(result >= 0);
1678 
1679  // Exit:
1680 
1681  return result;
1682 }
1683 
1687 {
1688  // Preconditions:
1689 
1690  // Body:
1691 
1692  size_type result = sheaf::deep_size(iterators(), true);
1693 
1694  // Postconditions:
1695 
1696  ensure(result >= 0);
1697 
1698  // Exit:
1699 
1700  return result;
1701 }
1702 
1706 {
1707  // Preconditions:
1708 
1709  // Body:
1710 
1711  interval_index_space_iterator& result = iterators().get();
1712  attach(result);
1713 
1714  // Postconditions:
1715 
1716  ensure(result.is_attached());
1717 
1718  // Exit:
1719 
1720  return result;
1721 }
1722 
1723 void
1726 {
1727  // Preconditions:
1728 
1729  require(allocated_iterator(xitr));
1730 
1731  // Body:
1732 
1733  // Detach the iterator.
1734 
1735  xitr.detach();
1736 
1737  // Release the iterator to the pool.
1738 
1739  iterators().release(reinterpret_cast<interval_index_space_iterator&>(xitr));
1740 
1741  // Postconditions:
1742 
1743  ensure(is_basic_query);
1744 
1745  // Exit:
1746 
1747  return;
1748 }
1749 
1750 bool
1753 {
1754  // Preconditions:
1755 
1756  // Body:
1757 
1758  const interval_index_space_iterator* litr =
1759  dynamic_cast<const interval_index_space_iterator*>(&xitr);
1760 
1761  bool result = (litr != 0) && iterators().allocated(*litr);
1762 
1763  // Postconditions:
1764 
1765  ensure(is_basic_query);
1766 
1767  // Exit:
1768 
1769  return result;
1770 }
1771 
1772 // PROTECTED MEMBER FUNCTIONS
1773 
1774 // PRIVATE MEMBER FUNCTIONS
1775 
1777 sheaf::interval_index_space_state::
1778 iterators()
1779 {
1780  // Preconditions:
1781 
1782  // Body:
1783 
1785 
1786  // Postconditions:
1787 
1788  ensure(is_basic_query);
1789 
1790  // Exit:
1791 
1792  return result;
1793 }
1794 
1795 
1796 // ===========================================================
1797 // FACTORY FACET
1798 // ===========================================================
1799 
1800 // PUBLIC MEMBER FUNCTIONS
1801 
1802 const std::string&
1804 class_name() const
1805 {
1806  static const std::string result("interval_index_space_state");
1807  return result;
1808 }
1809 
1812 clone() const
1813 {
1814  // Preconditions:
1815 
1816  // Body:
1817 
1819 
1820  // Postconditions:
1821 
1822  ensure(result != 0);
1823  ensure(is_same_type(result));
1824 
1825  // Exit:
1826 
1827  return result;
1828 }
1829 
1830 // PROTECTED MEMBER FUNCTIONS
1831 
1832 // PRIVATE MEMBER FUNCTIONS
1833 
1834 bool
1835 sheaf::interval_index_space_state::
1836 make_prototype()
1837 {
1838  // Preconditions:
1839 
1840  // Body:
1841 
1843 
1844  id_space_factory().insert_prototype(lproto);
1845 
1846  // Postconditions:
1847 
1848  // Exit:
1849 
1850  return true;
1851 }
1852 
1853 
1854 // ===========================================================
1855 // ANY FACET
1856 // ===========================================================
1857 
1858 // PUBLIC MEMBER FUNCTIONS
1859 
1860 bool
1862 is_ancestor_of(const any *other) const
1863 {
1864  // Preconditions:
1865 
1866  require(other != 0);
1867 
1868  // Body:
1869 
1870  // True if other conforms to this
1871 
1872  bool result = dynamic_cast<const interval_index_space_state*>(other) != 0;
1873 
1874  // Postconditions:
1875 
1876  // Exit:
1877 
1878  return result;
1879 }
1880 
1881 bool
1883 invariant() const
1884 {
1885  bool result = true;
1886 
1887  if(invariant_check())
1888  {
1889  // Prevent recursive calls to invariant
1890 
1892 
1893  // Must satisfy base class invariant
1894 
1896 
1897  // Invariances for this class:
1898 
1899  // Finished, turn invariant checking back on.
1900 
1902  }
1903 
1904  // Exit
1905 
1906  return result;
1907 }
1908 
1909 // PROTECTED MEMBER FUNCTIONS
1910 
1911 // PRIVATE MEMBER FUNCTIONS
1912 
1913 
1914 // ===========================================================
1915 // NON-MEMBER FUNCTIONS
1916 // ===========================================================
1917 
1918 size_t
1919 sheaf::
1920 deep_size(const interval_index_space_state& xn, bool xinclude_shallow)
1921 {
1922  // Preconditions:
1923 
1924  // Body:
1925 
1926  size_t result = xinclude_shallow ? sizeof(xn) : 0;
1927 
1928  // Add any contributions from the parent class.
1929 
1931  result += deep_size(ixn, false);
1932 
1933  // Add the memory allocated in member _to_domain.
1934 
1937  typedef no_deep_size_policy<map_type> map_policy_type;
1938  result += deep_size<pod_type, pod_type, map_policy_type>(xn._to_domain,
1939  false);
1940 
1941  // Add the memory allocated in member _to_range.
1942 
1943  result += deep_size<pod_type, pod_type, map_policy_type>(xn._to_range,
1944  false);
1945 
1946  // Postconditions:
1947 
1948  ensure(result >= 0);
1949 
1950  // Exit
1951 
1952  return result;
1953 }
An implementation of class scattered_insertion_index_space_handle that has a interval id space state...
virtual pod_type unglued_hub_pod(pod_type xid) const
The pod index in the unglued hub id space equivalent to xid in this id space.
An STL map implementation of class scattered_insertion_index_space_state optimized to efficiently rep...
bool contains_hub(pod_type xid) const
True if this space contains an id equivalent to xid in the unglued hub id space. synonym for contains...
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
size_type invalid_entry_ct(pod_type xhub_begin, pod_type xhub_end) const
The number of entries in the interval [xhub_begin, xhub_end] that have invalid map values...
size_type ct() const
The number of members.
virtual pod_type index() const
Index of this space.
bool in_scope() const
True if and only if scope() contains an entry for pod().
Definition: scoped_index.h:584
An abstract iterator over the ids of an id space.
to_range_type _to_range
The representation of the domain id to range id map.
pod_type interval_end(const scoped_index &xid) const
The end of the interval containing xid.hub_pod. synonym for internval_end(xid.hub_pod()).
virtual void map_rep_clear()
Removes all entrires from the map representation.
virtual bool conforms_to_state(const index_space_collection &xhost, pod_type xlocal_id) const
True if this conforms to the handle type required by the state with local scope id xlocal_id in the h...
virtual bool allocated_id_space(const index_space_handle &xid_space) const
True if and only if id space handle xid_space was allocated by the handle pool.
pod_type pod() const
The current id in the iteration.
size_type remove_hub_interval(pod_type xhub_begin, pod_type xhub_end)
Removes the equivalance associated with the interval [xhub_begin, xhub_end]. Returns the number of en...
static size_type iterator_pool_ct()
The number of iterators in the pool.
virtual bool is_persistent() const
True if this id space should be written to disk.
bool merge_mode() const
True if and only if compatible intervals should be merged.
static interval_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname, bool xis_persistent, bool xmerge_mode)
Create a new interval id space in the id space family xid_space at the next available id space index ...
void put_merge_mode(bool xvalue)
Sets merge_mode() to xvalue.
to_domain_type _to_domain
The representation of the range id to domain id map.
STL namespace.
virtual void detach()=0
Detach this handle form its state, if any.
An implementation of class explicit_index_space_state that supports either gathered or scattered inse...
An abstract handle to a space of alternate integer identifiers (aliases) for a subset of a hub set of...
virtual const index_space_family & id_spaces() const
The id space family for this (const version).
std::map< pod_type, pod_type > map_type
The type of the id maps.
virtual void detach()=0
Detach this handle form its state, if any.
pod_type interval_begin(const scoped_index &xid) const
The beginning of the interval containing xid.hub_pod(). synonym for internval_begin(xid.hub_pod()).
void print_map_rep(std::ostream &xos) const
Inserts the map representation into ostream xos.
friend SHEAF_DLL_SPEC size_t deep_size(const interval_index_space_state &xn, bool xinclude_shallow)
The deep size of interval_index_space_state& xn.
void attach(explicit_index_space_handle &xid_space) const
Attach the id space handle xid_space to this state.
pod_type _end
Ending id of this space.
virtual size_type capacity() const
The number of ids reserved in memory.
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual interval_index_space_state * clone() const
Virtual constructor; create a new instance of the same type at this.
bool merge_mode() const
True if and only if compatible intervals should be merged.
bool is_done() const
True if iteration is finished.
virtual bool invariant() const
Class invariant.
virtual void map_rep_gather()
Gathers the map representation into an interval.
An immutable abstract state for a space of alternate integer identifiers (aliases) for a subset of th...
virtual bool operator==(const explicit_index_space_state &xother) const
True if this is equivalent to xother.
virtual index_space_iterator & get_iterator() const
Allocates an id space iterator from the iterator pool.
std::string name() const
Name of this space.
Do not call deep_size on either the key or value.
Definition: deep_size.h:54
virtual bool allocated_iterator(const index_space_iterator &xitr) const
True if and only if id space iterator xitr was allocated by the iterator pool.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
virtual bool is_attached() const
True if this handle is attached to a state.
void insert_interval(pod_type xbegin, pod_type xend, const scoped_index &xhub_begin, const scoped_index &xhub_end)
Make the closed interval [xbegin, xend] equivalent to [xbegin.hub_pod(), xhub_end.hub_pod()]. synonym for insert_interval(xbegin, xend, xhub_begin.hub_pod(), xhub_end.hub_pod()).
void invalidate_extrema()
Invalidate the extrema.
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
virtual void map_rep_push_back(pod_type xrange_id)
Inserts entry (next_id(), xrange_id) into the map representation.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
virtual interval_index_space_state & operator=(const explicit_index_space_state &xother)
Assignment operator.
An iterator over an id space in which the equivalence between the ids in the space and the hub id spa...
bool is_explicit_interval(pod_type xid)
True, if and only if the id space interval that contains index xid is an explicit interval...
static pod_type map_value(pod_type xid, const std::map< pod_type, pod_type > &xmap)
The value of map xmap at id xid.
pod_type _capacity
The capacity of this map.
virtual void update_extrema_after_remove()
Update the id extrema after a remove operation.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
static void insert_map_interval(pod_type xdomain_begin, pod_type xdomain_end, pod_type xrange_begin, pod_type xrange_end, std::map< pod_type, pod_type > &xmap, bool xmerge_mode)
Maps the interval [xdomain_begin, xdomain_end] to.
virtual index_space_handle & get_id_space() const
The id space handle with this state.
void map_rep_insert_interval(pod_type xdomain_begin, pod_type xdomain_end, pod_type xrange_begin, pod_type xrange_end)
Inserts the intervals [xdomain_begin, xdomain_end] and [xrange_begin, xrange_end] into the map repres...
virtual size_type map_rep_remove_entry(pod_type xid, bool xis_range_id)
Removes the entry containing range id xid (xis_range_id true) or domain id xid (xis_range_id false) f...
virtual void update_extrema()
Update the id extrema.
virtual bool operator==(const explicit_index_space_state &xother) const
True if this is equivalent to xother.
virtual void release_id_space(index_space_handle &xid_space) const
Release the id space handle xid_space.
virtual pod_type pod(pod_type xid) const
The pod index in this space equivalent to xid in the hub id space.
size_type _ct
The number of members.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual void map_rep_insert_entry(pod_type xdomain_id, pod_type xrange_id)
Inserts entry (xdomain_id, xrange_id) into the map representation.
pod_index_type pod_type
The "plain old data" index type for this.
virtual bool contains_unglued_hub(pod_type xid) const
True if this space contains an id equivalent to xid in the unglued hub id space.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
bool _merge_mode
True if and only if compatible intervals should be merged.
virtual void reserve(size_type xcapacity)
Reserve enough memory for xcapacity number of ids.
static size_type handle_pool_ct()
The number of handles in the pool.
virtual void release_iterator(index_space_iterator &xitr) const
Returns the id space iterator xitr to the iterator pool.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
static size_type handle_pool_deep_size()
The deep size of the handle pool.
bool is_empty() const
True if there are no ids in the space.
virtual void map_rep_push(index_space_iterator &xitr, pod_type xrange_id)
Inserts entry (xitr.pod(), xrange_id) into the map representation. Increments all domain ids greater ...
Factory and container for a family of id spaces.
virtual const std::string & class_name() const
The name of this class.
virtual bool contains(pod_type xid) const
True if this space contains id xid.
void push_interval(const scoped_index &xhub_begin, const scoped_index &xhub_end)
Push the closed interval [xhub_begin.hub_pod(), xhub_end.hub_pod()] to the end of this space...
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
Definition: pod_types.cc:37
static factory< explicit_index_space_state > & id_space_factory()
A factory for making descendants of this class.
pod_type _begin
Beginning id of this space.
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
Definition: pod_types.cc:31
pod_type next_id() const
The id inserted by the next call to push_back.
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
size_type remove_interval(const scoped_index &xhub_begin, const scoped_index &xhub_end)
Removes the equivalance associated with the interval [xhub_begin.hub_pod(), xhub_end.hub_pod()]. synonym for remove_hub_interval(xhub_begin.hub_pod(), xhub_end.hub_pod()). Returns the number of entries actually removed, if any.
virtual bool is_attached() const
True if this iterator is attached to a state.
pod_type hub_pod(pod_type xid) const
The pod index in the unglued hub id space equivalent to xid in this id space. synonym for unglued_hub...
A reallocated pool of objects of type T. Objects in the pool are either allocated or stored in a free...
Definition: list_pool.h:42
size_type map_rep_remove_interval(pod_type xbegin, pod_type xend, bool xis_range_id)
Makes the interval [xbegin, xend) and its image unmapped in the map representation. Returns the number of entries actually unmapped, if any.
pod_type hub_pod() const
The current unglued hub id in the iteration. synonym for unglued_hub_pod().
static size_type iterator_pool_deep_size()
The deep size of the iterator pool.
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710