rejuicer 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -24,168 +24,4 @@ sudo gem install rejuicer
24
24
 
25
25
  == LICENSE:
26
26
 
27
- GNU LESSER GENERAL PUBLIC LICENSE
28
- Version 3, 29 June 2007
29
-
30
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
31
- Everyone is permitted to copy and distribute verbatim copies
32
- of this license document, but changing it is not allowed.
33
-
34
-
35
- This version of the GNU Lesser General Public License incorporates
36
- the terms and conditions of version 3 of the GNU General Public
37
- License, supplemented by the additional permissions listed below.
38
-
39
- 0. Additional Definitions.
40
-
41
- As used herein, "this License" refers to version 3 of the GNU Lesser
42
- General Public License, and the "GNU GPL" refers to version 3 of the GNU
43
- General Public License.
44
-
45
- "The Library" refers to a covered work governed by this License,
46
- other than an Application or a Combined Work as defined below.
47
-
48
- An "Application" is any work that makes use of an interface provided
49
- by the Library, but which is not otherwise based on the Library.
50
- Defining a subclass of a class defined by the Library is deemed a mode
51
- of using an interface provided by the Library.
52
-
53
- A "Combined Work" is a work produced by combining or linking an
54
- Application with the Library. The particular version of the Library
55
- with which the Combined Work was made is also called the "Linked
56
- Version".
57
-
58
- The "Minimal Corresponding Source" for a Combined Work means the
59
- Corresponding Source for the Combined Work, excluding any source code
60
- for portions of the Combined Work that, considered in isolation, are
61
- based on the Application, and not on the Linked Version.
62
-
63
- The "Corresponding Application Code" for a Combined Work means the
64
- object code and/or source code for the Application, including any data
65
- and utility programs needed for reproducing the Combined Work from the
66
- Application, but excluding the System Libraries of the Combined Work.
67
-
68
- 1. Exception to Section 3 of the GNU GPL.
69
-
70
- You may convey a covered work under sections 3 and 4 of this License
71
- without being bound by section 3 of the GNU GPL.
72
-
73
- 2. Conveying Modified Versions.
74
-
75
- If you modify a copy of the Library, and, in your modifications, a
76
- facility refers to a function or data to be supplied by an Application
77
- that uses the facility (other than as an argument passed when the
78
- facility is invoked), then you may convey a copy of the modified
79
- version:
80
-
81
- a) under this License, provided that you make a good faith effort to
82
- ensure that, in the event an Application does not supply the
83
- function or data, the facility still operates, and performs
84
- whatever part of its purpose remains meaningful, or
85
-
86
- b) under the GNU GPL, with none of the additional permissions of
87
- this License applicable to that copy.
88
-
89
- 3. Object Code Incorporating Material from Library Header Files.
90
-
91
- The object code form of an Application may incorporate material from
92
- a header file that is part of the Library. You may convey such object
93
- code under terms of your choice, provided that, if the incorporated
94
- material is not limited to numerical parameters, data structure
95
- layouts and accessors, or small macros, inline functions and templates
96
- (ten or fewer lines in length), you do both of the following:
97
-
98
- a) Give prominent notice with each copy of the object code that the
99
- Library is used in it and that the Library and its use are
100
- covered by this License.
101
-
102
- b) Accompany the object code with a copy of the GNU GPL and this license
103
- document.
104
-
105
- 4. Combined Works.
106
-
107
- You may convey a Combined Work under terms of your choice that,
108
- taken together, effectively do not restrict modification of the
109
- portions of the Library contained in the Combined Work and reverse
110
- engineering for debugging such modifications, if you also do each of
111
- the following:
112
-
113
- a) Give prominent notice with each copy of the Combined Work that
114
- the Library is used in it and that the Library and its use are
115
- covered by this License.
116
-
117
- b) Accompany the Combined Work with a copy of the GNU GPL and this license
118
- document.
119
-
120
- c) For a Combined Work that displays copyright notices during
121
- execution, include the copyright notice for the Library among
122
- these notices, as well as a reference directing the user to the
123
- copies of the GNU GPL and this license document.
124
-
125
- d) Do one of the following:
126
-
127
- 0) Convey the Minimal Corresponding Source under the terms of this
128
- License, and the Corresponding Application Code in a form
129
- suitable for, and under terms that permit, the user to
130
- recombine or relink the Application with a modified version of
131
- the Linked Version to produce a modified Combined Work, in the
132
- manner specified by section 6 of the GNU GPL for conveying
133
- Corresponding Source.
134
-
135
- 1) Use a suitable shared library mechanism for linking with the
136
- Library. A suitable mechanism is one that (a) uses at run time
137
- a copy of the Library already present on the user's computer
138
- system, and (b) will operate properly with a modified version
139
- of the Library that is interface-compatible with the Linked
140
- Version.
141
-
142
- e) Provide Installation Information, but only if you would otherwise
143
- be required to provide such information under section 6 of the
144
- GNU GPL, and only to the extent that such information is
145
- necessary to install and execute a modified version of the
146
- Combined Work produced by recombining or relinking the
147
- Application with a modified version of the Linked Version. (If
148
- you use option 4d0, the Installation Information must accompany
149
- the Minimal Corresponding Source and Corresponding Application
150
- Code. If you use option 4d1, you must provide the Installation
151
- Information in the manner specified by section 6 of the GNU GPL
152
- for conveying Corresponding Source.)
153
-
154
- 5. Combined Libraries.
155
-
156
- You may place library facilities that are a work based on the
157
- Library side by side in a single library together with other library
158
- facilities that are not Applications and are not covered by this
159
- License, and convey such a combined library under terms of your
160
- choice, if you do both of the following:
161
-
162
- a) Accompany the combined library with a copy of the same work based
163
- on the Library, uncombined with any other library facilities,
164
- conveyed under the terms of this License.
165
-
166
- b) Give prominent notice with the combined library that part of it
167
- is a work based on the Library, and explaining where to find the
168
- accompanying uncombined form of the same work.
169
-
170
- 6. Revised Versions of the GNU Lesser General Public License.
171
-
172
- The Free Software Foundation may publish revised and/or new versions
173
- of the GNU Lesser General Public License from time to time. Such new
174
- versions will be similar in spirit to the present version, but may
175
- differ in detail to address new problems or concerns.
176
-
177
- Each version is given a distinguishing version number. If the
178
- Library as you received it specifies that a certain numbered version
179
- of the GNU Lesser General Public License "or any later version"
180
- applies to it, you have the option of following the terms and
181
- conditions either of that published version or of any later version
182
- published by the Free Software Foundation. If the Library as you
183
- received it does not specify a version number of the GNU Lesser
184
- General Public License, you may choose any version of the GNU Lesser
185
- General Public License ever published by the Free Software Foundation.
186
-
187
- If the Library as you received it specifies that a proxy can decide
188
- whether future versions of the GNU Lesser General Public License shall
189
- apply, that proxy's public statement of acceptance of any version is
190
- permanent authorization for you to choose that version for the
191
- Library.
27
+ Rejuicer is released under the MIT license.
data/ext/rejuicer_set.c CHANGED
@@ -128,6 +128,54 @@ int search_and_insert_at_leaf(leaf_node leaf, unsigned int value)
128
128
  return exist_flag;
129
129
  }
130
130
 
131
+ //
132
+ // remove element from set
133
+ //
134
+ void delete_num(root_node root, unsigned int value)
135
+ {
136
+ unsigned int quotient, remainder;
137
+
138
+ quotient = value / INDEX_PER_SIZE[0];
139
+ remainder = value % INDEX_PER_SIZE[0];
140
+
141
+ if (!(root->index[quotient])) return;
142
+
143
+ if (search_and_remove((branch_node)root->index[quotient], 1, remainder, value)) {
144
+ root->size--;
145
+ }
146
+ }
147
+
148
+ int search_and_remove(branch_node branch, int level, unsigned int value, unsigned int original)
149
+ {
150
+ unsigned int quotient, remainder, result;
151
+
152
+ quotient = value / INDEX_PER_SIZE[level];
153
+ remainder = value % INDEX_PER_SIZE[level];
154
+
155
+ if (!(branch->index[quotient])) return;
156
+
157
+ if (level == LAST_BRANCH_LEVEL) {
158
+ return search_and_remove_at_leaf((leaf_node)branch->index[quotient], remainder);
159
+ } else {
160
+ return search_and_remove((branch_node)branch->index[quotient], level + 1, remainder, original);
161
+ }
162
+ }
163
+
164
+ int search_and_remove_at_leaf(leaf_node leaf, unsigned int value)
165
+ {
166
+ int exist_flag = 0;
167
+ unsigned int target_bit;
168
+
169
+ target_bit = 1 << value;
170
+
171
+ if ((leaf->data & target_bit)) {
172
+ leaf->data ^= target_bit;
173
+ exist_flag = 1;
174
+ }
175
+
176
+ return exist_flag;
177
+ }
178
+
131
179
  //
132
180
  // output Array object from internal set
133
181
  //
@@ -269,6 +317,7 @@ void destroy_branch(branch_node branch)
269
317
  for(i = 0, count = 0; i < BRANCH_NODE_SIZE || count < branch->children_size; i++) {
270
318
  if (branch->index[i]) {
271
319
  free((leaf_node)branch->index[i]);
320
+ branch->index[i] = NULL;
272
321
  count++;
273
322
  }
274
323
  }
@@ -276,6 +325,7 @@ void destroy_branch(branch_node branch)
276
325
  for(i = 0, count = 0; i < BRANCH_NODE_SIZE || count < branch->children_size; i++) {
277
326
  if (branch->index[i]) {
278
327
  destroy_branch((branch_node)branch->index[i]);
328
+ branch->index[i] = NULL;
279
329
  count++;
280
330
  }
281
331
  }
@@ -324,6 +374,22 @@ static VALUE t_add(VALUE self, VALUE value)
324
374
  return self;
325
375
  }
326
376
 
377
+ /**
378
+ * delete
379
+ **/
380
+ static VALUE t_delete(VALUE self, VALUE value)
381
+ {
382
+ root_node root;
383
+ unsigned int num;
384
+
385
+ Data_Get_Struct(self, struct _root_node, root);
386
+ if ((num = NUM2UINT(value)) != Qnil) {
387
+ delete_num(root, num);
388
+ }
389
+
390
+ return self;
391
+ }
392
+
327
393
  /**
328
394
  * intersection
329
395
  **/
@@ -395,6 +461,7 @@ void Init_rejuicer_set(void) {
395
461
  rb_cRejuicerSet = rb_define_class("RejuicerSet", rb_cObject);
396
462
  rb_define_singleton_method(rb_cRejuicerSet, "new", t_new, -1);
397
463
  rb_define_method(rb_cRejuicerSet, "add", t_add, 1);
464
+ rb_define_method(rb_cRejuicerSet, "delete", t_delete, 1);
398
465
  rb_define_method(rb_cRejuicerSet, "intersection", t_intersection, 1);
399
466
  rb_define_method(rb_cRejuicerSet, "to_a", t_to_a, 0);
400
467
  rb_define_method(rb_cRejuicerSet, "size", t_size, 0);
data/ext/rejuicer_set.h CHANGED
@@ -50,6 +50,11 @@ void add_num(root_node, unsigned int);
50
50
  int search_and_insert(branch_node, int, unsigned int, unsigned int);
51
51
  int search_and_insert_at_leaf(leaf_node, unsigned int);
52
52
 
53
+ // remove element from set
54
+ void delete_num(root_node, unsigned int);
55
+ int search_and_remove(branch_node, int, unsigned int, unsigned int);
56
+ int search_and_remove_at_leaf(leaf_node, unsigned int);
57
+
53
58
  // output Array object from internal set
54
59
  void to_array(root_node, VALUE);
55
60
  void search_and_get_array(branch_node, VALUE);
@@ -71,6 +76,7 @@ void destroy_branch(branch_node);
71
76
 
72
77
  static VALUE t_new(int, VALUE *, VALUE);
73
78
  static VALUE t_add(VALUE, VALUE);
79
+ static VALUE t_delete(VALUE, VALUE);
74
80
  static VALUE t_intersection(VALUE, VALUE);
75
81
  static VALUE t_to_a(VALUE);
76
82
  static VALUE t_size(VALUE);
data/lib/rejuicer.rb CHANGED
@@ -13,6 +13,8 @@ require 'rejuicer_set'
13
13
  # index.search(:remainder_3 => 2, :remainder_5 => 4) #=> [14,29,44,59,...,9974,9989]
14
14
  #
15
15
  class Rejuicer
16
+ VERSION = "0.0.2"
17
+
16
18
  #
17
19
  # args :
18
20
  # methods or attributes name
@@ -51,6 +53,25 @@ class Rejuicer
51
53
  end
52
54
  alias :<< :add
53
55
 
56
+ #
57
+ # delete from index
58
+ # obj : object
59
+ # id_attr : index id
60
+ #
61
+ def delete(obj, id_attr = :id)
62
+ @tree.keys.each do |k|
63
+ begin
64
+ at = obj.__send__(k)
65
+ obj_id = obj.__send__(id_attr)
66
+ rescue NoMethodError
67
+ next
68
+ end
69
+
70
+ next unless @tree[k.to_sym][at]
71
+ @tree[k.to_sym][at].delete(obj_id)
72
+ end
73
+ end
74
+
54
75
  #
55
76
  # search
56
77
  # conditions: search target
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rejuicer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
5
11
  platform: ruby
6
12
  authors:
7
13
  - Tsukasa OISHI
@@ -9,29 +15,40 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-04-05 00:00:00 +09:00
13
- default_executable:
18
+ date: 2010-08-08 00:00:00 Z
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: newgem
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ hash: 25
29
+ segments:
30
+ - 1
31
+ - 2
32
+ - 3
23
33
  version: 1.2.3
24
- version:
34
+ type: :development
35
+ version_requirements: *id001
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: hoe
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
30
41
  requirements:
31
42
  - - ">="
32
43
  - !ruby/object:Gem::Version
44
+ hash: 55
45
+ segments:
46
+ - 1
47
+ - 8
48
+ - 0
33
49
  version: 1.8.0
34
- version:
50
+ type: :development
51
+ version_requirements: *id002
35
52
  description: Rejuicer.
36
53
  email:
37
54
  - tsukasa.oishi@gmail.com
@@ -52,7 +69,6 @@ files:
52
69
  - ext/extconf.rb
53
70
  - ext/rejuicer_set.h
54
71
  - ext/rejuicer_set.c
55
- has_rdoc: true
56
72
  homepage: http://www.kaeruspoon.net/
57
73
  licenses: []
58
74
 
@@ -64,21 +80,27 @@ require_paths:
64
80
  - lib
65
81
  - ext
66
82
  required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
67
84
  requirements:
68
85
  - - ">="
69
86
  - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
70
90
  version: "0"
71
- version:
72
91
  required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
73
93
  requirements:
74
94
  - - ">="
75
95
  - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
76
99
  version: "0"
77
- version:
78
100
  requirements: []
79
101
 
80
102
  rubyforge_project: rejuicer
81
- rubygems_version: 1.3.5
103
+ rubygems_version: 1.8.5
82
104
  signing_key:
83
105
  specification_version: 2
84
106
  summary: Rejuicer.