This file is indexed.

/usr/include/deal.II/base/index_set.h is in libdeal.ii-dev 6.3.1-1.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
//---------------------------------------------------------------------------
//    $Id: index_set.h 21272 2010-06-22 21:58:56Z heister $
//    Version: $Name$
//
//    Copyright (C) 2009, 2010 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.
//
//---------------------------------------------------------------------------
#ifndef __deal2__index_set_h
#define __deal2__index_set_h

#include <base/config.h>
#include <base/exceptions.h>

#include <vector>
#include <algorithm>

#ifdef DEAL_II_USE_TRILINOS
#  include <Epetra_Map.h>
#endif

#if defined(DEAL_II_COMPILER_SUPPORTS_MPI) || defined(DEAL_II_USE_PETSC)
#include <mpi.h>
#else
typedef int MPI_Comm;
#define MPI_COMM_WORLD 0
#endif

DEAL_II_NAMESPACE_OPEN

/**
 * A class that represents a subset of indices among a larger set. For
 * example, it can be used to denote the set of degrees of freedom
 * within the range $[0,\text{dof\_handler.n\_dofs})$ that belongs to
 * a particular subdomain, or those among all degrees of freedom that
 * are stored on a particular processor in a distributed parallel
 * computation.
 *
 * This class can represent a collection of half-open ranges of
 * indices as well as individual elements. For practical purposes it
 * also stores the overall range these indices can assume. In other
 * words, you need to specify the size of the index space
 * $[0,\text{size})$ of which objects of this class are a subset.
 *
 * @author Wolfgang Bangerth, 2009
 */
class IndexSet
{
  public:
				     /**
				      * Default constructor.
				      */
    IndexSet ();

				     /**
				      * Constructor that also sets the
				      * overall size of the index
				      * range.
				      */
    IndexSet (const unsigned int size);

				     /**
				      * Set the maximal size of the
				      * indices upon which this object
				      * operates.
				      *
				      * This function can only be
				      * called if the index set does
				      * not yet contain any elements.
				      */
    void set_size (const unsigned int size);

				     /**
				      * Return the size of the index
				      * space of which this index set
				      * is a subset of.
				      */
    unsigned int size () const;

				     /**
				      * Add the half-open range
				      * $[\text{begin},\text{end})$ to
				      * the set of indices represented
				      * by this class.
				      */
    void add_range (const unsigned int begin,
		    const unsigned int end);

				     /**
				      * Add an individual index to the
				      * set of indices.
				      */
    void add_index (const unsigned int index);

				     /**
				      * Add a whole set of indices
				      * described by dereferencing
				      * every element of the the
				      * iterator range
				      * <code>[begin,end)</code>.
				      */
    template <typename ForwardIterator>
    void add_indices (const ForwardIterator &begin,
		      const ForwardIterator &end);

				     /**
				      * Return whether the specified
				      * index is an element of the
				      * index set.
				      */
    bool is_element (const unsigned int index) const;

				     /**
				      * Return whether the index set
				      * stored by this object defines
				      * a contiguous range. This is
				      * true also if no indices are
				      * stored at all.
				      */
    bool is_contiguous () const;

				     /**
				      * Return the number of elements
				      * stored in this index set.
				      */
    unsigned int n_elements () const;

				     /**
				      * Return the nth index stored in
				      * this index set. @p n obviously
				      * needs to be less than
				      * n_elements().
				      */
    unsigned int nth_index_in_set (const unsigned int n) const;

				     /**
				      * Return the how-manyth element
				      * of this set (counted in
				      * ascending order) @p n is. @p n
				      * needs to be less than the
				      * size(). This function throws
				      * an exception if the index @p n
				      * is not actually a member of
				      * this index set, i.e. if
				      * is_element(n) is false.
				      */
    unsigned int index_within_set (const unsigned int n) const;

				     /**
				      * Each index set can be
				      * represented as the union of a
				      * number of contiguous intervals
				      * of indices, where if necessary
				      * intervals may only consist of
				      * individual elements to
				      * represent isolated members of
				      * the index set.
				      *
				      * This function returns the
				      * minimal number of such
				      * intervals that are needed to
				      * represent the index set under
				      * consideration.
				      */
    unsigned int n_intervals () const;

				     /**
				      * Compress the internal
				      * representation by merging
				      * individual elements with
				      * contiguous ranges, etc. This
				      * function does not have any
				      * external effect.
				      */
    void compress () const;

				     /**
				      * Comparison for equality of
				      * index sets. This operation is
				      * only allowed if the size of
				      * the two sets is the same
				      * (though of course they do not
				      * have to have the same number
				      * of indices).
				      */
    bool operator == (const IndexSet &is) const;

				     /**
				      * Comparison for inequality of
				      * index sets. This operation is
				      * only allowed if the size of
				      * the two sets is the same
				      * (though of course they do not
				      * have to have the same number
				      * of indices).
				      */
    bool operator != (const IndexSet &is) const;

				     /**
				      * Return the intersection of the
				      * current index set and the
				      * argument given, i.e. a set of
				      * indices that are elements of
				      * both index sets. The two index
				      * sets must have the same size
				      * (though of course they do not
				      * have to have the same number
				      * of indices).
				      */
    IndexSet operator & (const IndexSet &is) const;

				     /**
				      * This command takes an interval
				      * <tt>[begin, end)</tt> and returns
				      * the intersection of the current
				      * index set with the interval, shifted
				      * to the range <tt>[0,
				      * end-begin)</tt>.
				      */
    IndexSet get_view (const unsigned int begin,
		       const unsigned int end) const;


				     /**
				      * Removes all elements contained in @p
				      * other from this set. In other words,
				      * if $x$ is the current object and $o$
				      * the argument, then we compute $x
				      * \leftarrow x \backslash o$.
				      */
    void subtract_set (const IndexSet & other);


				     /**
				      * Fills the given vector with all
				      * indices contained in this IndexSet.
				      */
    void fill_index_vector(std::vector<unsigned int> & indices) const;


				     /**
				      * Outputs a text representation of this
				      * IndexSet to the given stream. Used for
				      * testing.
				      */
    template <class STREAM>
    void print(STREAM &out) const;

				     /**
				      * Writes the IndexSet into a text based
				      * file format, that can be read in again
				      * using the read() function.
				      */
    void write(std::ostream & out) const;

				     /**
				      * Constructs the IndexSet from a text
				      * based representation given by the
				      * stream @param in written by the
				      * write() function.
				      */
    void read(std::istream & in);
    
    
#ifdef DEAL_II_USE_TRILINOS
				     /**
				      * Given an MPI communicator,
				      * create a Trilinos map object
				      * that represents a distribution
				      * of vector elements or matrix
				      * rows in which we will locally
				      * store those elements or rows
				      * for which we store the index
				      * in the current index set, and
				      * all the other elements/rows
				      * elsewhere on one of the other
				      * MPI processes.
				      *
				      * The last argument only plays a
				      * role if the communicator is a
				      * parallel one, distributing
				      * computations across multiple
				      * processors. In that case, if
				      * the last argument is false,
				      * then it is assumed that the
				      * index sets this function is
				      * called on on all processors
				      * are mutually exclusive but
				      * together enumerate each index
				      * exactly once. In other words,
				      * if you call this function on
				      * two processors, then the index
				      * sets this function is called
				      * with must together have all
				      * possible indices from zero to
				      * size()-1, and no index must
				      * appear in both index
				      * sets. This corresponds, for
				      * example, to the case where we
				      * want to split the elements of
				      * vectors into unique subsets to
				      * be stored on different
				      * processors -- no element
				      * should be owned by more than
				      * one processor, but each
				      * element must be owned by one.
				      *
				      * On the other hand, if the
				      * second argument is true, then
				      * the index sets can be
				      * overlapping, though they still
				      * need to contain each index
				      * exactly once on all processors
				      * taken together. This is a
				      * useful operation if we want to
				      * create vectors that not only
				      * contain the locally owned
				      * indices, but for example also
				      * the elements that correspond
				      * to degrees of freedom located
				      * on ghost cells.
				      */
    Epetra_Map make_trilinos_map (const MPI_Comm &communicator = MPI_COMM_WORLD,
				  const bool      overlapping  = false) const;
#endif

    
				     /**
                                      * Determine an estimate for the memory
                                      * consumption (in bytes) of this
                                      * object.
				      */
    unsigned int memory_consumption () const;

  private:
				     /**
				      * A type that denotes the half
				      * open index range
				      * <code>[begin,end)</code>.
				      *
				      * The nth_index_in_set denotes
				      * the how many-th index within
				      * this IndexSet the first
				      * element of the current range
				      * is. This information is only
				      * accurate if
				      * IndexSet::compress() has been
				      * called after the last
				      * insertion.
				      */
    struct Range
    {
	unsigned int begin;
	unsigned int end;

	unsigned int nth_index_in_set;

	Range (const unsigned int i1,
	       const unsigned int i2);

	friend
	inline bool operator< (const Range &range_1,
			       const Range &range_2)
	  {
	    return ((range_1.begin < range_2.begin)
		    ||
		    ((range_1.begin == range_2.begin)
		     &&
		     (range_1.end < range_2.end)));
	  }

	static bool end_compare(const IndexSet::Range & x, const IndexSet::Range & y)
	  {
	    return x.end < y.end;
	  }

	friend
	inline bool operator== (const Range &range_1,
				const Range &range_2)
	  {
	    return ((range_1.begin == range_2.begin)
		    ||
		    (range_1.begin == range_2.begin));
	  }

	unsigned int memory_consumption () const
	  {
	    return sizeof(Range);
	  }
	
    };

				     /**
				      * A set of contiguous ranges of
				      * indices that make up (part of)
				      * this index set. This variable
				      * is always kept sorted.
				      *
				      * The variable is marked
				      * "mutable" so that it can be
				      * changed by compress(), though
				      * this of course doesn't change
				      * anything about the external
				      * representation of this index
				      * set.
				      */
    mutable std::vector<Range> ranges;

				     /**
				      * True if compress() has been
				      * called after the last change
				      * in the set of indices.
				      *
				      * The variable is marked
				      * "mutable" so that it can be
				      * changed by compress(), though
				      * this of course doesn't change
				      * anything about the external
				      * representation of this index
				      * set.
				      */
    mutable bool is_compressed;

				     /**
				      * The overall size of the index
				      * range. Elements of this index
				      * set have to have a smaller
				      * number than this value.
				      */
    unsigned int index_space_size;

				     /**
				      * Actually perform the compress()
				      * operation.
				      */
    void do_compress() const;
};


/* ------------------ inline functions ------------------ */

inline
IndexSet::Range::Range (const unsigned int i1,
			const unsigned int i2)
		:
		begin(i1),
		end(i2)
{}



inline
IndexSet::IndexSet ()
		:
		is_compressed (true),
		index_space_size (0)
{}



inline
IndexSet::IndexSet (const unsigned int size)
		:
		is_compressed (true),
		index_space_size (size)
{}



inline
void
IndexSet::set_size (const unsigned int sz)
{
  Assert (ranges.empty(),
	  ExcMessage ("This function can only be called if the current "
		      "object does not yet contain any elements."));
  index_space_size = sz;
  is_compressed = true;
}



inline
unsigned int
IndexSet::size () const
{
  return index_space_size;
}



inline
void
IndexSet::compress () const
{
  if (is_compressed == true)
    return;

  do_compress();
}



inline
void
IndexSet::add_range (const unsigned int begin,
		     const unsigned int end)
{
  Assert (begin < index_space_size,
	  ExcIndexRange (begin, 0, index_space_size));
  Assert (end <= index_space_size,
	  ExcIndexRange (end, 0, index_space_size+1));
  Assert (begin <= end,
	  ExcIndexRange (begin, 0, end));

  if (begin != end)
    {
      const Range new_range(begin,end);
      ranges.insert (std::lower_bound (ranges.begin(),
				       ranges.end(),
				       new_range),
		     new_range);
      is_compressed = false;
    }
}



inline
void
IndexSet::add_index (const unsigned int index)
{
  Assert (index < index_space_size,
	  ExcIndexRange (index, 0, index_space_size));

  const Range new_range(index, index+1);
  ranges.insert (std::lower_bound (ranges.begin(),
				   ranges.end(),
				   new_range),
		 new_range);
  is_compressed = false;
}



template <typename ForwardIterator>
inline
void
IndexSet::add_indices (const ForwardIterator &begin,
		       const ForwardIterator &end)
{
				   // insert each element of the
				   // range. if some of them happen to
				   // be consecutive, merge them to a
				   // range
  for (ForwardIterator p=begin; p!=end;)
    {
      const unsigned int begin_index = *p;
      unsigned int       end_index   = begin_index + 1;
      ForwardIterator q = p;
      ++q;
      while ((q != end) && (*q == end_index))
	{
	  ++end_index;
	  ++q;
	}

      add_range (begin_index, end_index);
      p = q;
    }
}



inline
bool
IndexSet::is_element (const unsigned int index) const
{
  if (ranges.empty() == false)
    {
      compress ();

				       // get the element after which
				       // we would have to insert a
				       // range that consists of all
				       // elements from this element
				       // to the end of the index
				       // range plus one. after this
				       // call we know that if
				       // p!=end() then
				       // p->begin<=index unless there
				       // is no such range at all
				       //
				       // if the searched for element
				       // is an element of this range,
				       // then we're done. otherwise,
				       // the element can't be in one
				       // of the following ranges
				       // because otherwise p would be
				       // a different iterator
      std::vector<Range>::const_iterator
	p = std::upper_bound (ranges.begin(),
			      ranges.end(),
			      Range (index, size()+1));

      if (p == ranges.begin())
	return ((index >= p->begin) && (index < p->end));

      Assert ((p == ranges.end()) || (p->begin > index),
		ExcInternalError());

				       // now move to that previous
				       // range
      --p;
      Assert (p->begin <= index, ExcInternalError());

      return (p->end > index);
    }

				   // didn't find this index, so it's
				   // not in the set
  return false;
}



inline
bool
IndexSet::is_contiguous () const
{
  compress ();
  return (ranges.size() <= 1);
}



inline
unsigned int
IndexSet::n_elements () const
{
				   // make sure we have
				   // non-overlapping ranges
  compress ();

  unsigned int s = 0;
  for (std::vector<Range>::iterator range = ranges.begin();
       range != ranges.end();
       ++range)
    s += (range->end - range->begin);

  return s;
}



inline
unsigned int
IndexSet::nth_index_in_set (const unsigned int n) const
{
  Assert (n < n_elements(), ExcIndexRange (n, 0, n_elements()));

//TODO: this could be done more efficiently by using a binary search
  for (std::vector<Range>::const_iterator p = ranges.begin();
       p != ranges.end(); ++p)
    {
      Assert (n >= p->nth_index_in_set, ExcInternalError());
      if (n < p->nth_index_in_set + (p->end-p->begin))
	return p->begin + (n-p->nth_index_in_set);
    }

  Assert (false, ExcInternalError());
  return numbers::invalid_unsigned_int;
}



inline
unsigned int
IndexSet::index_within_set (const unsigned int n) const
{
  Assert (is_element(n) == true,
	  ExcMessage ("Given number is not an element of this set."));
  Assert (n < size(), ExcIndexRange (n, 0, size()));

  Range r(n, n);

  std::vector<Range>::const_iterator p = std::lower_bound(ranges.begin(),
							  ranges.end(),
							  r,
							  Range::end_compare);

  Assert(p!=ranges.end(), ExcInternalError());
  Assert(p->begin<=n, ExcInternalError());
  Assert(n<p->end, ExcInternalError());
  return (n-p->begin) + p->nth_index_in_set;
}



inline
bool
IndexSet::operator == (const IndexSet &is) const
{
  Assert (size() == is.size(),
	  ExcDimensionMismatch (size(), is.size()));

  compress ();
  is.compress ();

  return ranges == is.ranges;
}



inline
bool
IndexSet::operator != (const IndexSet &is) const
{
  Assert (size() == is.size(),
	  ExcDimensionMismatch (size(), is.size()));

  compress ();
  is.compress ();

  return ranges != is.ranges;
}

template <class STREAM>
inline
void
IndexSet::print (STREAM &out) const
{
  compress();
  out << "{";
  std::vector<Range>::const_iterator p;
  for (p = ranges.begin(); p != ranges.end(); ++p)
    {
      if (p->end-p->begin==1)
	out << p->begin;
      else
	out << "[" << p->begin << "," << p->end-1 << "]";

      if (p !=--ranges.end())
	out << ", ";
    }
  out << "}" << std::endl;
}


DEAL_II_NAMESPACE_CLOSE

#endif