Class: Bitmapper
- Inherits:
-
Object
- Object
- Bitmapper
- Defined in:
- ext/bitmapper/bitmapper.c
Instance Method Summary collapse
- #add(file_str) ⇒ Object
-
#clear(num) ⇒ Object
removes the given number from bitmapper.
- #clear_filters(val) ⇒ Object
- #disable_filter ⇒ Object
- #dump_range_to_str(file_str, start, end) ⇒ Object
- #dump_to(file_str) ⇒ Object
- #dump_to_str(file_str, index) ⇒ Object
- #enable_filter ⇒ Object
-
#get_indexes ⇒ Object
Call to refresh indexs in @indexes and return the value.
- #initialize(len) ⇒ Object constructor
- #load_from_str(file_str, index) ⇒ Object
- #remove(file_str) ⇒ Object
-
#reset ⇒ Object
Frees memory.
-
#set(num) ⇒ Object
adds the given number to bitmapper.
- #set_filters(val) ⇒ Object
-
#status?(num) ⇒ Boolean
returns true if the provided number is present in bitmap or returns false.
Constructor Details
#initialize(len) ⇒ Object
7 8 9 10 11 12 13 |
# File 'ext/bitmapper/bitmapper.c', line 7
VALUE bm_init(VALUE self, VALUE len){
Bitmapper* map;
Data_Get_Struct(self, Bitmapper, map);
allocate_map(map, FIX2INT(len));
rb_iv_set(self, "@index_len", len);
return self;
}
|
Instance Method Details
#add(file_str) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'ext/bitmapper/bitmapper.c', line 74
VALUE bm_add_from_file(VALUE self, VALUE file_str){
Bitmapper* map;
FILE *fp;
Data_Get_Struct(self, Bitmapper, map);
fp = fopen(RSTRING_PTR(StringValue(file_str)), "r");
if(fp == NULL) rb_raise(rb_eIOError, "file counld not be opened");
add_numbers_in_file(map, fp);
fclose(fp);
return self;
}
|
#clear(num) ⇒ Object
removes the given number from bitmapper
174 175 176 177 178 179 180 181 182 183 184 |
# File 'ext/bitmapper/bitmapper.c', line 174
VALUE bm_clear(VALUE self, VALUE num){
int status;
Bitmapper* map;
Data_Get_Struct(self, Bitmapper, map);
status = remove_num(map, bm_to_ll(num));
if(status==0)
return (VALUE)Qtrue;
else
rb_raise(rb_eTypeError, "not valid number");
}
|
#clear_filters(val) ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'ext/bitmapper/bitmapper.c', line 235
VALUE bm_clear_filters(VALUE self, VALUE val){
int i;
Bitmapper* map;
VALUE tmp;
if(TYPE(val) != T_ARRAY) rb_raise(rb_eRuntimeError, "Should be of type Array");
Data_Get_Struct(self, Bitmapper, map);
for(i=0; i< RARRAY_LEN(val); i++){
tmp = RARRAY_PTR(val)[i];
tmp = rb_funcall(tmp, rb_intern("to_s"), 0); /* hack */
clear_in_filter(map, bm_to_ll(tmp));
}
return (VALUE)Qtrue;
}
|
#disable_filter ⇒ Object
213 214 215 216 217 218 |
# File 'ext/bitmapper/bitmapper.c', line 213 VALUE bm_disable_filter(VALUE self){ Bitmapper* map; Data_Get_Struct(self, Bitmapper, map); disable_filter(map); return self; } |
#dump_range_to_str(file_str, start, end) ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'ext/bitmapper/bitmapper.c', line 118
VALUE bm_dump_range_bkt_str(VALUE self, VALUE file_str, VALUE start, VALUE end){
Bitmapper* map;
FILE *fp;
Data_Get_Struct(self, Bitmapper, map);
fp = fopen(RSTRING_PTR(StringValue(file_str)), "w");
if(fp == NULL) rb_raise(rb_eIOError, "file counld not be opened");
dump_bucket_range_str_to_file(map, fp, NUM2LL(start), NUM2LL(end));
fclose(fp);
return self;
}
|
#dump_to(file_str) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'ext/bitmapper/bitmapper.c', line 96
VALUE bm_dump_to_file(VALUE self, VALUE file_str){
Bitmapper* map;
FILE *fp;
Data_Get_Struct(self, Bitmapper, map);
fp = fopen(RSTRING_PTR(StringValue(file_str)), "w");
if(fp == NULL) rb_raise(rb_eIOError, "file counld not be opened");
dump_all_to_file(map, fp);
fclose(fp);
return self;
}
|
#dump_to_str(file_str, index) ⇒ Object
129 130 131 132 133 134 135 136 137 138 |
# File 'ext/bitmapper/bitmapper.c', line 129
VALUE bm_dump_bkt_str(VALUE self, VALUE file_str, VALUE index){
Bitmapper* map;
FILE *fp;
Data_Get_Struct(self, Bitmapper, map);
fp = fopen(RSTRING_PTR(StringValue(file_str)), "w");
if(fp == NULL) rb_raise(rb_eIOError, "file counld not be opened");
dump_bucket_str_to_file(map, fp, NUM2LL(index));
fclose(fp);
return self;
}
|
#enable_filter ⇒ Object
206 207 208 209 210 211 |
# File 'ext/bitmapper/bitmapper.c', line 206 VALUE bm_enable_filter(VALUE self){ Bitmapper* map; Data_Get_Struct(self, Bitmapper, map); enable_filter(map); return self; } |
#get_indexes ⇒ Object
Call to refresh indexs in @indexes and return the value
69 70 71 72 |
# File 'ext/bitmapper/bitmapper.c', line 69 VALUE bm_get_indexes(VALUE self){ bm_referesh_indexes(self); return rb_iv_get(self, "@indexes"); } |
#load_from_str(file_str, index) ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'ext/bitmapper/bitmapper.c', line 107
VALUE bm_load_str_to_bkt(VALUE self, VALUE file_str, VALUE index){
Bitmapper* map;
FILE *fp;
Data_Get_Struct(self, Bitmapper, map);
fp = fopen(RSTRING_PTR(StringValue(file_str)), "r");
if(fp == NULL) rb_raise(rb_eIOError, "file counld not be opened");
load_str_file_to_bucket(map, fp, NUM2LL(index));
fclose(fp);
return self;
}
|
#remove(file_str) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'ext/bitmapper/bitmapper.c', line 85
VALUE bm_remove_from_file(VALUE self, VALUE file_str){
Bitmapper* map;
FILE *fp;
Data_Get_Struct(self, Bitmapper, map);
fp = fopen(RSTRING_PTR(StringValue(file_str)), "r");
if(fp == NULL) rb_raise(rb_eIOError, "file counld not be opened");
remove_numbers_in_file(map, fp);
fclose(fp);
return self;
}
|
#reset ⇒ Object
Frees memory. The amount of memory returned to OS depends on compiler trip settings.
27 28 29 30 31 32 33 34 35 |
# File 'ext/bitmapper/bitmapper.c', line 27 VALUE bm_reset(VALUE self){ Bitmapper* map; VALUE len; Data_Get_Struct(self, Bitmapper, map); free_map(map); len = rb_iv_get(self, "@index_len"); allocate_map(map, FIX2INT(len)); return self; } |
#set(num) ⇒ Object
adds the given number to bitmapper
159 160 161 162 163 164 165 166 167 168 169 |
# File 'ext/bitmapper/bitmapper.c', line 159
VALUE bm_set(VALUE self, VALUE num){
int status;
Bitmapper* map;
Data_Get_Struct(self, Bitmapper, map);
status = add_num(map, bm_to_ll(num));
if(status==0)
return (VALUE)Qtrue;
else
rb_raise(rb_eTypeError, "not valid number");
}
|
#set_filters(val) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'ext/bitmapper/bitmapper.c', line 220
VALUE bm_set_filters(VALUE self, VALUE val){
int i;
Bitmapper* map;
VALUE tmp;
if(TYPE(val) != T_ARRAY) rb_raise(rb_eRuntimeError, "Should be of type Array");
Data_Get_Struct(self, Bitmapper, map);
for(i=0; i< RARRAY_LEN(val); i++){
tmp = RARRAY_PTR(val)[i];
tmp = rb_funcall(tmp, rb_intern("to_s"), 0); /* hack */
set_in_filter(map, bm_to_ll(tmp));
}
return (VALUE)Qtrue;
}
|
#status?(num) ⇒ Boolean
returns true if the provided number is present in bitmap or returns false
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'ext/bitmapper/bitmapper.c', line 190
VALUE bm_num_status(VALUE self, VALUE num){
int status;
VALUE return_val;
Bitmapper* map;
Data_Get_Struct(self, Bitmapper, map);
status = status_num(map, bm_to_ll(num));
if(status==1)
return (VALUE)Qtrue;
else if(status == 0)
return (VALUE)Qfalse;
else
rb_raise(rb_eTypeError, "not valid number");
return (VALUE)Qfalse;
}
|