Class: JudyHash

Inherits:
Object
  • Object
show all
Defined in:
ext/judy_hash.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.newObject



45
46
47
48
49
# File 'ext/judy_hash.c', line 45

VALUE ruby_JudyHash_allocate(VALUE self) {
  tree_object* tree = malloc( sizeof(tree_object) ) ;
  tree->judy = NULL;
  return Data_Wrap_Struct(self,  gc_mark_hash, gc_free_hash, tree);
}

Instance Method Details

#[](index) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'ext/judy_hash.c', line 51

VALUE ruby_JudyHash_getitem(VALUE self , VALUE index) {
  VALUE val;
  JudyHash *p_hash ;
  if( index == Qnil ) return Qnil ;
  p_hash = Get_Hash(self);
  check_index_basic(index);
  val = (VALUE)judy_array_at_index(p_hash, index);
  return (val == 0) ? Qnil : val;
}

#[]=(index, value) ⇒ Object



81
82
83
84
85
86
87
88
# File 'ext/judy_hash.c', line 81

VALUE ruby_JudyHash_setitem(VALUE self , VALUE index , VALUE value ) {
  JudyHash *p_hash = Get_Hash(self) ;
  tree_object *was;
  check_index_basic(index);
  if( index == Qnil ) return Qnil ;
  was = judy_array_set(p_hash , index , (tree_object*)value);
  return value;
}

#by_count(num) ⇒ Object



138
139
140
141
142
143
144
# File 'ext/judy_hash.c', line 138

VALUE ruby_JudyHash_by_count(VALUE self, VALUE num) {
  JudyHash *p_hash = Get_Hash(self) ;
  VALUE val;
  check_index_basic(num);
  val = (VALUE)judy_array_at_count(p_hash, num);
  return (val == 0) ? Qnil : val;
}

#clearObject



23
24
25
26
27
# File 'ext/judy_hash.c', line 23

VALUE ruby_JudyHash_clear(VALUE self) {
  JudyHash *p_hash = Get_Hash(self) ;
  JudyLFreeArray( p_hash, PJE0);
  return self;
}

#countObject



90
91
92
93
# File 'ext/judy_hash.c', line 90

VALUE ruby_JudyHash_length(VALUE self) {
  JudyHash *p_hash = Get_Hash(self) ;
  return judy_array_length(p_hash);
}

#delete(index) ⇒ Object



72
73
74
75
76
77
78
79
# File 'ext/judy_hash.c', line 72

VALUE ruby_JudyHash_delete(VALUE self , VALUE index) {
  JudyHash *p_hash = Get_Hash(self) ;
  tree_object * was;
  check_index_basic(index);
  if( index == Qnil ) return Qfalse ;
  was = judy_array_delete(p_hash , index);
  return (was == NULL) ? Qfalse : Qtrue ;
}

#do_get(index) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'ext/judy_hash.c', line 51

VALUE ruby_JudyHash_getitem(VALUE self , VALUE index) {
  VALUE val;
  JudyHash *p_hash ;
  if( index == Qnil ) return Qnil ;
  p_hash = Get_Hash(self);
  check_index_basic(index);
  val = (VALUE)judy_array_at_index(p_hash, index);
  return (val == 0) ? Qnil : val;
}

#eachObject



116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'ext/judy_hash.c', line 116

VALUE ruby_JudyHash_each(VALUE self) {
  JudyHash *p_hash = Get_Hash(self) ;
  VALUE index = Qfalse;
  VALUE value = Qnil;
  if(p_hash == NULL) return self;
  index = judy_array_first_index(p_hash);
  while (index != Qfalse) {
    value = (VALUE) judy_array_at_index(p_hash , index);
    rb_yield_values(2 , index , value );
    index = judy_array_next_index(p_hash, index);
  }
  return self;
}

#each_keyObject



95
96
97
98
99
100
101
102
103
# File 'ext/judy_hash.c', line 95

VALUE ruby_JudyHash_each_key(VALUE self) {
  JudyHash *p_hash = Get_Hash(self) ;
  VALUE index = judy_array_first_index(p_hash);
  while (index != Qfalse) {
    rb_yield(index);
    index = judy_array_next_index(p_hash, index);
  }
  return self;
}

#empty?Boolean

Returns:

  • (Boolean)


130
131
132
133
134
135
136
# File 'ext/judy_hash.c', line 130

VALUE ruby_JudyHash_empty(VALUE self) {
  JudyHash *p_hash = Get_Hash(self) ;
  int c;
  if( ! p_hash ) return Qtrue;
  c = JudyLCount(*p_hash, 0 , -1 , PJE0) ;
  return  (0 == c) ? Qtrue : Qfalse ;
}

#first_indexObject



151
152
153
154
155
# File 'ext/judy_hash.c', line 151

VALUE ruby_JudyHash_first_index(VALUE self) {
    JudyHash *p_hash = Get_Hash(self) ;
    VALUE val = (VALUE)judy_array_first_index(p_hash);
    return (val == 0) ? Qnil : val;
}

#get(index) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'ext/judy_hash.c', line 51

VALUE ruby_JudyHash_getitem(VALUE self , VALUE index) {
  VALUE val;
  JudyHash *p_hash ;
  if( index == Qnil ) return Qnil ;
  p_hash = Get_Hash(self);
  check_index_basic(index);
  val = (VALUE)judy_array_at_index(p_hash, index);
  return (val == 0) ? Qnil : val;
}

#has_key?(index) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
68
69
70
# File 'ext/judy_hash.c', line 61

VALUE ruby_JudyHash_has_key(VALUE self , VALUE index) {
  JudyHash *p_hash ;
  VALUE val;
  if( index == Qnil ) return Qnil ;
  p_hash = Get_Hash(self) ;
  check_index_basic(index);
  if(!p_hash) return Qfalse;
  val = (VALUE)judy_array_at_index(p_hash, index);
  return (val == 0) ? Qfalse : Qtrue;
}

#include?(dat) ⇒ Boolean

Returns:

  • (Boolean)


178
179
180
181
182
183
184
185
186
187
188
# File 'ext/judy_hash.c', line 178

VALUE ruby_JudyHash_includeq(VALUE self, VALUE dat) {
  JudyHash *p_hash = Get_Hash(self) ;
  VALUE index = judy_array_first_index(p_hash);
  VALUE value = Qnil;
  while (index != Qfalse) {
    value = (VALUE) judy_array_at_index(p_hash , index);
    if( dat == value ) return index;
    index = judy_array_next_index(p_hash, index);
  }
  return Qfalse;
}

#keysObject



105
106
107
108
109
110
111
112
113
114
# File 'ext/judy_hash.c', line 105

VALUE ruby_JudyHash_keys(VALUE self) {
  JudyHash *p_hash = Get_Hash(self) ;
  VALUE index = judy_array_first_index(p_hash);
  VALUE array = rb_ary_new();
  while (index != Qfalse) {
    rb_ary_push(array , (VALUE)index);
    index = judy_array_next_index(p_hash, index);
  }
  return array;
}

#last_indexObject



165
166
167
168
169
# File 'ext/judy_hash.c', line 165

VALUE ruby_JudyHash_last_index(VALUE self) {
    JudyHash *p_hash = Get_Hash(self) ;
    VALUE val = (VALUE)judy_array_last_index(p_hash);
    return (val == 0) ? Qnil : val;
}

#lengthObject



90
91
92
93
# File 'ext/judy_hash.c', line 90

VALUE ruby_JudyHash_length(VALUE self) {
  JudyHash *p_hash = Get_Hash(self) ;
  return judy_array_length(p_hash);
}

#mem_usedObject



146
147
148
149
# File 'ext/judy_hash.c', line 146

VALUE ruby_JudyHash_mem_used(VALUE self) {
  JudyHash *p_hash = Get_Hash(self) ;
  return judy_array_mem(p_hash);
}

#next_index(in) ⇒ Object



157
158
159
160
161
162
163
# File 'ext/judy_hash.c', line 157

VALUE ruby_JudyHash_next_index(VALUE self, VALUE in) {
  JudyHash *p_hash = Get_Hash(self) ;
  VALUE val;
  check_index_basic(in);
  val = (VALUE)judy_array_next_index(p_hash, in);
  return (val == 0) ? Qnil : val;
}

#set(index, value) ⇒ Object



81
82
83
84
85
86
87
88
# File 'ext/judy_hash.c', line 81

VALUE ruby_JudyHash_setitem(VALUE self , VALUE index , VALUE value ) {
  JudyHash *p_hash = Get_Hash(self) ;
  tree_object *was;
  check_index_basic(index);
  if( index == Qnil ) return Qnil ;
  was = judy_array_set(p_hash , index , (tree_object*)value);
  return value;
}