This file is indexed.

/usr/lib/R/site-library/dplyr/include/dplyr/Result/Rank.h is in r-cran-dplyr 0.7.4-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
#ifndef dplyr_Result_Rank_H
#define dplyr_Result_Rank_H

#include <tools/hash.h>

#include <dplyr/GroupedDataFrame.h>

#include <dplyr/comparisons.h>
#include <dplyr/visitor.h>

#include <dplyr/Order.h>

#include <dplyr/Result/Result.h>
#include <dplyr/Result/VectorSliceVisitor.h>

namespace dplyr {
namespace internal {

struct min_rank_increment {
  typedef IntegerVector OutputVector;
  typedef int scalar_type;

  template <typename Container>
  inline int post_increment(const Container& x, int) const {
    return x.size();
  }

  template <typename Container>
  inline int pre_increment(const Container&, int) const {
    return 0;
  }

  inline int start() const {
    return 1;
  }

};

struct dense_rank_increment {
  typedef IntegerVector OutputVector;
  typedef int scalar_type;

  template <typename Container>
  inline int post_increment(const Container&, int) const {
    return 1;
  }

  template <typename Container>
  inline int pre_increment(const Container&, int) const {
    return 0;
  }

  inline int start() const {
    return 1;
  }

};

struct percent_rank_increment {
  typedef NumericVector OutputVector;
  typedef double scalar_type;

  template <typename Container>
  inline double post_increment(const Container& x, int m) const {
    return (double)x.size() / (m - 1);
  }

  template <typename Container>
  inline double pre_increment(const Container&, int) const {
    return 0.0;
  }

  inline double start() const {
    return 0.0;
  }


};

struct cume_dist_increment {
  typedef NumericVector OutputVector;
  typedef double scalar_type;

  template <typename Container>
  inline double post_increment(const Container&, int) const {
    return 0.0;
  }

  template <typename Container>
  inline double pre_increment(const Container& x, int m) const {
    return (double)x.size() / m;
  }

  inline double start() const {
    return 0.0;
  }
};

}


template <int RTYPE, bool ascending = true>
class RankComparer {
  typedef comparisons<RTYPE> compare;

public:
  typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;

  inline bool operator()(STORAGE lhs, STORAGE rhs) const {
    return compare::is_less(lhs, rhs);
  }
};

template <int RTYPE>
class RankComparer<RTYPE, false> {
  typedef comparisons<RTYPE> compare;

public:
  typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;
  inline bool operator()(STORAGE lhs, STORAGE rhs) const {
    return compare::is_greater(lhs, rhs);
  }
};

template <int RTYPE>
class RankEqual {
  typedef comparisons<RTYPE> compare;

public:
  typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;

  inline bool operator()(STORAGE lhs, STORAGE rhs) const {
    return compare::equal_or_both_na(lhs, rhs);
  }
};

// powers both dense_rank and min_rank, see dplyr.cpp for how it is used
template <int RTYPE, typename Increment, bool ascending = true>
class Rank_Impl : public Result, public Increment {
public:
  typedef typename Increment::OutputVector OutputVector;
  typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;

  typedef VectorSliceVisitor<RTYPE> Slice;
  typedef RankComparer<RTYPE, ascending> Comparer;
  typedef RankEqual<RTYPE> Equal;

  typedef dplyr_hash_map<STORAGE, std::vector<int>, boost::hash<STORAGE>, Equal > Map;
  typedef std::map<STORAGE, const std::vector<int>*, Comparer> oMap;

  Rank_Impl(SEXP data_) : data(data_), map() {}

  virtual SEXP process(const GroupedDataFrame& gdf) {
    int ng = gdf.ngroups();
    int n  = gdf.nrows();
    if (n == 0) return IntegerVector(0);
    GroupedDataFrame::group_iterator git = gdf.group_begin();
    OutputVector out = no_init(n);
    for (int i = 0; i < ng; i++, ++git) {
      process_slice(out, *git);
    }
    return out;
  }

  virtual SEXP process(const RowwiseDataFrame& gdf) {
    return IntegerVector(gdf.nrows(), 1);
  }

  virtual SEXP process(const FullDataFrame& df) {
    int n = df.nrows();
    if (n == 0) return IntegerVector(0);
    OutputVector out = no_init(n);
    process_slice(out, df.get_index());
    return out;
  }

  virtual SEXP process(const SlicingIndex& index) {
    int n = index.size();
    if (n == 0) return IntegerVector(0);
    OutputVector out = no_init(n);
    process_slice(out, index);
    return out;
  }

private:

  void process_slice(OutputVector& out, const SlicingIndex& index) {
    map.clear();
    Slice slice(&data, index);
    int m = index.size();
    for (int j = 0; j < m; j++) {
      map[ slice[j] ].push_back(j);
    }
    STORAGE na = Rcpp::traits::get_na<RTYPE>();
    typename Map::const_iterator it = map.find(na);
    if (it != map.end()) {
      m -= it->second.size();
    }

    oMap ordered;

    it = map.begin();
    for (; it != map.end(); ++it) {
      ordered[it->first] = &it->second;
    }
    typename oMap::const_iterator oit = ordered.begin();
    typename Increment::scalar_type j = Increment::start();
    for (; oit != ordered.end(); ++oit) {
      STORAGE key = oit->first;
      const std::vector<int>& chunk = *oit->second;
      int n = chunk.size();
      j += Increment::pre_increment(chunk, m);
      if (Rcpp::traits::is_na<RTYPE>(key)) {
        typename Increment::scalar_type inc_na =
          Rcpp::traits::get_na< Rcpp::traits::r_sexptype_traits<typename Increment::scalar_type>::rtype >();
        for (int k = 0; k < n; k++) {
          out[ chunk[k] ] = inc_na;
        }
      } else {
        for (int k = 0; k < n; k++) {
          out[ chunk[k] ] = j;
        }
      }
      j += Increment::post_increment(chunk, m);
    }
  }


  Vector<RTYPE> data;
  Map map;
};

template <int RTYPE, bool ascending = true>
class RowNumber : public Result {
public:
  typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;

  typedef VectorSliceVisitor<RTYPE> Slice;
  typedef OrderVectorVisitorImpl<RTYPE, ascending, Slice> Visitor;
  typedef Compare_Single_OrderVisitor<Visitor> Comparer;

  RowNumber(SEXP data_) : data(data_) {}

  virtual SEXP process(const GroupedDataFrame& gdf) {
    std::vector<int> tmp(gdf.max_group_size());

    int ng = gdf.ngroups();
    int n  = gdf.nrows();
    if (n == 0) return IntegerVector(0);
    GroupedDataFrame::group_iterator git = gdf.group_begin();
    IntegerVector out(n);
    for (int i = 0; i < ng; i++, ++git) {
      const SlicingIndex& index = *git;

      // tmp <- 0:(m-1)
      int m = index.size();
      for (int j = 0; j < m; j++) tmp[j] = j;

      Slice slice(&data, index);
      // order( gdf.group(i) )
      Visitor visitor(slice);
      Comparer comparer(visitor);
      std::sort(tmp.begin(), tmp.begin() + m, comparer);
      int j = m - 1;
      for (; j >= 0; j--) {
        if (Rcpp::traits::is_na<RTYPE>(slice[ tmp[j] ])) {
          m--;
          out[ index[j] ] = NA_INTEGER;
        } else {
          break;
        }
      }
      for (; j >= 0; j--) {
        out[ index[j] ] = tmp[j] + 1;
      }
    }
    return out;

  }

  virtual SEXP process(const RowwiseDataFrame& gdf) {
    return IntegerVector(gdf.nrows(), 1);
  }

  virtual SEXP process(const FullDataFrame& df) {
    return process(df.get_index());
  }

  virtual SEXP process(const SlicingIndex& index) {
    int nrows = index.size();
    if (nrows == 0) return IntegerVector(0);
    IntegerVector x = seq(0, nrows - 1);
    Slice slice(&data, index);
    Visitor visitor(slice);
    std::sort(x.begin(), x.end(), Comparer(visitor));
    IntegerVector out = no_init(nrows);
    int j = nrows - 1;
    for (; j >= 0; j--) {
      if (Rcpp::traits::is_na<RTYPE>(slice[ x[j] ])) {
        out[ x[j] ] = NA_INTEGER;
      } else {
        break;
      }
    }
    for (; j >= 0; j--) {
      out[ x[j] ] = j + 1;
    }
    return out;
  }

private:
  Vector<RTYPE> data;
};

template <int RTYPE, bool ascending = true>
class Ntile : public Result {
public:
  typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;

  typedef VectorSliceVisitor<RTYPE> Slice;
  typedef OrderVectorVisitorImpl<RTYPE, ascending, Slice> Visitor;
  typedef Compare_Single_OrderVisitor<Visitor> Comparer;

  Ntile(SEXP data_, double ntiles_) : data(data_), ntiles(ntiles_) {}

  virtual SEXP process(const GroupedDataFrame& gdf) {
    std::vector<int> tmp(gdf.max_group_size());

    int ng = gdf.ngroups();
    int n  = gdf.nrows();
    if (n == 0) return IntegerVector(0);
    GroupedDataFrame::group_iterator git = gdf.group_begin();
    IntegerVector out(n);
    for (int i = 0; i < ng; i++, ++git) {
      const SlicingIndex& index = *git;

      // tmp <- 0:(m-1)
      int m = index.size();
      for (int j = 0; j < m; j++) tmp[j] = j;
      Slice slice(&data, index);

      // order( gdf.group(i) )
      Visitor visitor(slice);
      Comparer comparer(visitor);
      std::sort(tmp.begin(), tmp.begin() + m, comparer);
      int j = m - 1;
      for (; j >= 0; j--) {
        if (Rcpp::traits::is_na<RTYPE>(slice[tmp[j]])) {
          out[index[j]] = NA_INTEGER;
          m--;
        } else {
          break;
        }
      }
      for (; j >= 0; j--) {
        out[ index[j] ] = (int)floor((ntiles * tmp[j]) / m) + 1;
      }
    }
    return out;

  }

  virtual SEXP process(const RowwiseDataFrame& gdf) {
    return IntegerVector(gdf.nrows(), 1);
  }

  virtual SEXP process(const FullDataFrame& df) {
    return process(df.get_index());
  }

  virtual SEXP process(const SlicingIndex& index) {
    int nrows = index.size();
    if (nrows == 0) return IntegerVector(0);
    IntegerVector x = seq(0, nrows - 1);
    Slice slice(&data, index);
    Visitor visitor(slice);
    std::sort(x.begin(), x.end(), Comparer(visitor));
    IntegerVector out = no_init(nrows);
    int i = nrows - 1;
    for (; i >= 0; i--) {
      if (Rcpp::traits::is_na<RTYPE>(slice[x[i]])) {
        nrows--;
        out[x[i]] = NA_INTEGER;
      } else {
        break;
      }
    }

    for (; i >= 0; i--) {
      out[ x[i] ] = (int)floor(ntiles * i / nrows) + 1;
    }
    return out;
  }

private:
  Vector<RTYPE> data;
  double ntiles;
};

class RowNumber_0 : public Result {
public:

  virtual SEXP process(const GroupedDataFrame& gdf) {
    int n = gdf.nrows(), ng = gdf.ngroups();
    if (n == 0) return IntegerVector(0);

    IntegerVector res = no_init(n);
    GroupedDataFrame::group_iterator git = gdf.group_begin();
    for (int i = 0; i < ng; i++, ++git) {
      const SlicingIndex& index = *git;
      int m = index.size();
      for (int j = 0; j < m; j++) res[index[j]] = j + 1;
    }
    return res;
  }

  virtual SEXP process(const RowwiseDataFrame& gdf) {
    return IntegerVector(gdf.nrows(), 1);
  }

  virtual SEXP process(const FullDataFrame& df) {
    if (df.nrows() == 0) return IntegerVector(0);
    IntegerVector res = seq(1, df.nrows());
    return res;
  }

  virtual SEXP process(const SlicingIndex& index) {
    if (index.size() == 0) return IntegerVector(0);
    IntegerVector res = seq(1, index.size());
    return res;
  }

};

}

#include <dplyr/visitor_impl.h>

#endif