Class: Patricia::Node

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

Instance Method Summary collapse

Instance Method Details

#data ⇒ Object

---------- methods to node ----------



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'ext/rpatricia/rpatricia.c', line 229

static VALUE
p_data (VALUE self)
{
  VALUE user_data;
  patricia_node_t *node;
  Data_Get_Struct(self, patricia_node_t, node);

  user_data = (VALUE)node->data;

  /* for backwards compatibility, we always dup and return new strings */
  if (TYPE(user_data) == T_STRING)
    user_data = rb_str_dup(user_data);

  return user_data;
}

#network ⇒ Object



245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'ext/rpatricia/rpatricia.c', line 245

static VALUE
p_network (VALUE self)
{
  patricia_node_t *node;
  VALUE str = rb_str_new(0, PATRICIA_MAXSTRLEN);
  char *cstr = RSTRING_PTR(str);

  Data_Get_Struct(self, patricia_node_t, node);
  prefix_toa2x(node->prefix, cstr, 0);
  rb_str_set_len(str, strlen(cstr));

  return str;
}

#prefix ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'ext/rpatricia/rpatricia.c', line 259

static VALUE
p_prefix (VALUE self)
{
  patricia_node_t *node;
  VALUE str = rb_str_new(0, INET6_ADDRSTRLEN);
  char *cstr = RSTRING_PTR(str);

  Data_Get_Struct(self, patricia_node_t, node);
  prefix_toa2(node->prefix, cstr);
  rb_str_set_len(str, strlen(cstr));

  return str;
}

#prefixlen ⇒ Object



273
274
275
276
277
278
279
# File 'ext/rpatricia/rpatricia.c', line 273

static VALUE
p_prefixlen (VALUE self)
{
  patricia_node_t *node;
  Data_Get_Struct(self, patricia_node_t, node);
  return INT2NUM(node->prefix->bitlen);
}

#show_data ⇒ Object



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'ext/rpatricia/rpatricia.c', line 229

static VALUE
p_data (VALUE self)
{
  VALUE user_data;
  patricia_node_t *node;
  Data_Get_Struct(self, patricia_node_t, node);

  user_data = (VALUE)node->data;

  /* for backwards compatibility, we always dup and return new strings */
  if (TYPE(user_data) == T_STRING)
    user_data = rb_str_dup(user_data);

  return user_data;
}