This file is indexed.

/usr/include/gecode/int/element/view.hpp is in libgecode-dev 3.7.1-3.

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
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
 *  Main authors:
 *     Christian Schulte <schulte@gecode.org>
 *
 *  Contributing authors:
 *     Guido Tack <tack@gecode.org>
 *
 *  Copyright:
 *     Christian Schulte, 2004
 *     Guido Tack, 2004
 *
 *  Last modified:
 *     $Date: 2011-08-08 18:04:53 +0200 (Mon, 08 Aug 2011) $ by $Author: schulte $
 *     $Revision: 12253 $
 *
 *  This file is part of Gecode, the generic constraint
 *  development environment:
 *     http://www.gecode.org
 *
 *  Permission is hereby granted, free of charge, to any person obtaining
 *  a copy of this software and associated documentation files (the
 *  "Software"), to deal in the Software without restriction, including
 *  without limitation the rights to use, copy, modify, merge, publish,
 *  distribute, sublicense, and/or sell copies of the Software, and to
 *  permit persons to whom the Software is furnished to do so, subject to
 *  the following conditions:
 *
 *  The above copyright notice and this permission notice shall be
 *  included in all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

#include <algorithm>

namespace Gecode { namespace Int { namespace Element {

  /// VarArg type for integer views
  template<>
  class ViewToVarArg<IntView> {
  public:
    typedef IntVarArgs argtype;
  };
  /// VarArg type for Boolean views
  template<>
  class ViewToVarArg<BoolView> {
  public:
    typedef BoolVarArgs argtype;
  };

  /**
   * \brief Class for pair of index and view
   *
   */
  template<class View>
  class IdxView {
  public:
    int idx; View view;

    static IdxView* allocate(Space&, int);
  };

  template<class View>
  forceinline IdxView<View>*
  IdxView<View>::allocate(Space& home, int n) {
    return home.alloc<IdxView<View> >(n);
  }

  template<class View>
  IdxViewArray<View>::IdxViewArray(void) : xs(NULL), n(0) {}

  template<class View>
  IdxViewArray<View>::IdxViewArray(const IdxViewArray<View>& a) {
    n = a.n; xs = a.xs;
  }

  template<class View>
  IdxViewArray<View>::IdxViewArray(Space& home,
    const typename ViewToVarArg<View>::argtype& xa) : xs(NULL) {
    n = xa.size();
    if (n>0) {
      xs = IdxView<View>::allocate(home, n);
      for (int i = n; i--; ) {
        xs[i].idx = i; xs[i].view = xa[i];
      }
    }
  }

  template<class View>
  IdxViewArray<View>::IdxViewArray(Space& home, int n0) : xs(NULL) {
    n = n0;
    if (n>0) {
      xs = IdxView<View>::allocate(home, n);
    }
  }

  template<class View>
  forceinline int
  IdxViewArray<View>::size(void) const {
    return n;
  }

  template<class View>
  forceinline void
  IdxViewArray<View>::size(int n0) {
    n = n0;
  }

  template<class View>
  forceinline IdxView<View>&
  IdxViewArray<View>::operator [](int i) {
    assert((i >= 0) && (i < size()));
    return xs[i];
  }

  template<class View>
  forceinline const IdxView<View>&
  IdxViewArray<View>::operator [](int i) const {
    assert((i >= 0) && (i < size()));
    return xs[i];
  }

  template<class View>
  void
  IdxViewArray<View>::subscribe(Space& home, Propagator& p, PropCond pc,
                                bool process) {
    for (int i = n; i--; )
      xs[i].view.subscribe(home,p,pc,process);
  }

  template<class View>
  void
  IdxViewArray<View>::cancel(Space& home, Propagator& p, PropCond pc) {
    for (int i = n; i--; )
      xs[i].view.cancel(home,p,pc);
  }

  template<class View>
  void
  IdxViewArray<View>::update(Space& home, bool share, IdxViewArray<View>& a) {
    n = a.size();
    if (n>0) {
      xs = IdxView<View>::allocate(home,n);
      for (int i=n; i--; ) {
        xs[i].idx = a[i].idx;
        xs[i].view.update(home,share,a[i].view);
      }
    }
  }


  /**
   * \brief Class for bounds-equality test
   *
   */
  template<class VA, class VC>
  class RelTestBnd {
  public:
    RelTest operator ()(VA,VC);
  };
  /**
   * \brief Class for bounds-equality test (specialized)
   *
   */
  template<class VA>
  class RelTestBnd<VA,ConstIntView> {
  public:
    RelTest operator ()(VA,ConstIntView);
  };

  /**
   * \brief Class for domain-equality test
   *
   */
  template<class VA, class VC>
  class RelTestDom {
  public:
    RelTest operator ()(VA,VC);
  };
  /**
   * \brief Class for domain-equality test (specialized)
   *
   */
  template<class VA>
  class RelTestDom<VA,ConstIntView> {
  public:
    RelTest operator ()(VA,ConstIntView);
  };


  template<class VA, class VC>
  forceinline RelTest
  RelTestBnd<VA,VC>::operator ()(VA x, VC y) {
    return rtest_eq_bnd(x,y);
  }
  template<class VA>
  forceinline RelTest
  RelTestBnd<VA,ConstIntView>::operator ()(VA x, ConstIntView y) {
    return rtest_eq_bnd(x,y.val());
  }

  template<class VA, class VC>
  forceinline RelTest
  RelTestDom<VA,VC>::operator ()(VA x, VC y) {
    return rtest_eq_dom(x,y);
  }
  template<class VA>
  forceinline RelTest
  RelTestDom<VA,ConstIntView>::operator ()(VA x, ConstIntView y) {
    return rtest_eq_dom(x,y.val());
  }




  /*
   * Base class
   *
   */

  template<class VA, class VB, class VC, PropCond pc_ac>
  View<VA,VB,VC,pc_ac>::View(Home home, IdxViewArray<VA>& iv0,
                             VB y0, VC y1)
    : Propagator(home), iv(iv0), x0(y0), x1(y1) {
    x0.subscribe(home,*this,PC_INT_DOM);
    x1.subscribe(home,*this,pc_ac);
    iv.subscribe(home,*this,pc_ac);
  }

  template<class VA, class VB, class VC, PropCond pc_ac>
  forceinline
  View<VA,VB,VC,pc_ac>::View(Space& home, bool share, View& p)
    : Propagator(home,share,p) {
    x0.update(home,share,p.x0);
    x1.update(home,share,p.x1);
    iv.update(home,share,p.iv);
  }

  template<class VA, class VB, class VC, PropCond pc_ac>
  PropCost
  View<VA,VB,VC,pc_ac>::cost(const Space&, const ModEventDelta&) const {
    // This is required for subscribing to variables in the
    // above constructor, but this is then the only time this
    // virtual function is ever used!
    return PropCost::linear(PropCost::LO,iv.size()+2);
  }

  template<class VA, class VB, class VC, PropCond pc_ac>
  forceinline size_t
  View<VA,VB,VC,pc_ac>::dispose(Space& home) {
    x0.cancel(home,*this,PC_INT_DOM);
    x1.cancel(home,*this,pc_ac);
    iv.cancel(home,*this,pc_ac);
    (void) Propagator::dispose(home);
    return sizeof(*this);
  }




  /**
   * \brief Value iterator for indices in index-view map
   *
   */
  template<class View>
  class IterIdxView {
  private:
    const IdxView<View> *cur, *end;
  public:
    IterIdxView(void);
    IterIdxView(const IdxView<View>*, const IdxView<View>*);
    void init(const IdxView<View>*, const IdxView<View>*);
    bool operator ()(void) const;
    void operator ++(void);
    int  val(void) const;
  };

  template<class View>
  forceinline
  IterIdxView<View>::IterIdxView(void) {}
  template<class View>
  forceinline
  IterIdxView<View>::IterIdxView(const IdxView<View>* b,
                                 const IdxView<View>* e)
    : cur(b), end(e) {}
  template<class View>
  forceinline void
  IterIdxView<View>::init(const IdxView<View>* b,
                          const IdxView<View>* e) {
    cur=b; end=e;
  }
  template<class View>
  forceinline bool
  IterIdxView<View>::operator ()(void) const {
    return cur < end;
  }
  template<class View>
  forceinline void
  IterIdxView<View>::operator ++(void) {
    cur++;
  }
  template<class View>
  forceinline int
  IterIdxView<View>::val(void) const {
    return cur->idx;
  }




  /*
   * Generic scanning: does all but computing new domain for result
   * (which is specific to bounds/domain version)
   *
   */

  template<class VA, class VB, class VC, PropCond pc_ac, class RelTest>
  ExecStatus
  scan(Space& home, IdxViewArray<VA>& iv,
       VB x0, VC x1, Propagator& p, RelTest rt) {
    assert(iv.size() > 1);
    /*
     * Prunes pairs of index, variable
     *  - checks for idx value removed
     *  - checks for disequal variables
     *
     */
    ViewValues<VB> vx0(x0);
    int i = 0;
    int j = 0;
    while (vx0() && (i < iv.size())) {
      if (iv[i].idx < vx0.val()) {
        iv[i].view.cancel(home,p,pc_ac);
        ++i;
      } else if (iv[i].idx > vx0.val()) {
        ++vx0;
      } else {
        assert(iv[i].idx == vx0.val());
        switch (rt(iv[i].view,x1)) {
        case RT_FALSE:
          iv[i].view.cancel(home,p,pc_ac);
          break;
        case RT_TRUE:
        case RT_MAYBE:
          iv[j++] = iv[i];
          break;
        default: GECODE_NEVER;
        }
        ++vx0; ++i;
      }
    }
    while (i < iv.size())
      iv[i++].view.cancel(home,p,pc_ac);
    bool adjust = (j<iv.size());
    iv.size(j);

    if (iv.size() == 0)
      return ES_FAILED;

    if (iv.size() == 1) {
      GECODE_ME_CHECK(x0.eq(home,iv[0].idx));
    } else if (adjust) {
      IterIdxView<VA> v(&iv[0],&iv[0]+iv.size());
      GECODE_ME_CHECK(x0.narrow_v(home,v,false));
      assert(x0.size() == static_cast<unsigned int>(iv.size()));
    }
    return ES_OK;
  }




  /*
   * Bounds consistent propagator
   *
   */

  template<class VA, class VB, class VC>
  forceinline
  ViewBnd<VA,VB,VC>::ViewBnd(Home home,
                             IdxViewArray<VA>& iv, VB x0, VC x1)
    : View<VA,VB,VC,PC_INT_BND>(home,iv,x0,x1) {}

  template<class VA, class VB, class VC>
  ExecStatus
  ViewBnd<VA,VB,VC>::post(Home home,
                          IdxViewArray<VA>& iv, VB x0, VC x1) {
    GECODE_ME_CHECK(x0.gq(home,0));
    GECODE_ME_CHECK(x0.le(home,iv.size()));
    if (x0.assigned()) {
      (void) new (home) Rel::EqBnd<VA,VC>(home,iv[x0.val()].view,x1);
      return ES_OK;
    } else {
      assert(iv.size()>1);
      (void) new (home) ViewBnd<VA,VB,VC>(home,iv,x0,x1);
    }
    return ES_OK;
  }


  template<class VA, class VB, class VC>
  forceinline
  ViewBnd<VA,VB,VC>::ViewBnd(Space& home, bool share, ViewBnd& p)
    : View<VA,VB,VC,PC_INT_BND>(home,share,p) {}

  template<class VA, class VB, class VC>
  Actor*
  ViewBnd<VA,VB,VC>::copy(Space& home, bool share) {
    return new (home) ViewBnd<VA,VB,VC>(home,share,*this);
  }

  template<class VA, class VB, class VC>
  ExecStatus
  ViewBnd<VA,VB,VC>::propagate(Space& home, const ModEventDelta&) {
    assert(iv.size() > 1);
    RelTestBnd<VA,VC> rt;
    GECODE_ES_CHECK((scan<VA,VB,VC,PC_INT_BND,RelTestBnd<VA,VC> >
                     (home,iv,x0,x1,*this,rt)));
    if (iv.size() == 1) {
      ExecStatus es = home.ES_SUBSUMED(*this);
      (void) new (home) Rel::EqBnd<VA,VC>(home,iv[0].view,x1);
      return es;
    }
    assert(iv.size() > 1);
    // Compute new result
    int min = iv[iv.size()-1].view.min();
    int max = iv[iv.size()-1].view.max();
    for (int i=iv.size()-1; i--; ) {
      min = std::min(iv[i].view.min(),min);
      max = std::max(iv[i].view.max(),max);
    }
    ExecStatus es = shared(x0,x1) ? ES_NOFIX : ES_FIX;
    {
     ModEvent me = x1.lq(home,max);
     if (me_failed(me))
       return ES_FAILED;
     if (me_modified(me) && (x1.max() != max))
       es = ES_NOFIX;
    }
    {
     ModEvent me = x1.gq(home,min);
     if (me_failed(me))
       return ES_FAILED;
     if (me_modified(me) && (x1.min() != min))
       es = ES_NOFIX;
    }
    return (x1.assigned() && (min == max)) ?
      home.ES_SUBSUMED(*this) : es;
  }





  /*
   * Domain consistent propagator
   *
   */

  template<class VA, class VB, class VC>
  forceinline
  ViewDom<VA,VB,VC>::ViewDom(Home home,
                             IdxViewArray<VA>& iv, VB x0, VC x1)
    : View<VA,VB,VC,PC_INT_DOM>(home,iv,x0,x1) {}

  template<class VA, class VB, class VC>
  ExecStatus
  ViewDom<VA,VB,VC>::post(Home home,
                          IdxViewArray<VA>& iv, VB x0, VC x1){
    GECODE_ME_CHECK(x0.gq(home,0));
    GECODE_ME_CHECK(x0.le(home,iv.size()));
    if (x0.assigned()) {
      (void) new (home) Rel::EqDom<VA,VC>(home,iv[x0.val()].view,x1);
      return ES_OK;
    } else {
      assert(iv.size()>1);
      (void) new (home) ViewDom<VA,VB,VC>(home,iv,x0,x1);
    }
    return ES_OK;
  }


  template<class VA, class VB, class VC>
  forceinline
  ViewDom<VA,VB,VC>::ViewDom(Space& home, bool share, ViewDom& p)
    : View<VA,VB,VC,PC_INT_DOM>(home,share,p) {}

  template<class VA, class VB, class VC>
  Actor*
  ViewDom<VA,VB,VC>::copy(Space& home, bool share) {
    return new (home) ViewDom<VA,VB,VC>(home,share,*this);
  }


  template<class VA, class VB, class VC>
  PropCost
  ViewDom<VA,VB,VC>::cost(const Space&, const ModEventDelta& med) const {
    return PropCost::linear((VA::me(med) != ME_INT_DOM) ?
                            PropCost::LO : PropCost::HI, iv.size()+2);
  }

  template<class VA, class VB, class VC>
  ExecStatus
  ViewDom<VA,VB,VC>::propagate(Space& home, const ModEventDelta& med) {
    assert(iv.size() > 1);
    if (VA::me(med) != ME_INT_DOM) {
      RelTestBnd<VA,VC> rt;
      GECODE_ES_CHECK((scan<VA,VB,VC,PC_INT_DOM,RelTestBnd<VA,VC> >
                       (home,iv,x0,x1,*this,rt)));
      if (iv.size() == 1) {
        ExecStatus es = home.ES_SUBSUMED(*this);
        (void) new (home) Rel::EqDom<VA,VC>(home,iv[0].view,x1);
        return es;
      }
      // Compute new result
      int min = iv[iv.size()-1].view.min();
      int max = iv[iv.size()-1].view.max();
      for (int i=iv.size()-1; i--; ) {
        min = std::min(iv[i].view.min(),min);
        max = std::max(iv[i].view.max(),max);
      }
      GECODE_ME_CHECK(x1.lq(home,max));
      GECODE_ME_CHECK(x1.gq(home,min));
      return (x1.assigned() && (min == max)) ?
        home.ES_SUBSUMED(*this) :
        home.ES_NOFIX_PARTIAL(*this,VA::med(ME_INT_DOM));
    }
    RelTestDom<VA,VC> rt;
    GECODE_ES_CHECK((scan<VA,VB,VC,PC_INT_DOM,RelTestDom<VA,VC> >
                     (home,iv,x0,x1,*this,rt)));
    if (iv.size() == 1) {
      ExecStatus es = home.ES_SUBSUMED(*this);
      (void) new (home) Rel::EqDom<VA,VC>(home,iv[0].view,x1);
      return es;
    }
    assert(iv.size() > 1);
    Region r(home);
    ViewRanges<VA>* i_view = r.alloc<ViewRanges<VA> >(iv.size());
    for (int i = iv.size(); i--; )
      i_view[i].init(iv[i].view);
    Iter::Ranges::NaryUnion i_val(r, i_view, iv.size());
    ModEvent me = x1.inter_r(home,i_val);
    r.free<ViewRanges<VA> >(i_view,iv.size());
    GECODE_ME_CHECK(me);
    return (shared(x0,x1) || me_modified(me)) ? ES_NOFIX : ES_FIX;
  }

}}}

// STATISTICS: int-prop