Class: Array

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#all_false?Boolean

Returns:

  • (Boolean)


55
56
57
58
59
# File 'ext/just_all_the_same/just_all_the_same.c', line 55

static VALUE
all_false_p(VALUE ary)
{
  return all_same_p(ary, Qfalse);
}

#all_nil?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'ext/just_all_the_same/just_all_the_same.c', line 43

static VALUE
all_nil_p(VALUE ary)
{
  return all_same_p(ary, Qnil);
}

#all_same?(target) ⇒ Boolean

Returns:

  • (Boolean)


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
# File 'ext/just_all_the_same/just_all_the_same.c', line 6

static VALUE
all_same_p(VALUE ary, VALUE target)
{
  long size = RARRAY_LEN(ary);

  if (size == 0) return Qtrue;

  VALUE *forward_p = RARRAY_PTR(ary);

  if (forward_p[0] != target) return Qfalse;

  VALUE *backward_p;

  long s = size;      // size of foward_ary + backward_aray
  long v = size / 2;  // splitting index

  /* split algorithm */
  while (v >= SWITCH_TO_LINER / 2)
  {
    backward_p = forward_p + v;

    /* check last of array nil? if size is not odd? */
    if (s%2 && forward_p[s-1] != target) return Qfalse;

    /* check quick same back and fowerd */
    if (memcmp(forward_p, backward_p, sizeof(VALUE) * v)) return Qfalse;

    s = v;
    v /= 2;
  }

  /* liner algorithm */
  for (long i = 1; i < s; i++) if (forward_p[i] != target) return Qfalse;

  return Qtrue;
}

#all_true?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
# File 'ext/just_all_the_same/just_all_the_same.c', line 49

static VALUE
all_true_p(VALUE ary)
{
  return all_same_p(ary, Qtrue);
}