SheafSystem  0.0.0.0
primary_sum_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/primary_sum_index_space_state.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/deep_size.h"
24 #include "SheafSystem/index_space_family.h"
25 #include "SheafSystem/interval_index_space_state.h"
26 #include "SheafSystem/poset_path.h"
27 #include "SheafSystem/primary_index_space_handle.h"
28 #include "SheafSystem/primitive_value.h"
29 #include "SheafSystem/hub_index_space_iterator.h"
30 #include "SheafSystem/reserved_primary_index_space_state.h"
31 #include "SheafSystem/std_sstream.h"
32 
33 using namespace std;
34 
35 // ===========================================================
36 // SPACE FACTORY FACET
37 // ===========================================================
38 
39 // PUBLIC MEMBER FUNCTIONS
40 
44  const std::string& xname)
45 {
46  // Preconditions:
47 
48  require(!xname.empty());
49  require(!xid_spaces.contains(xname));
50 
51  // Body:
52 
54  lstate->new_state(xid_spaces, xname, false);
55 
56  hub_index_space_handle result(*lstate);
57 
58  // Postconditions:
59 
60  ensure(&result.id_spaces() == &xid_spaces);
61  ensure(xid_spaces.contains(xname));
62  ensure(result.conforms_to_state(xname));
63 
64  ensure(result.name() == xname);
65  ensure(!result.is_persistent());
66 
67  // Exit:
68 
69  return result;
70 }
71 
75  pod_index_type xid,
76  const std::string& xname)
77 {
78  // Preconditions:
79 
80  require(!xid_spaces.contains(xid));
81  require(xid_spaces.is_explicit_interval(xid));
82  require(!xname.empty());
83  require(!xid_spaces.contains(xname));
84 
85  // Body:
86 
88  lstate->new_state(xid_spaces, xid, xname, false);
89 
90  hub_index_space_handle result(*lstate);
91 
92  // Postconditions:
93 
94  ensure(&result.id_spaces() == &xid_spaces);
95  ensure(xid_spaces.contains(xname));
96  ensure(result.conforms_to_state(xname));
97 
98  ensure(result.index() == xid);
99  ensure(result.name() == xname);
100  ensure(!result.is_persistent());
101 
102  // Exit:
103 
104  return result;
105 }
106 
107 // PROTECTED MEMBER FUNCTIONS
108 
109 // PRIVATE MEMBER FUNCTIONS
110 
111 
112 // ===========================================================
113 // PRIMARY_SUM_INDEX_SPACE_STATE FACET
114 // ===========================================================
115 
116 // PUBLIC MEMBER FUNCTIONS
117 
118 // PROTECTED MEMBER FUNCTIONS
119 
123  _standard_id_end(0),
124  _term_id_begin(0),
125  _term_id_end(0),
126  _next_id(0)
127 {
128  // Preconditions:
129 
130  // Body:
131 
132  // Postconditions:
133 
134  ensure(invariant());
135  ensure(is_empty());
136 
137  // Exit:
138 
139  return;
140 }
141 
144 {
145  // Preconditions:
146 
147  // Body:
148 
149  // nothing to do.
150 
151  // Postconditions:
152 
153  // Exit:
154 
155  return;
156 }
157 
158 // PRIVATE MEMBER FUNCTIONS
159 
160 
161 // ===========================================================
162 // PRIMARY SUM INDEX SPACE FACET
163 // ===========================================================
164 
165 // PUBLIC MEMBER FUNCTIONS
166 
170 {
171  // Preconditions:
172 
173  // Body:
174 
176  {
177  // Current reserved term is full or has not been created;
178  // need to allocated a new term.
179 
181  }
182 
184 
185  // Insert member.
186 
187  _members.insert_member(result);
188 
189  // Update count and extrema.
190 
191  _ct++;
192 
193  update_extrema();
194 
195  // Postconditions:
196 
197  ensure(contains(result));
198  ensure(term_of(result).contains_hub(result));
199 
200  // Exit:
201 
202  return result;
203 }
204 
208 {
209  // Preconditions:
210 
211  require(is_valid_reserved_id(xid));
212 
213  // Body:
214 
215  pod_type lterm_id = term_id(xid);
216 
217  if(!is_valid(lterm_id))
218  {
219  // xid is not contained in any term; allocate a new term that includes it.
220 
221  // The allocated reserved term will be at term end.
222 
223  lterm_id = _term_id_end;
224 
225  // Create the reserved term.
226 
227  new_reserved_term(xid);
228  }
229 
230  // Insert the id into the reserved term.
231 
232  reinterpret_cast<reserved_primary_index_space_handle*>(_terms[lterm_id])->new_hub_id(xid);
233 
234  // Insert member.
235 
236  _members.insert_member(xid);
237 
238  // Update count and extrema.
239 
240  _ct++;
241 
242  update_extrema();
243 
244  // Postconditions:
245 
246  ensure(contains(xid));
247  ensure(term_of(xid).contains_hub(xid));
248 
249  // Exit:
250 
251  return xid;
252 }
253 
254 void
257 {
258  // Preconditions:
259 
260  // Body:
261 
262  if(_members.contains_member(xid))
263  {
264  _members.remove_member(xid);
265  _ct--;
266  update_extrema();
267  }
268 
269  // Postconditions:
270 
271  ensure(!contains(xid));
272 
273  // Exit:
274 
275  return;
276 }
277 
278 bool
281 {
282  // Preconditions:
283 
284  // Body:
285 
286  bool result;
287 
288  pod_type lterm_id = term_id(xid);
289  if(is_valid(lterm_id))
290  {
291  // There is a term, make sure it is a reserved term.
292 
293  index_space_handle* lterm = _terms[lterm_id];
294  if(dynamic_cast<reserved_primary_index_space_handle*>(lterm) != 0)
295  {
296  // The term is a reserved term, make sure the id is available.
297 
298  result = reinterpret_cast<reserved_primary_index_space_handle*>(lterm)->is_hub_id_available(xid);
299  }
300  else
301  {
302  // Not a reserved term, id is not valid.
303 
304  result = false;
305  }
306  }
307  else
308  {
309  // There is no term, is if the reserved interval is available.
310 
311  result = reserved_interval_is_available(xid);
312  }
313 
314  // Postconditions:
315 
316  ensure(is_basic_query);
317 
318  // Exit:
319 
320  return result;
321 }
322 
325 next_id() const
326 {
327  // Preconditions:
328 
329  // Body:
330 
331  pod_type result = _next_id;
332 
333  // Postconditions:
334 
335  ensure(is_basic_query);
336 
337  // Exit:
338 
339  return result;
340 }
341 
345 {
346  // Preconditions:
347 
348  require(interval_is_available(next_id(), next_id()+xct));
349 
350  // Body:
351 
352  define_old_variable(size_type old_ct = ct());
353  define_old_variable(pod_type old_term_id_end = term_id_end());
354  define_old_variable(pod_type old_next_id = next_id());
355 
356  pod_type result = new_primary_term(_next_id, xct);
357 
358  // Postconditions:
359 
360  ensure(invariant());
361  ensure(term_id_end() == old_term_id_end + 1);
362  ensure(id_spaces().contains(result));
363  ensure(interval_is_full(old_next_id, old_next_id+xct));
364  ensure(ct() == old_ct + xct);
365  ensure(next_id() == old_next_id + xct);
366 
367  // Exit:
368 
369  return result;
370 }
371 
375 {
376  // Preconditions:
377 
378  require(interval_is_available(xid, xid+xct));
379 
380  // Body:
381 
382  define_old_variable(size_type old_ct = ct());
383  define_old_variable(pod_type old_term_id_end = term_id_end());
384 
385  // Create the term.
386 
387  pod_type result =
389  next_term_name(),
390  xid, xct).index();
391 
392  // Add the term to this space.
393 
394  add_term(result, xid, xid+xct);
395 
396  // Add the members to the domain.
397 
398  _members.insert_interval(xid, xid+xct-1);
399 
400  // Increment the count.
401 
402  _ct += xct;
403 
404  // Update the extrema.
405 
406  update_extrema();
407 
408  // Postconditions:
409 
410  ensure(invariant());
411  ensure(term_id_end() == old_term_id_end + 1);
412  ensure(id_spaces().contains(result));
413  ensure(interval_is_full(xid, xid+xct));
414  ensure(ct() == old_ct + xct);
415 
416  // Exit:
417 
418  return result;
419 }
420 
421 void
424 {
425  // Preconditions:
426 
427  require(contains_term_id(xi));
428 
429  // Body:
430 
431  define_old_variable(pod_type old_term_ct = term(xi).ct());
432  define_old_variable(pod_type old_begin = _term_begin[xi]);
433  define_old_variable(pod_type old_end = _term_end[xi]);
434  define_old_variable(size_type old_ct = ct());
435  define_old_variable(pod_type old_term_id_begin = term_id_begin());
436  define_old_variable(pod_type old_term_id_end = term_id_end());
437 
438  // Remove the term from the sum id space.
439 
440  pod_type lbegin = _term_begin[xi];
441  pod_type lend = _term_end[xi];
442 
444  _terms[xi] = 0;
448  if(!is_valid(_sum_to_term_map.find(lbegin)->second))
449  _sum_to_term_map.erase(lbegin);
450 
451  // Set the term id extrema.
452 
453  if((xi == _term_id_begin) && (xi == _term_id_end-1))
454  {
455  // All the terms have been erased, set _term_id_begin to _term_id_end
456  // so that the next time the user inserts a term _term_id_begin will be
457  // correct.
458 
460  }
461  else if(xi == _term_id_begin)
462  {
463  for(pod_type i=xi+1; i < _term_id_end; ++i)
464  {
465  if(_terms[i] != 0)
466  {
467  // Found a term, that is the new term begin.
468 
469  _term_id_begin = i;
470  break;
471  }
472  }
473  }
474  else if(xi == _term_id_end-1)
475  {
476  for(pod_type i=xi-1; i >= _term_id_begin; --i)
477  {
478  if(_terms[i] != 0)
479  {
480  // Found a term, that is the new term end.
481 
482  _term_id_end = i+1;
483  break;
484  }
485  }
486  }
487 
488  // Decrement the count.
489 
490  pod_type lmember_end = lend - 1;
491 
492  _ct -= _members.member_ct(lbegin, lmember_end);
493 
494  // Remove the term's sum id interval.
495 
496  _members.remove_interval(lbegin, lmember_end);
497 
498  // Update the extrema.
499 
500  update_extrema();
501 
502  // Postconditions:
503 
504  ensure(invariant());
505  ensure(ct() <= old_ct);
506  ensure(term_id_begin() >= old_term_id_begin);
507  ensure(term_id_end() <= old_term_id_end);
508  ensure(interval_is_empty(old_begin, old_end - 1));
509 
510  // Exit:
511 
512  return;
513 }
514 
515 void
518 {
519  // Preconditions:
520 
521  // Body:
522 
523  define_old_variable(size_type old_ct = ct());
524  define_old_variable(pod_type old_term_id_end = term_id_end());
525 
526  // Get the last term
527 
528  pod_type last_term_id = _term_id_end - 1;
529 
531  reinterpret_cast<primary_index_space_handle*>(_terms[last_term_id]);
532  size_type old_last_term_ct = last_term->ct();
533 
534  pod_type old_last_term_begin = _term_begin[last_term_id];
535  pod_type new_last_term_end = old_last_term_begin + xct;
536 
537  // Update the term map.
538 
539  last_term->extend(xct);
540 
541  // Update term ends buffer.
542 
543  _term_end[last_term_id] = new_last_term_end;
544 
545  // Increment the count.
546 
547  _ct += (xct - old_last_term_ct);
548 
549  // Update the term's sum id interval.
550 
551  _members.insert_interval(old_last_term_begin, new_last_term_end - 1);
552 
553  // Update the extrema.
554 
555  update_extrema();
556 
557  // Postconditions:
558 
559  ensure(invariant());
560  ensure(ct() == (old_ct - old_last_term_ct + xct));
561  ensure(term_id_end() == old_term_id_end);
562  ensure(interval_is_full(old_last_term_begin, old_last_term_begin + xct));
563 
564  // Exit:
565 
566  return;
567 }
568 
569 bool
571 interval_is_full(pod_type xbegin, pod_type xend) const
572 {
573  // Preconditions:
574 
575  require(xbegin < xend);
576 
577  // Body:
578 
579  bool result = _members.interval_is_full(xbegin, xend - 1);
580 
581  // Postconditions:
582 
583  ensure(is_basic_query);
584 
585  // Exit:
586 
587  return result;
588 }
589 
590 bool
593 {
594  // Preconditions:
595 
596  require(xbegin < xend);
597 
598  // Body:
599 
600  bool result = _members.interval_is_empty(xbegin, xend - 1);
601 
602  // Postconditions:
603 
604  ensure(is_basic_query);
605 
606  // Exit:
607 
608  return result;
609 }
610 
611 bool
614 {
615  // Preconditons:
616 
617  require(xbegin < xend);
618 
619  // Body:
620 
621  bool result = true;
622 
623  for(pod_type i = _term_id_begin; result && (i < _term_id_end); ++i)
624  {
625  // Make sure no part of the interval does not overlap term.
626 
627  result = (_term_end[i] <= xbegin) || (_term_begin[i] >= xend);
628  }
629 
630  // Postconditions:
631 
632  ensure(is_basic_query);
633 
634  // Exit:
635 
636  return result;
637 }
638 
639 // PROTECTED MEMBER FUNCTIONS
640 
641 const std::string&
644 {
645  // Preconditions:
646 
647  // Body:
648 
649  static const std::string result("__hub_term_");
650 
651  // Postconditions:
652 
653  ensure(!result.empty());
654 
655  // Exit:
656 
657  return result;
658 }
659 
660 std::string
663 {
664  std::string result;
665 
666  // Preconditions:
667 
668  // Body:
669 
670  std::stringstream lstr;
671  lstr << term_prefix() << term_id_end();
672  lstr >> result;
673 
674  // Postconditions:
675 
676  ensure(!result.empty());
677 
678  // Exit:
679 
680  return result;
681 }
682 
686 {
687  // Preconditions:
688 
689  // Body:
690 
691  define_old_variable(pod_type old_next_id = _next_id);
692  define_old_variable(pod_type old_term_id_end = _term_id_end);
693 
695 
696  // Postconditions:
697 
698  ensure(_reserved_term.offset() >= old_next_id);
699  ensure(term_id_end() == old_term_id_end+1);
700  ensure(next_id() >= term_end(old_term_id_end));
701 
702  // Exit:
703 
704  return result;
705 }
706 
710 {
711  // Preconditions:
712 
713  // Body:
714 
715  define_old_variable(pod_type old_term_id_end = _term_id_end);
716 
717  // Term must begin at 0 mod RESERVED_TERM_SIZE and include xid;
718  // compute beginning of term.
719 
720  pod_type lterm_begin = (xid/RESERVED_TERM_SIZE)*RESERVED_TERM_SIZE;
721 
722  // Create the term.
723 
724  pod_type result =
726  next_term_name(),
727  lterm_begin,
729 
730  // Add the term to this id space.
731 
732  add_term(result, lterm_begin, lterm_begin+RESERVED_TERM_SIZE);
733 
734  // Update reserved term id.
735 
737 
738  // Postconditions:
739 
740  ensure(result == _reserved_term.index());
741  ensure(term_id_end() == old_term_id_end+1);
742  ensure(next_id() >= term_end(old_term_id_end));
743 
744  // Exit:
745 
746  return result;
747 }
748 
749 void
751 add_term(pod_type xterm_id, pod_type xbegin, pod_type xend)
752 {
753  // Preconditions:
754 
755  require(id_spaces().contains(xterm_id));
756  require(interval_is_available(xbegin, xend));
757 
758  // Body:
759 
760  define_old_variable(size_type old_ct = ct());
761  define_old_variable(pod_type old_term_id_end = term_id_end());
762 
763  // Add term handle.
764 
767 
768  _terms.force_item(_term_id_end, &lterm);
771 
773 
774  // Add an entry for the upper bound of the term.
775 
777 
778  // The interval below this term may be empty.
779  // Make sure ids in that interval don't map to this term.
780 
781  if(_sum_to_term_map.find(xbegin) == _sum_to_term_map.end())
782  {
784  }
785 
786  // Update the next available id.
787 
788  if(xend > _next_id)
789  {
790  _next_id = xend;
791  }
792 
793  // Increment the term end.
794 
795  _term_id_end++;
796 
797  // Postconditions:
798 
799  ensure(invariant());
800  ensure(term_id_end() == old_term_id_end + 1);
801  ensure(interval_is_empty(xbegin, xend));
802 
803  // Exit:
804 
805  return;
806 }
807 
808 bool
811 {
812  // Preconditions:
813 
814  // Body:
815 
817  pod_type lbegin = (xid/lsize)*lsize;
818  pod_type lend = lbegin + lsize;
819 
820  bool result = interval_is_available(lbegin, lend);
821 
822  // Postconditions:
823 
824  // Exit:
825 
826  return result;
827 }
828 
829 void
832 {
833  // Preconditions:
834 
835  // Body:
836 
837  if(_ct == 0)
838  {
839  // The map is empty; invalidate the extrema.
840 
842  }
843  else
844  {
845  // Extract the extrema from the members set.
846 
847  _begin = _members.begin();
848  _end = _members.end() + 1;
849  }
850 
851  // Postconditions:
852 
853  // Exit:
854 
855  return;
856 }
857 
858 // PRIVATE MEMBER FUNCTIONS
859 
860 
861 // ===========================================================
862 // GLUING FACET
863 // ===========================================================
864 
865 // PUBLIC MEMBER FUNCTIONS
866 
867 void
870 {
871  // Preconditions:
872 
873  require(contains_unique_rep(xid)); // Can't already be glued.
874  require(contains_rep(xrep));
875  require(term_id(xid) > term_id(xrep));
876 
877  // Body:
878 
879  _rem[xid] = xrep;
880  _rem_inv.insert(rem_inv_type::value_type(xrep, xid));
881 
883 
884  // Postconditions:
885 
886  ensure(invariant());
887  ensure(!contains_rep(xid));
888  ensure(glued_hub_pod(xid) == xrep);
889 
890  // Exit:
891 
892  return;
893 }
894 
895 void
898 {
899  // Preconditions:
900 
901  require(contains(xid));
902  require(!contains_rep(xid));
903 
904  // Body:
905 
906  // Get the representative member.
907 
908  pod_type lrep_id = hub_pod(xid);
909 
910  // Erase the entry in the rem map.
911 
912  _rem.erase(xid);
913 
914  // Find and erase the entry in the inverse rem map.
915 
916  typedef rem_inv_type::iterator itr_type;
917  pair<itr_type, itr_type> lrange = _rem_inv.equal_range(lrep_id);
918 
919  for(itr_type litr = lrange.first; litr != lrange.second; ++litr)
920  {
921  if(litr->second == xid)
922  {
923  _rem_inv.erase(litr);
924  break;
925  }
926  }
927 
929 
930  // Postconditions:
931 
932  ensure(invariant());
933  ensure(contains_unique_rep(xid));
934 
935  // Exit:
936 
937  return;
938 }
939 
940 void
943 {
944  // Preconditions:
945 
946  require(contains_rep(xrep_id));
947 
948  // Body:
949 
950  // Find and erase the entry in the rem map
951  // for each member of the equivalence class.
952 
953  typedef rem_inv_type::iterator itr_type;
954  pair<itr_type, itr_type> lrange = _rem_inv.equal_range(xrep_id);
955 
956  for(itr_type litr = lrange.first; litr != lrange.second; ++litr)
957  {
958  _rem.erase(litr->second);
959  }
960 
961  // Erase all the entries in the inverse rem map.
962 
963  _rem_inv.erase(xrep_id);
964 
966 
967  // Postconditions:
968 
969  ensure(invariant());
970  ensure(contains_unique_rep(xrep_id));
971 
972  // Exit:
973 
974  return;
975 }
976 
977 bool
979 has_gluing() const
980 {
981  // Preconditions:
982 
983  // Body:
984 
985  bool result = !_rem.empty();
986 
987  // Postconditions:
988 
989  ensure(is_basic_query);
990 
991  // Exit:
992 
993  return result;
994 }
995 
996 // PROTECTED MEMBER FUNCTIONS
997 
998 // PRIVATE MEMBER FUNCTIONS
999 
1000 
1001 // ===========================================================
1002 // GATHERED ID SPACE FACET
1003 // ===========================================================
1004 
1005 // PUBLIC MEMBER FUNCTIONS
1006 
1009 new_gathered_id_space(bool xexclude_bottom)
1010 {
1011  // Preconditions:
1012 
1013  require(!has_gathered_id_space());
1014 
1015  // Body:
1016 
1020  false, false);
1021 
1022  update_gathered_id_space(xexclude_bottom);
1023 
1024  // Postconditions:
1025 
1026  ensure(has_gathered_id_space());
1027  ensure(gathered_id_space().is_gathered());
1028  ensure(xexclude_bottom == gathered_id_space_excludes_bottom());
1029 
1030  // Exit:
1031 
1032  return _gathered_id_space;
1033 }
1034 
1035 void
1038 {
1039  // Preconditions:
1040 
1041  require(has_gathered_id_space());
1042 
1043  // Body:
1044 
1046 
1047  // Postconditions:
1048 
1049  ensure(gathered_id_space().is_gathered());
1050 
1051  // Exit:
1052 
1053  return;
1054 }
1055 
1059 {
1060  // Preconditions:
1061 
1062  require(has_gathered_id_space());
1063 
1064  // Body:
1065 
1066  // Postconditions:
1067 
1068  ensure(is_basic_query);
1069 
1070  // Exit:
1071 
1072  return _gathered_id_space;
1073 }
1074 
1075 bool
1078 {
1079  // Preconditions:
1080 
1081  // Body:
1082 
1083  bool result = _gathered_id_space.is_attached();
1084 
1085  // Postconditions:
1086 
1087  ensure(is_basic_query);
1088 
1089  // Exit:
1090 
1091  return result;
1092 }
1093 
1094 bool
1097 {
1098  // Preconditions:
1099 
1100  // Body:
1101 
1102  bool result = !_gathered_id_space.contains_hub(BOTTOM_INDEX);
1103 
1104  // Postconditions:
1105 
1106  ensure(is_basic_query);
1107 
1108  // Exit:
1109 
1110  return result;
1111 }
1112 
1113 const std::string&
1116 {
1117  // Preconditions:
1118 
1119  // Body:
1120 
1121  static const std::string result(poset_path::reserved_prefix() + "gathered_hub");
1122 
1123  // Postconditions:
1124 
1125  ensure(is_basic_query);
1126 
1127  // Exit:
1128 
1129  return result;
1130 }
1131 
1132 // PROTECTED MEMBER FUNCTIONS
1133 
1134 void
1136 update_gathered_id_space(bool xexclude_bottom)
1137 {
1138  // Preconditions:
1139 
1140  require(has_gathered_id_space());
1141 
1142  // Body:
1143 
1144  // Clear gathered id space if required.
1145 
1147  {
1149  }
1150 
1151  // Populate the gathered id space.
1152 
1153  pod_type lhub_begin = invalid_pod_index();
1154  pod_type lhub_end;
1155 
1157 
1158  while(litr != _members.interval_map().end())
1159  {
1160  if(litr->second)
1161  {
1162  // Interval is full, insert it.
1163 
1164  assertion(is_valid(lhub_begin)); // The first interval should have been empty.
1165 
1166  lhub_end = litr->first;
1167 
1168  if(!xexclude_bottom || lhub_begin > BOTTOM_INDEX || lhub_end < BOTTOM_INDEX)
1169  {
1170  _gathered_id_space.push_interval(lhub_begin, lhub_end);
1171  }
1172  else if(lhub_begin == BOTTOM_INDEX)
1173  {
1174  _gathered_id_space.push_interval(lhub_begin+1, lhub_end);
1175  }
1176  else if(lhub_end == BOTTOM_INDEX)
1177  {
1178  _gathered_id_space.push_interval(lhub_begin, lhub_end-1);
1179  }
1180  else
1181  {
1182  _gathered_id_space.push_interval(lhub_begin, BOTTOM_INDEX-1);
1183  _gathered_id_space.push_interval(BOTTOM_INDEX+1, lhub_end);
1184  }
1185  }
1186 
1187  // Update the hub begin.
1188 
1189  lhub_begin = litr->first + 1;
1190 
1191  // Increment to next interval.
1192 
1193  ++litr;
1194  }
1195 
1196  // Postconditions:
1197 
1198  ensure(gathered_id_space().is_gathered());
1199  ensure(xexclude_bottom == gathered_id_space_excludes_bottom());
1200 
1201  // Exit:
1202 
1203  return;
1204 }
1205 
1206 // PRIVATE MEMBER FUNCTIONS
1207 
1208 
1209 // ===========================================================
1210 // STANDARD IDS FACET
1211 // ===========================================================
1212 
1213 // PUBLIC MEMBER FUNCTIONS
1214 
1215 void
1218 {
1219  // Preconditions:
1220 
1221  // Body:
1222 
1223  _standard_id_end = end();
1224 
1225  // Postconditions:
1226 
1227  ensure(has_only_standard_ids());
1228 
1229  // Exit:
1230 
1231  return;
1232 }
1233 
1234 bool
1237 {
1238  // Preconditions:
1239 
1240  // Body:
1241 
1242  bool result = (_standard_id_end == end());
1243 
1244  // Postconditions:
1245 
1246  ensure(is_basic_query);
1247 
1248  // Exit:
1249 
1250  return result;
1251 }
1252 
1253 void
1256 {
1257  // Preconditions:
1258 
1259  // Body:
1260 
1261  if(!has_only_standard_ids())
1262  {
1263  // Determine the number of members to remove.
1264 
1266 
1267  if(lmember_ct > 0)
1268  {
1269  // There are members to remove, remove them.
1270 
1272 
1273  // Update count and extrema.
1274 
1275  _ct -= lmember_ct;
1276  update_extrema();
1277  }
1278 
1279  // Update standard id end.
1280 
1281  _standard_id_end = end();
1282  }
1283 
1284  // Postconditions:
1285 
1286  ensure(has_only_standard_ids());
1287 
1288  // Exit:
1289 
1290  return;
1291 }
1292 
1293 // PROTECTED MEMBER FUNCTIONS
1294 
1295 // PRIVATE MEMBER FUNCTIONS
1296 
1297 
1298 // ===========================================================
1299 // SUM INDEX SPACE FACET
1300 // ===========================================================
1301 
1302 // PUBLIC MEMBER FUNCTIONS
1303 
1304 bool
1306 contains_rep(pod_type xhub_id) const
1307 {
1308  // Preconditions:
1309 
1310  // Body:
1311 
1312  // _rem contains the reflexive reduction of the rem function,
1313  // that is, it contains an entry for sum id s if and only if
1314  // s is not its own representative. So s is a representative
1315  // if it is a hub id and is not contained in _rem.
1316 
1317  bool result =
1318  contains_hub(xhub_id) &&
1319  (_rem.find(xhub_id) == _rem.end());
1320 
1321  // Postconditions:
1322 
1323  ensure(result ? contains_hub(xhub_id) : true);
1324 
1325  // Exit:
1326 
1327  return result;
1328 }
1329 
1332 rep(pod_type xhub_id) const
1333 {
1334  // Preconditions:
1335 
1336  require(contains_hub(xhub_id));
1337 
1338  // Body:
1339 
1340  pod_type result;
1341 
1342  rem_type::const_iterator litr = _rem.find(xhub_id);
1343  if(litr != _rem.end())
1344  {
1345  // Xhub_id is not its own representative;
1346 
1347  result = litr->second;
1348  }
1349  else
1350  {
1351  // Xhub_id is its own representative.
1352 
1353  result = xhub_id;
1354  }
1355 
1356  // Postconditions:
1357 
1358  ensure(is_basic_query);
1359 
1360  // Exit:
1361 
1362  return result;
1363 }
1364 
1367 host_rep(pod_type xhub_id) const
1368 {
1369  // Preconditions:
1370 
1371  require(contains_hub(xhub_id));
1372 
1373  // Body:
1374 
1375  // Host id of rep is same as rep.
1376 
1377  pod_type result = rep(xhub_id);
1378 
1379  // Postconditions:
1380 
1381  ensure(contains(result));
1382 
1383  // Exit:
1384 
1385  return result;
1386 }
1387 
1391 {
1392  // Preconditions:
1393 
1394  // Body:
1395 
1396  pod_type result = _term_id_begin;
1397 
1398  // Postconditions:
1399 
1400  ensure(is_basic_query);
1401 
1402  // Exit:
1403 
1404  return result;
1405 }
1406 
1410 {
1411  // Preconditions:
1412 
1413  // Body:
1414 
1415  pod_type result = _term_id_end;
1416 
1417  // Postconditions:
1418 
1419  ensure(is_basic_query);
1420 
1421  // Exit:
1422 
1423  return result;
1424 }
1425 
1426 bool
1429 {
1430  // Preconditions:
1431 
1432  // Body:
1433 
1434  bool result = ((_term_id_begin <= xi) &&
1435  (xi < _term_id_end) &&
1436  (_terms[xi] != 0));
1437 
1438  // Postconditions:
1439 
1440  ensure(is_basic_query);
1441 
1442  // Exit:
1443 
1444  return result;
1445 }
1446 
1447 void
1450 {
1451  // Preconditions:
1452 
1453  // Body:
1454 
1456 
1457  _rem.clear();
1458  _members.clear();
1459  _term_id_begin = 0;
1460  _term_id_end = 0;
1461 
1462  // Postconditions:
1463 
1464  ensure(invariant());
1465  ensure(is_empty());
1466 
1467  // Exit:
1468 
1469  return;
1470 }
1471 
1472 // PROTECTED MEMBER FUNCTIONS
1473 
1474 // PRIVATE MEMBER FUNCTIONS
1475 
1476 
1477 // ===========================================================
1478 // EXPLICIT_INDEX_SPACE_STATE FACET
1479 // ===========================================================
1480 
1481 // PUBLIC MEMBER FUNCTIONS
1482 
1483 bool
1486 {
1487  // Preconditions:
1488 
1489  require(is_ancestor_of(&xother));
1490 
1491  // Body:
1492 
1493  const primary_sum_index_space_state& lother =
1494  dynamic_cast<const primary_sum_index_space_state&>(xother);
1495 
1496  bool result = sum_index_space_state::operator==(xother);
1497  result = result && (_members == lother._members);
1498  result = result && (_next_id == lother._next_id);
1499  result = result && (_reserved_term == lother._reserved_term);
1500  result = result && (_standard_id_end == lother._standard_id_end);
1503 // result = result && (_rem == lother._rem);
1504  result = result && (_term_id_begin == lother._term_id_begin);
1505  result = result && (_term_id_end == lother._term_id_end);
1506 
1507  // Postconditions:
1508 
1509  // Exit
1510 
1511  return result;
1512 }
1513 
1516 deep_size(bool xinclude_shallow) const
1517 {
1518  // Preconditions:
1519 
1520  // Body:
1521 
1522  size_type result = sheaf::deep_size(*this, xinclude_shallow);
1523 
1524  // Postconditions:
1525 
1526  ensure(result >= 0);
1527 
1528  // Exit:
1529 
1530  return result;
1531 }
1532 
1533 // PROTECTED MEMBER FUNCTIONS
1534 
1538 {
1539  // Preconditions:
1540 
1541  require(is_ancestor_of(&xother));
1542 
1543  // Body:
1544 
1545  const primary_sum_index_space_state& lother =
1546  dynamic_cast<const primary_sum_index_space_state&>(xother);
1547 
1548  _members = lother._members;
1549  _next_id = lother._next_id;
1550  _reserved_term = lother._reserved_term;
1552  _rem = lother._rem;
1553  _term_id_begin = lother._term_id_begin;
1554  _term_id_end = lother._term_id_end;
1555 
1556  (void) sum_index_space_state::operator=(xother);
1557 
1558  // Postconditions:
1559 
1560  ensure(invariant());
1561  ensure((*this) == xother);
1562 
1563  // Exit
1564 
1565  return *this;
1566 }
1567 
1568 // PRIVATE MEMBER FUNCTIONS
1569 
1570 
1571 // ===========================================================
1572 // INDEX SPACE FACET
1573 // ===========================================================
1574 
1575 // PUBLIC MEMBER FUNCTIONS
1576 
1577 bool
1579 contains(pod_type xid) const
1580 {
1581  // Preconditions:
1582 
1583  // Body:
1584 
1585  bool result = _members.contains_member(xid);
1586 
1587  // Postconditions:
1588 
1589  ensure(is_basic_query);
1590 
1591  // Exit
1592 
1593  return result;
1594 }
1595 
1596 bool
1599 {
1600  // Preconditions:
1601 
1602  // Body:
1603 
1604  bool result = _members.contains_member(xhub_id);
1605 
1606  // Postconditions:
1607 
1608  ensure(is_basic_query);
1609 
1610  // Exit
1611 
1612  return result;
1613 }
1614 
1615 bool
1618 {
1619  // Preconditions:
1620 
1621  // Body:
1622 
1623  // The glued hub id space is the subset of the unglued hub id space
1624  // that contains only the representative members of the equivalence classes.
1625  // _rem contains an entry for xhub_id if and only if xhub_id is not a
1626  // representative member. So xhub_id is contained in the glued hub id space
1627  // if and only if it is in the primary sum id space and _rem does not contain an entry for it.
1628 
1629  bool result =
1630  _members.contains_member(xhub_id) &&
1631  (_rem.find(xhub_id) == _rem.end());
1632 
1633  // Postconditions:
1634 
1635  ensure(is_basic_query);
1636 
1637  // Exit
1638 
1639  return result;
1640 }
1641 
1644 pod(pod_type xhub_id) const
1645 {
1646  // Preconditions:
1647 
1648  // Body:
1649 
1650  // The hub to primary sum direction of the map is identical to the inverse rem map.
1651  // The image of a hub id is thus a set of primary sum ids, the equivalence class
1652  // of the hub id. For consisentency with the base class, pod()
1653  // returns just one of the members of the equivalence class. The obvious
1654  // choice is the representative member, that is, xhub_id itself.
1655 
1656  pod_type result =
1657  contains_hub(xhub_id) ? xhub_id : invalid_pod_index();
1658 
1659  // Postconditions:
1660 
1661  ensure(!is_valid(result) || contains(result));
1662 
1663  // Exit
1664 
1665  return result;
1666 }
1667 
1671 {
1672  // Preconditions:
1673 
1674  // Body:
1675 
1676  pod_type result = contains(xid) ? xid : invalid_pod_index();
1677 
1678  // Postconditions:
1679 
1680  ensure(!is_valid(result) || contains_unglued_hub(result));
1681 
1682  // Exit:
1683 
1684  return result;
1685 }
1686 
1690 {
1691  // Preconditions:
1692 
1693  // Body:
1694 
1695  // The sum to host map is identical to the rem function, it's value is the
1696  // representative member of the equivalence class of xid.
1697 
1698  pod_type result;
1699 
1700  if(contains(xid))
1701  {
1702  // xid is in the sum id space.
1703 
1704  rem_type::const_iterator litr = _rem.find(xid);
1705  if(litr != _rem.end())
1706  {
1707  // xid is not its own representative;
1708 
1709  result = litr->second;
1710  }
1711  else
1712  {
1713  // xid is its own representative.
1714 
1715  result = xid;
1716  }
1717  }
1718  else
1719  {
1720  // xid is not in the sum id space;
1721  // result is invalid.
1722 
1723  result = invalid_pod_index();
1724  }
1725 
1726  // Postconditions:
1727 
1728  ensure(!is_valid(result) || contains_glued_hub(result));
1729 
1730  // Exit:
1731 
1732  return result;
1733 }
1734 
1735 // PROTECTED MEMBER FUNCTIONS
1736 
1737 // PRIVATE MEMBER FUNCTIONS
1738 
1739 
1740 // ===========================================================
1741 // HANDLE POOL FACET
1742 // ===========================================================
1743 
1744 // PUBLIC MEMBER FUNCTIONS
1745 
1749 {
1750  // Preconditions:
1751 
1752  // Body:
1753 
1754  size_type result = handles().ct();
1755 
1756  // Postconditions:
1757 
1758  ensure(result >= 0);
1759 
1760  // Exit:
1761 
1762  return result;
1763 }
1764 
1768 {
1769  // Preconditions:
1770 
1771  // Body:
1772 
1773  size_type result = sheaf::deep_size(handles(), true);
1774 
1775  // Postconditions:
1776 
1777  ensure(result >= 0);
1778 
1779  // Exit:
1780 
1781  return result;
1782 }
1783 
1787 {
1788  // Preconditions:
1789 
1790  // Body:
1791 
1792  hub_index_space_handle& result = handles().get();
1793  attach(result);
1794 
1795  // Postconditions:
1796 
1797  ensure(result.is_attached());
1798 
1799  // Exit:
1800 
1801  return result;
1802 }
1803 
1804 void
1807 {
1808  // Preconditions:
1809 
1810  require(allocated_id_space(xid_space));
1811 
1812  // Body:
1813 
1814  // Detach the handle.
1815 
1816  xid_space.detach();
1817 
1818  // Release the handle to the pool.
1819 
1820  handles().release(reinterpret_cast<hub_index_space_handle&>(xid_space));
1821 
1822  // Postconditions:
1823 
1824  ensure(is_basic_query);
1825 
1826  // Exit:
1827 
1828  return;
1829 }
1830 
1831 bool
1834 {
1835  // Preconditions:
1836 
1837  // Body:
1838 
1839  const hub_index_space_handle* lid_space =
1840  dynamic_cast<const hub_index_space_handle*>(&xid_space);
1841 
1842  bool result = (lid_space != 0) && handles().allocated(*lid_space);
1843 
1844  // Postconditions:
1845 
1846  ensure(is_basic_query);
1847 
1848  // Exit:
1849 
1850  return result;
1851 }
1852 
1853 // PROTECTED MEMBER FUNCTIONS
1854 
1855 // PRIVATE MEMBER FUNCTIONS
1856 
1858 sheaf::primary_sum_index_space_state::
1859 handles()
1860 {
1861  // Preconditions:
1862 
1863  // Body:
1864 
1865  static list_pool<hub_index_space_handle> result;
1866 
1867  // Postconditions:
1868 
1869  ensure(is_basic_query);
1870 
1871  // Exit:
1872 
1873  return result;
1874 }
1875 
1876 
1877 // ===========================================================
1878 // ITERATOR POOL FACET
1879 // ===========================================================
1880 
1881 // PUBLIC MEMBER FUNCTIONS
1882 
1886 {
1887  // Preconditions:
1888 
1889  // Body:
1890 
1891  size_type result = iterators().ct();
1892 
1893  // Postconditions:
1894 
1895  ensure(result >= 0);
1896 
1897  // Exit:
1898 
1899  return result;
1900 }
1901 
1905 {
1906  // Preconditions:
1907 
1908  // Body:
1909 
1910  size_type result = sheaf::deep_size(iterators(), true);
1911 
1912  // Postconditions:
1913 
1914  ensure(result >= 0);
1915 
1916  // Exit:
1917 
1918  return result;
1919 }
1920 
1924 {
1925  // Preconditions:
1926 
1927  // Body:
1928 
1929  hub_index_space_iterator& result = iterators().get();
1930  attach(result);
1931 
1932  // Postconditions:
1933 
1934  ensure(result.is_attached());
1935 
1936  // Exit:
1937 
1938  return result;
1939 }
1940 
1941 void
1944 {
1945  // Preconditions:
1946 
1947  require(allocated_iterator(xitr));
1948 
1949  // Body:
1950 
1951  // Detach the iterator.
1952 
1953  xitr.detach();
1954 
1955  // Release the iterator to the pool.
1956 
1957  iterators().release(reinterpret_cast<hub_index_space_iterator&>(xitr));
1958 
1959  // Postconditions:
1960 
1961  ensure(is_basic_query);
1962 
1963  // Exit:
1964 
1965  return;
1966 }
1967 
1968 bool
1971 {
1972  // Preconditions:
1973 
1974  // Body:
1975 
1976  const hub_index_space_iterator* litr =
1977  dynamic_cast<const hub_index_space_iterator*>(&xitr);
1978 
1979  bool result = (litr != 0) && iterators().allocated(*litr);
1980 
1981  // Postconditions:
1982 
1983  ensure(is_basic_query);
1984 
1985  // Exit:
1986 
1987  return result;
1988 }
1989 
1990 // PROTECTED MEMBER FUNCTIONS
1991 
1992 // PRIVATE MEMBER FUNCTIONS
1993 
1995 sheaf::primary_sum_index_space_state::
1996 iterators()
1997 {
1998  // Preconditions:
1999 
2000  // Body:
2001 
2003 
2004  // Postconditions:
2005 
2006  ensure(is_basic_query);
2007 
2008  // Exit:
2009 
2010  return result;
2011 }
2012 
2013 
2014 // ===========================================================
2015 // FACTORY FACET
2016 // ===========================================================
2017 
2018 // PUBLIC MEMBER FUNCTIONS
2019 
2020 const std::string&
2022 class_name() const
2023 {
2024  static const std::string result("primary_sum_index_space_state");
2025  return result;
2026 }
2027 
2030 clone() const
2031 {
2032  // Preconditions:
2033 
2034  // Body:
2035 
2038 
2039  // Postconditions:
2040 
2041  ensure(result != 0);
2042  ensure(is_same_type(result));
2043 
2044  // Exit:
2045 
2046  return result;
2047 }
2048 
2049 // PROTECTED MEMBER FUNCTIONS
2050 
2051 // PRIVATE MEMBER FUNCTIONS
2052 
2053 bool
2054 sheaf::primary_sum_index_space_state::
2055 make_prototype()
2056 {
2057  // Preconditions:
2058 
2059  // Body:
2060 
2062 
2063  id_space_factory().insert_prototype(lproto);
2064 
2065  // Postconditions:
2066 
2067  // Exit:
2068 
2069  return true;
2070 }
2071 
2072 
2073 // ===========================================================
2074 // ANY FACET
2075 // ===========================================================
2076 
2077 // PUBLIC MEMBER FUNCTIONS
2078 
2079 bool
2081 is_ancestor_of(const any *other) const
2082 {
2083 
2084  // Preconditions:
2085 
2086  require(other != 0);
2087 
2088  // Body:
2089 
2090  // True if other conforms to this
2091 
2092  bool result = dynamic_cast<const primary_sum_index_space_state*>(other) != 0;
2093 
2094  // Postconditions:
2095 
2096  // Exit:
2097 
2098  return result;
2099 }
2100 
2101 bool
2103 invariant() const
2104 {
2105  bool result = true;
2106 
2107  if(invariant_check())
2108  {
2109  // Prevent recursive calls to invariant
2110 
2112 
2113  // Must satisfy base class invariant
2114 
2115  invariance(sum_index_space_state::invariant());
2116 
2117  // Invariances for this class:
2118 
2119  // Finished, turn invariant checking back on.
2120 
2122  }
2123 
2124  // Exit
2125 
2126  return result;
2127 }
2128 
2129 // PROTECTED MEMBER FUNCTIONS
2130 
2131 // PRIVATE MEMBER FUNCTIONS
2132 
2133 
2134 // ===========================================================
2135 // NON-MEMBER FUNCTIONS
2136 // ===========================================================
2137 
2138 size_t
2139 sheaf::
2140 deep_size(const primary_sum_index_space_state& xn, bool xinclude_shallow)
2141 {
2142  // Preconditions:
2143 
2144  // Body:
2145 
2146  size_t result = xinclude_shallow ? sizeof(xn) : 0;
2147 
2148  // Add any contributions from the parent class.
2149 
2150  const sum_index_space_state& ixn = static_cast<const sum_index_space_state&>(xn);
2151  result += deep_size(ixn, false);
2152 
2153  // Add the memory allocated in member _rem.
2154 
2156  result += deep_size<pod_index_type, pod_index_type, rem_policy_type>(xn._rem, false);
2157 
2158  // Add the memory allocated in member _members.
2159 
2160  result += deep_size(xn._members, false);
2161 
2162  // Postconditions:
2163 
2164  ensure(result >= 0);
2165 
2166  // Exit
2167 
2168  return result;
2169 }
pod_type _term_id_end
Ending index of the terms in this sum.
std::string next_term_name()
Name of the next term id space.
const size_type RESERVED_TERM_SIZE
Size of reserved term in top id space.
Definition: sheaf.h:107
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...
bool contains_member(pod_type xmbr) const
True, if the integer xmbr is in this set.
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.
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() const
The number of members.
virtual index_space_handle & get_id_space() const
The id space handle with this state.
virtual void attach_to(pod_type xindex)
Attach to the state with index xindex in the id space family id_spaces().
virtual pod_type index() const
Index of this space.
void clear_ids()
Deallocate all non-standard ids.
void unglue_all(pod_type xrep_id)
Unglue all ids glued to representative xrep_id; makes each id in the equivalence class of xrep_id its...
static const std::string & term_prefix()
Prefix of the term id spaces.
const map_type & interval_map() const
Map that defines the intervals of this set.
bool is_empty() const
True if there are no ids in the space.
pod_type term_id(pod_type xid) const
The id of the term containing id xid.
void put_hub_term_id(pod_type xhub_term_id)
Sets hub_term_id() to xhub_term_id.
An abstract iterator over the ids of an id space.
rem_type _rem
The reflexive reduction of the rem map.
void release_id_space(index_space_handle &xid_space) const
Returns the id space handle xid_space to the handle pool.
static size_type iterator_pool_deep_size()
The deep size of the iterator pool.
pod_type _standard_id_end
The end id of the standard ids.
pod_type end() const
Ending id of this space.
pod_type next_id() const
The next available id.
virtual bool contains_glued_hub(pod_type xid) const
True if this space contains an id equivalent to xid in the glued hub id space.
pod_type new_id()
Allocate the next available id in this space. Returns the allocated id in the hub id space...
pod_type _term_id_begin
Beginning index of the terms in this sum.
void add_term(pod_type xterm_id, pod_type xbegin, pod_type xend)
Insert term with id xterm_id into the interval .
static hub_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname)
Create a new primary sum id space in the id space family xid_space at the next available id space ind...
bool reserved_interval_is_available(pod_type xid) const
True if the reserved interval for id xid is available for allocation.
bool is_valid_reserved_id(pod_type xid) const
True if and only if the reserved term containing xid is already a reserved term or is available for a...
virtual pod_type term_id_end() const
Ending index of the terms in this sum.
virtual bool is_persistent() const
True if this id space should be written to disk.
bool interval_is_empty(pod_type xbegin, pod_type xend) const
True if all ids in the interval [xbegin, xend) are not in this space.
index_space_handle & get_id_space(const std::string &xname) const
Allocates an id space handle from the handle pool attached to state with name xname.
virtual bool invariant() const
Class invariant.
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 ...
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 contains_rep(pod_type xhub_id) const
True if and only if hub id xhub_id is the representative member of its equivalence class...
virtual void release_iterator(index_space_iterator &xitr) const
Returns the id space iterator xitr to the iterator pool.
void force_item(index_type xindex, const_reference_type xitem)
Puts the item xitem at index xindex, resizing if necessary; any other new storage allocated is uninit...
STL namespace.
virtual void detach()=0
Detach this handle form its state, if any.
virtual bool operator==(const explicit_index_space_state &xother) const
True if this is equivalent to xother.
bool is_gathered() const
True if begin() == 0 and end() == ct().
void update_gathered_id_space()
Update the gathered id space.
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).
virtual pod_type term_id_begin() const
Beginning index of the terms in this sum.
bool interval_is_full(pod_type xbegin, pod_type xend) const
True if all ids in the interval [xbegin, xend) are in this space.
const index_space_family & id_spaces() const
The id space family for this (const version).
bool interval_is_empty(pod_type xbegin, pod_type xend) const
True, if there are no members in this set for the interval [xbegin, xend].
block< pod_type > _term_end
The end of the interval in the sum id space for each term.
virtual bool operator==(const explicit_index_space_state &xother) const
True if this is equivalent to xother.
virtual void detach()=0
Detach this handle form its state, if any.
An implementation of class sum_index_space_handle that has a primary sum id space state...
const index_space_handle & term(pod_type xi) const
The xi-th term.
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.
An implementation of class explicit_index_space_handle that has a primary id space state...
interval_index_space_handle _gathered_id_space
The gathered id space.
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.
Abstract base class with useful features for all objects.
Definition: any.h:39
bool is_next_id_available() const
True if and only if the next id is available for allocation.
static size_type iterator_pool_ct()
The number of iterators in the pool.
bool interval_is_available(pod_type xbegin, pod_type xend) const
True if the ids in the interval [xbegin, xend) are available in this space.
pod_type new_primary_term(size_type xct)
Create a new primary term [next_id(), next_id()+xct). Returns the index of the term created...
const index_space_handle & new_gathered_id_space(bool xexclude_bottom)
Construct a gathered id space from this id space. If xexclude_bottom, construct the id space without ...
interval_set _members
Set of members in the domain of this map.
virtual const std::string & class_name() const
The name of this class.
An immutable abstract state for a space of alternate integer identifiers (aliases) for a subset of th...
void glue(pod_type xid, pod_type xrep)
Glues xid to xrep; adds xid to the equivalence class with representative member xrep.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
void extend_last_term(size_type xct)
Extends the last term to ct() == xct.
void delete_id(pod_type xid)
Deallocate the id xid in this space.
void unglue(pod_type xid)
Unglues xid; makes xid its own representative.
std::string name() const
Name of this space.
Do not call deep_size on either the key or value.
Definition: deep_size.h:54
static primary_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname, pod_type xoffset, size_type xct)
Create a new primary id space in the id space family xid_space at the next available id space index w...
bool gathered_id_space_excludes_bottom() const
True, if the gathered id space excludes BOTTOM_INDEX.
virtual bool is_attached() const
True if this handle is attached to a state.
An abstract id space of alternate integer identifiers which is the sum (disjoint union) of two or mor...
const index_space_handle & term_of(pod_type xid) const
The term containing id xid.
void invalidate_extrema()
Invalidate the extrema.
pod_type begin() const
The first member in this set.
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.
terms_type _terms
The terms of this sum.
static reserved_primary_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname, pod_type xoffset, size_type xct)
Create a new reserved primary id space in the id space family xid_space at the next available id spac...
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
bool interval_is_full(pod_type xbegin, pod_type xend) const
True, if there is a continuous interval of members [xbegin, xend] in this set.
virtual pod_type host_rep(pod_type xhub_id) const
The host id associated with the representative member of the equivalence class of hub id xhub_id...
static std::string reserved_prefix()
Prefix for identifying member names reserved by the sheaf system.
Definition: poset_path.cc:883
const index_space_handle & last_term() const
The last term.
bool is_explicit_interval(pod_type xid)
True, if and only if the id space interval that contains index xid is an explicit interval...
virtual primary_sum_index_space_state & operator=(const explicit_index_space_state &xother)
Assignment operator.
virtual pod_type rep(pod_type xhub_id) const
The representative member of the equivalence class of hub id xhub_id.
bool has_only_standard_ids() const
True if and only if there are only standard ids.
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...
pod_type term_end(pod_type xi) const
Ending id of the xi-th term.
reserved_primary_index_space_handle _reserved_term
The current reserved term.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
virtual pod_type glued_hub_pod(pod_type xid) const
The pod index in the glued primary sum id space equivalent to xid in this id space.
size_type member_ct(pod_type xbegin, pod_type xend) const
The number of members in the interval [xbegin, xend].
pod_type new_id()
Allocate the next available id in this space.
pod_type end() const
The last member in this set.
static size_type handle_pool_deep_size()
The deep size of the handle pool.
size_type _ct
The number of members.
bool contains_unique_rep(pod_type xhub_id) const
True if and only if hub id xhub_id is the only member of its equivalence class.
void insert_interval(pod_type xbegin, pod_type xend)
Insert an interval of members [xbegin, xend] into this set.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
pod_index_type pod_type
The "plain old data" index type for this.
static const std::string & gathered_hub_id_space_name()
Name of the gathered id space.
bool has_gathered_id_space() const
True, if the gathered id space exists.
An implementation of class primary_index_space_handle that has a reserved primary id space state...
block< pod_type > _term_begin
The beginning of the interval in the sum id space for each term.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
void remove_term(pod_type xi)
Remove xi-th term of this sum.
sum_to_term_type _sum_to_term_map
The term id corresponding to each sum id.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
pod_type new_reserved_term()
Creates a new reserved term starting above next_hub_id(). Returns the index of the term created...
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...
void update_standard_ids()
Make end() the standard id end.
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.
void clear()
Clear this set.
virtual void clear()
Deletes all entries.
virtual size_type ct() const
The number of members.
virtual void release_id_space(index_space_handle &xid_space) const
Release the id space handle xid_space.
virtual bool invariant() const
Class invariant.
An implementation of class sum_index_space_state intended for use as the sum of the primary id spaces...
bool is_empty() const
True if there are no ids in the space.
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.
Factory and container for a family of id spaces.
An iterator over an id space which is the sum of the primary id spaces.
virtual primary_sum_index_space_state * clone() const
Virtual constructor; create a new instance of the same type at this.
pod_type offset() const
The offset into the hub id space.
static size_type handle_pool_ct()
The number of handles in the pool.
rem_inv_type _rem_inv
The inverse rem map.
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.
virtual bool contains_term_id(pod_type xi) const
True if this map contains the xi-th term.
const index_space_handle & gathered_id_space() const
The gathered id space.
bool has_gluing() const
Ture if there is any gluing.
pod_type _begin
Beginning id of this space.
void remove_interval(pod_type xbegin, pod_type xend)
Remove an interval of members [xbegin, xend] from this set.
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
Definition: pod_types.cc:31
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
virtual bool is_attached() const
True if this iterator is attached to a state.
void insert_member(pod_type xmbr)
Insert xmbr into this set.
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
virtual bool contains(pod_type xid) const
True if this space contains id xid.
map_type::const_iterator map_iterator_type
The type of the interval map iterator.
Definition: interval_set.h:203
friend SHEAF_DLL_SPEC size_t deep_size(const primary_sum_index_space_state &xn, bool xinclude_shallow)
The deep size of primary_sum_index_space_state& xn.
virtual index_space_iterator & get_iterator() const
Allocates an id space iterator from the iterator pool.
void remove_member(pod_type xmbr)
Remove xmbr from this set.
void extend(size_type xct)
Extend this id space to have ct() == xct.