mack-facets 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gems.rb +25 -0
- data/lib/gems/english-0.3.1/VERSION +1 -0
- data/lib/gems/english-0.3.1/lib/english/array.rb +48 -0
- data/lib/gems/english-0.3.1/lib/english/censor.rb +76 -0
- data/lib/gems/english-0.3.1/lib/english/double_metaphone.rb +353 -0
- data/lib/gems/english-0.3.1/lib/english/dresner.rb +47 -0
- data/lib/gems/english-0.3.1/lib/english/inflect.rb +299 -0
- data/lib/gems/english-0.3.1/lib/english/jumble.rb +37 -0
- data/lib/gems/english-0.3.1/lib/english/levenshtein.rb +78 -0
- data/lib/gems/english-0.3.1/lib/english/metaphone.rb +110 -0
- data/lib/gems/english-0.3.1/lib/english/numerals.rb +71 -0
- data/lib/gems/english-0.3.1/lib/english/patterns.rb +49 -0
- data/lib/gems/english-0.3.1/lib/english/porter_stemming.rb +188 -0
- data/lib/gems/english-0.3.1/lib/english/roman.rb +174 -0
- data/lib/gems/english-0.3.1/lib/english/similarity.rb +103 -0
- data/lib/gems/english-0.3.1/lib/english/soundex.rb +70 -0
- data/lib/gems/english-0.3.1/lib/english/string.rb +210 -0
- data/lib/gems/english-0.3.1/lib/english/style.rb +294 -0
- data/lib/gems/english-0.3.1/lib/english/style_orm.rb +143 -0
- data/lib/gems/english-0.3.1/lib/english/textfilter.rb +91 -0
- data/lib/gems/extlib-0.9.8/lib/extlib.rb +56 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/assertions.rb +8 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/blank.rb +59 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/boolean.rb +11 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/class.rb +175 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/datetime.rb +9 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/dictionary.rb +433 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/hash.rb +419 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/hook.rb +366 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/inflection.rb +435 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/lazy_array.rb +106 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/logger.rb +202 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/mash.rb +148 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/module.rb +41 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/nil.rb +5 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/numeric.rb +5 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/object.rb +175 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/object_space.rb +13 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/pathname.rb +5 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/pooling.rb +239 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/rubygems.rb +38 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/simple_set.rb +39 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/string.rb +132 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/struct.rb +8 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/symbol.rb +17 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/tasks/release.rb +15 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/time.rb +19 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/version.rb +3 -0
- data/lib/gems/extlib-0.9.8/lib/extlib/virtual_file.rb +10 -0
- data/lib/gems/facets-2.4.5/VERSION +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets-live.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets-load.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets.rb +11 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/combination.rb +59 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/conjoin.rb +58 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/delete.rb +61 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/index.rb +48 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/indexable.rb +73 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/merge.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/not_empty.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/only.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/pad.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/permutation.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/product.rb +57 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/recursively.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/rotate.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/select.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/splice.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/stackable.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/array/traverse.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding/caller.rb +54 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding/defined.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding/eval.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding/local_variables.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/binding/self.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/bitmask.rb +104 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/blank.rb +60 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/boolean.rb +156 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/callstack.rb +52 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/cattr.rb +2 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/cattr.rb +115 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/cattr_accessor.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/cattr_reader.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/cattr_writer.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/descendents.rb +36 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/methodize.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/pathize.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/prepend.rb +50 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/subclasses.rb +2 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/class/to_proc.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/comparable.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/comparable/bound.rb +65 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/comparable/cmp.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/comparable/comparable.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir/ascend.rb +59 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir/descend.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir/multiglob.rb +92 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir/parent.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/dir/recurse.rb +29 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/accumulate.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/cluster_by.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/collect.rb +54 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/commonality.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/count.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/divide.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/duplicates.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/each_by.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/entropy.rb +37 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/frequency.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/group_by.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/inject.rb +31 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/map_send.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/mash.rb +32 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/mode.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/modulate.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/none.rb +31 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/occur.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/one.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/probability.rb +36 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/split.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/sum.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/enumerable/uniq_by.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/exception.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/exception/detail.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/exception/suppress.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/append.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/create.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/null.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/read.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/rewrite.rb +88 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/rootname.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/split_root.rb +10 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/write.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/file/writelines.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/filetest.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/filetest/root.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/float.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/float/round.rb +2 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/functor.rb +77 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/alias.rb +31 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/argumentize.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/at.rb +8 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/autonew.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/collate.rb +45 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/delete.rb +47 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/diff.rb +11 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/except.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/insert.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/inverse.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/join.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/keys.rb +45 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/mash.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/merge.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op.rb +7 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_add.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_and.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_mul.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_or.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_push.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/op_sub.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/recursive_merge.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/recursively.rb +29 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/rekey.rb +59 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/select.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/slice.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/swap.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/to_h.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/to_proc.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/to_struct.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/traverse.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/update.rb +81 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/weave.rb +81 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/hash/zipnew.rb +2 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/indexable.rb +251 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/even.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/factorial.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/multiple.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/odd.rb +35 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/of.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/integer/ordinal.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__callee__.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__class__.rb +9 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__dir__.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__get__.rb +10 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__method__.rb +36 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/__set__.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/as.rb +100 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/ask.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/attr_singleton.rb +62 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/complete.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/constant.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/d.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/deep_copy.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/demo.rb +23 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/ergo.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/here.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/in.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance_assign.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance_class.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance_exec.rb +40 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance_send.rb +7 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/instance_variables.rb +99 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/maybe.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/not_nil.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/object_class.rb +10 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/object_hexid.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/object_send.rb +32 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/p.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/populate.rb +73 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/qua_class.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/require_all.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/require_local.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/resc.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/respond.rb +23 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/returning.rb +23 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/silence.rb +75 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/singleton_class.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/tap.rb +32 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/try.rb +23 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/val.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/kernel/with.rb +20 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/lazy.rb +238 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/matchdata.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/matchdata/match.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/matchdata/matchset.rb +44 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/metaid.rb +94 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/abstract.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/alias_accessor.rb +45 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/alias_method_chain.rb +50 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/alias_module_function.rb +30 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/ancestor.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/basename.rb +31 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/can.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/class.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/conflict.rb +63 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/include_function_module.rb +25 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/instance_methods.rb +40 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/integrate.rb +2 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/is.rb +57 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/methodize.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/modspace.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/module_load.rb +56 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/nesting.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/op.rb +95 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/pathize.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/prepend.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/redefine_method.rb +35 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/redirect_method.rb +45 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/rename_method.rb +20 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/revise.rb +62 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/spacename.rb +25 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/module/wrap_method.rb +28 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/nilclass.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/nilclass/ergo.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/nilclass/to_f.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/numeric.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/numeric/approx.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/numeric/distance.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/numeric/round.rb +72 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc/bind.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc/compose.rb +42 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc/curry.rb +31 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc/to_method.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/proc/update.rb +9 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range/combine.rb +47 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range/overlap.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range/to_r.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range/umbrella.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/range/within.rb +66 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/regexp.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/regexp/arity.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/regexp/to_re.rb +28 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/stackable.rb +86 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/align.rb +106 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/bracket.rb +105 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/bytes.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/camelcase.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/capitalized.rb +46 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/chars.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/chomp.rb +33 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/cleave.rb +36 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/divide.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/each_char.rb +29 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/each_word.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/end_with.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/fold.rb +39 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/interpolate.rb +20 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/line_wrap.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/lines.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/methodize.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/modulize.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/mscan.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/natcmp.rb +88 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/nchar.rb +28 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/op_sub.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/pathize.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/range.rb +77 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/rewrite.rb +28 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/shatter.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/snakecase.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/splice.rb +37 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/start_with.rb +32 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/subtract.rb +4 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/tab.rb +103 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/titlecase.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/to_re.rb +26 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/variablize.rb +13 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/word_wrap.rb +34 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/words.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/string/xor.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/chomp.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/generate.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/not.rb +29 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/plain.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/query.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/re_s.rb +18 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/setter.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/succ.rb +19 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/to_proc.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/symbol/variablize.rb +12 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/advance.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/ago.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/change.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/elapse.rb +16 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/hence.rb +94 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/round.rb +17 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/set.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/stamp.rb +44 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/to_time.rb +21 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/time/trunc.rb +15 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/to_hash.rb +87 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/unboundmethod.rb +6 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/unboundmethod/arguments.rb +44 -0
- data/lib/gems/facets-2.4.5/lib/core/facets/unboundmethod/name.rb +25 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/basicobject.rb +14 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/cgi.rb +50 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/continuation.rb +57 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/date.rb +396 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/head.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/safe_ln.rb +28 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/slice.rb +141 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/tail.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/wc.rb +114 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/whereis.rb +64 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/fileutils/which.rb +101 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/getoptlong.rb +71 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/logger.rb +291 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/ostruct.rb +238 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/pathname.rb +172 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/rbconfig.rb +45 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/set.rb +27 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/shellwords.rb +89 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/uri.rb +249 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/yaml.rb +75 -0
- data/lib/gems/facets-2.4.5/lib/lore/facets/zlib.rb +38 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/1stclassmethod.rb +140 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/advisable.rb +162 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/annotations.rb +302 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/ansicode.rb +315 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/arguments.rb +365 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/argvector.rb +353 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/association.rb +194 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/attr.rb +208 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/autoarray.rb +62 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/autoreload.rb +150 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/basex.rb +37 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/bbcode.rb +397 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/bicrypt.rb +265 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/binding/opvars.rb +24 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/binreadable.rb +221 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/blankslate.rb +66 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/buildable.rb +344 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/bytes.rb +175 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/cachedecorator.rb +117 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/capsule.rb +258 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/chain.rb +58 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/class_extension.rb +114 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/classmethods.rb +199 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/cloneable.rb +76 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/command.rb +439 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/consoleutils.rb +113 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/coroutine.rb +159 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/crypt.rb +166 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/cssfilter.rb +254 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/daemonize.rb +44 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/dependency.rb +151 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/dictionary.rb +478 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/dictionarymatcher.rb +136 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/downloader.rb +281 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/duplicable.rb +43 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/duration.rb +540 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/elementor.rb +133 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/elementwise.rb +61 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/enumerablepass.rb +217 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/equatable.rb +120 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/eventhook.rb +132 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/expirable.rb +82 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/fileable.rb +162 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/filelist.rb +497 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb +202 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/hash/stringify_keys.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/hash/symbolize_keys.rb +94 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/heap.rb +22 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/htmlfilter.rb +595 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/infinity.rb +193 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/inheritor.rb +130 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/ini.rb +264 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/instantiable.rb +47 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/instantise.rb +1 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/instantize.rb +95 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/interval.rb +282 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/ioredirect.rb +130 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/iteration.rb +65 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/kernel/meta.rb +32 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/linkedlist.rb +222 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/lrucache.rb +157 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/main.rb +70 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/memoize.rb +116 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/methodspace.rb +141 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/minitar.rb +1063 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/multipliers.rb +109 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/multiton.rb +386 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/nackclass.rb +41 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/net/smtp_tls.rb +131 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/nilstatus.rb +47 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/nullclass.rb +74 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/opencascade.rb +94 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/opencollection.rb +43 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/openhash.rb +39 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/openobject.rb +267 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/opesc.rb +60 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/orderedhash.rb +37 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/overload.rb +94 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/paramix.rb +202 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/partial.rb +37 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/pathlist.rb +112 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/platform.rb +192 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/pool.rb +91 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/pqueue.rb +449 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/progressbar.rb +253 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/prototype.rb +88 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/random.rb +451 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/rbsystem.rb +222 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/recorder.rb +109 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/reference.rb +99 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/reflection.rb +145 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/registerable.rb +35 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/rwdelegator.rb +74 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/semaphore.rb +92 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/settings.rb +248 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/snapshot.rb +209 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/string/mask.rb +278 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/string/words.rb +173 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/succ.rb +44 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/syncarray.rb +114 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/synchash.rb +157 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/tagiter.rb +366 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/thread.rb +51 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/timer.rb +274 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/times.rb +431 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/tracepoint.rb +209 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/tuple.rb +325 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/typecast.rb +261 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/uninheritable.rb +50 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/uploadutils.rb +464 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/version.rb +136 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/xmlhash.rb +112 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/xoxo.rb +259 -0
- data/lib/gems/facets-2.4.5/lib/more/facets/ziputils.rb +349 -0
- data/lib/mack-facets.rb +4 -2
- data/lib/mack-facets/english_extensions/inflect.rb +50 -50
- data/lib/mack-facets/extensions/string.rb +10 -1
- data/lib/mack-facets/utils/inflections.rb +50 -47
- data/lib/mack-facets/utils/inflector.rb +19 -19
- metadata +547 -36
@@ -0,0 +1,91 @@
|
|
1
|
+
# = Pool
|
2
|
+
#
|
3
|
+
# Generalized object pool implementation. Implemented as a thread
|
4
|
+
# safe stack. Exclusive locking is needed both for push and pop.
|
5
|
+
#
|
6
|
+
# == Author
|
7
|
+
#
|
8
|
+
# * George Moschovitis
|
9
|
+
#
|
10
|
+
# == Todo
|
11
|
+
#
|
12
|
+
# * Could use the SizedQueue/Queue?
|
13
|
+
#
|
14
|
+
# == Copying
|
15
|
+
#
|
16
|
+
# Copyright (c) 2004 George Moschovitis
|
17
|
+
#
|
18
|
+
# Ruby License
|
19
|
+
#
|
20
|
+
# This module is free software. You may use, modify, and/or redistribute this
|
21
|
+
# software under the same terms as Ruby.
|
22
|
+
#
|
23
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
24
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
25
|
+
# FOR A PARTICULAR PURPOSE.
|
26
|
+
|
27
|
+
require 'thread'
|
28
|
+
require 'monitor'
|
29
|
+
|
30
|
+
# = Pool
|
31
|
+
#
|
32
|
+
# Generalized object pool implementation. Implemented as a thread
|
33
|
+
# safe stack. Exclusive locking is needed both for push and pop.
|
34
|
+
#
|
35
|
+
class Pool < Array
|
36
|
+
|
37
|
+
include MonitorMixin
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
super
|
41
|
+
@cv = new_cond()
|
42
|
+
end
|
43
|
+
|
44
|
+
# Add, restore an object to the pool.
|
45
|
+
|
46
|
+
def push(obj)
|
47
|
+
synchronize do
|
48
|
+
super
|
49
|
+
@cv.signal()
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Obtain an object from the pool.
|
54
|
+
|
55
|
+
def pop
|
56
|
+
synchronize do
|
57
|
+
@cv.wait_while { empty? }
|
58
|
+
super
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Obtains an object, passes it to a block for processing
|
63
|
+
# and restores it to the pool.
|
64
|
+
|
65
|
+
def obtain
|
66
|
+
result = nil
|
67
|
+
begin
|
68
|
+
obj = pop()
|
69
|
+
result = yield(obj)
|
70
|
+
ensure
|
71
|
+
push(obj)
|
72
|
+
end
|
73
|
+
return result
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
# _____ _
|
81
|
+
# |_ _|__ ___| |_
|
82
|
+
# | |/ _ \/ __| __|
|
83
|
+
# | | __/\__ \ |_
|
84
|
+
# |_|\___||___/\__|
|
85
|
+
#
|
86
|
+
|
87
|
+
# TODO
|
88
|
+
|
89
|
+
=begin #testing
|
90
|
+
|
91
|
+
=end
|
@@ -0,0 +1,449 @@
|
|
1
|
+
# = PQueue
|
2
|
+
#
|
3
|
+
# Priority queue with array based heap.
|
4
|
+
#
|
5
|
+
# A priority queue is like a standard queue, except that each inserted
|
6
|
+
# elements is given a certain priority, based on the result of the
|
7
|
+
# comparison block given at instantiation time. Also, retrieving an element
|
8
|
+
# from the queue will always return the one with the highest priority
|
9
|
+
# (see #pop and #top).
|
10
|
+
#
|
11
|
+
# The default is to compare the elements in repect to their #> method.
|
12
|
+
# For example, Numeric elements with higher values will have higher
|
13
|
+
# priorities.
|
14
|
+
#
|
15
|
+
# == Thanks
|
16
|
+
#
|
17
|
+
# Rick Bradley 2003/02/02, patch for Ruby 1.6.5. Thank you!
|
18
|
+
#
|
19
|
+
# == Authors
|
20
|
+
#
|
21
|
+
# * Olivier Renaud
|
22
|
+
# * K.Kodama (Created original PQueue.rb)
|
23
|
+
# * Ronald Butler (reated original Heap.rb)
|
24
|
+
#
|
25
|
+
# == Copying
|
26
|
+
#
|
27
|
+
# Copyright (c) 2005 K.Kodama, Ronald Butler, Olivier Renaud
|
28
|
+
|
29
|
+
# = PQueue
|
30
|
+
#
|
31
|
+
# Priority queue with array based heap.
|
32
|
+
#
|
33
|
+
# A priority queue is like a standard queue, except that each inserted
|
34
|
+
# elements is given a certain priority, based on the result of the
|
35
|
+
# comparison block given at instantiation time. Also, retrieving an element
|
36
|
+
# from the queue will always return the one with the highest priority
|
37
|
+
# (see #pop and #top).
|
38
|
+
#
|
39
|
+
# The default is to compare the elements in repect to their #> method.
|
40
|
+
# For example, Numeric elements with higher values will have higher
|
41
|
+
# priorities.
|
42
|
+
#
|
43
|
+
class PQueue
|
44
|
+
|
45
|
+
# number of elements
|
46
|
+
attr_reader :size
|
47
|
+
# compare Proc
|
48
|
+
attr_reader :gt
|
49
|
+
attr_reader :qarray #:nodoc:
|
50
|
+
protected :qarray
|
51
|
+
|
52
|
+
# Returns a new priority queue.
|
53
|
+
#
|
54
|
+
# If elements are given, build the priority queue with these initial
|
55
|
+
# values. The elements object must respond to #to_a.
|
56
|
+
#
|
57
|
+
# If a block is given, it will be used to determine the priority between
|
58
|
+
# the elements.
|
59
|
+
#
|
60
|
+
# By default, the priority queue retrieves maximum elements first
|
61
|
+
# (using the #> method).
|
62
|
+
def initialize(elements=nil, &block) # :yields: a, b
|
63
|
+
@qarray = [nil]
|
64
|
+
@size = 0
|
65
|
+
@gt = block || lambda {|a,b| a > b}
|
66
|
+
replace(elements) if elements
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
# Assumes that the tree is a heap, for nodes < k.
|
72
|
+
#
|
73
|
+
# The element at index k will go up until it finds its place.
|
74
|
+
def upheap(k)
|
75
|
+
k2 = k.div(2)
|
76
|
+
v = @qarray[k]
|
77
|
+
while k2 > 0 && @gt[v, @qarray[k2]]
|
78
|
+
@qarray[k] = @qarray[k2]
|
79
|
+
k = k2
|
80
|
+
k2 = k2.div(2)
|
81
|
+
end
|
82
|
+
@qarray[k] = v
|
83
|
+
end
|
84
|
+
|
85
|
+
# Assumes the entire tree is a heap.
|
86
|
+
#
|
87
|
+
# The element at index k will go down until it finds its place.
|
88
|
+
def downheap(k)
|
89
|
+
v = @qarray[k]
|
90
|
+
q2 = @size.div(2)
|
91
|
+
loop {
|
92
|
+
break if k > q2
|
93
|
+
j = 2 * k
|
94
|
+
if j < @size && @gt[@qarray[j+1], @qarray[j]]
|
95
|
+
j += 1
|
96
|
+
end
|
97
|
+
break if @gt[v, @qarray[j]]
|
98
|
+
@qarray[k] = @qarray[j]
|
99
|
+
k = j
|
100
|
+
}
|
101
|
+
@qarray[k] = v;
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
# Recursive version of heapify. I kept the code, since it may be
|
106
|
+
# easier to understand than the non-recursive one.
|
107
|
+
# def heapify
|
108
|
+
# @size.div(2).downto(1) {|i| h(i)}
|
109
|
+
# end
|
110
|
+
# def h(t)
|
111
|
+
# l = 2 * t
|
112
|
+
# r = l + 1
|
113
|
+
# hi = if r > @size || @gt[@qarray[l],@qarray[r]] then l else r end
|
114
|
+
# if @gt[@qarray[hi],@qarray[t]]
|
115
|
+
# @qarray[hi], @qarray[t] = @qarray[t], @qarray[hi]
|
116
|
+
# h(hi) if hi <= @size.div(2)
|
117
|
+
# end
|
118
|
+
# end
|
119
|
+
|
120
|
+
# Make a heap out of an unordered array.
|
121
|
+
def heapify
|
122
|
+
@size.div(2).downto(1) do |t|
|
123
|
+
begin
|
124
|
+
l = 2 * t
|
125
|
+
r = l + 1
|
126
|
+
hi = if r > @size || @gt[@qarray[l],@qarray[r]] then l else r end
|
127
|
+
if @gt[@qarray[hi],@qarray[t]]
|
128
|
+
@qarray[hi], @qarray[t] = @qarray[t], @qarray[hi]
|
129
|
+
if hi <= @size.div(2)
|
130
|
+
t = hi
|
131
|
+
redo
|
132
|
+
end # if
|
133
|
+
end #if
|
134
|
+
end #begin
|
135
|
+
end # downto
|
136
|
+
end
|
137
|
+
|
138
|
+
public
|
139
|
+
|
140
|
+
# Add an element in the priority queue.
|
141
|
+
#
|
142
|
+
# The insertion time is O(log n), with n the size of the queue.
|
143
|
+
def push(v)
|
144
|
+
@size += 1
|
145
|
+
@qarray[@size] = v
|
146
|
+
upheap(@size)
|
147
|
+
return self
|
148
|
+
end
|
149
|
+
|
150
|
+
alias :<< :push
|
151
|
+
|
152
|
+
# Return the element with the highest priority and remove it from
|
153
|
+
# the queue.
|
154
|
+
#
|
155
|
+
# The highest priority is determined by the block given at instanciation
|
156
|
+
# time.
|
157
|
+
#
|
158
|
+
# The deletion time is O(log n), with n the size of the queue.
|
159
|
+
#
|
160
|
+
# Return nil if the queue is empty.
|
161
|
+
def pop
|
162
|
+
return nil if empty?
|
163
|
+
res = @qarray[1]
|
164
|
+
@qarray[1] = @qarray[@size]
|
165
|
+
@size -= 1
|
166
|
+
downheap(1)
|
167
|
+
return res
|
168
|
+
end
|
169
|
+
|
170
|
+
# Return the element with the highest priority.
|
171
|
+
def top
|
172
|
+
return nil if empty?
|
173
|
+
return @qarray[1]
|
174
|
+
end
|
175
|
+
|
176
|
+
# Add more than one element at the same time. See #push.
|
177
|
+
#
|
178
|
+
# The elements object must respond to #to_a, or to be a PQueue itself.
|
179
|
+
def push_all(elements)
|
180
|
+
if empty?
|
181
|
+
if elements.kind_of?(PQueue)
|
182
|
+
initialize_copy(elements)
|
183
|
+
else
|
184
|
+
replace(elements)
|
185
|
+
end
|
186
|
+
else
|
187
|
+
if elements.kind_of?(PQueue)
|
188
|
+
@qarray[@size + 1, elements.size] = elements.qarray[1..-1]
|
189
|
+
elements.size.times{ @size += 1; upheap(@size)}
|
190
|
+
else
|
191
|
+
ary = elements.to_a
|
192
|
+
@qarray[@size + 1, ary.size] = ary
|
193
|
+
ary.size.times{ @size += 1; upheap(@size)}
|
194
|
+
end
|
195
|
+
end
|
196
|
+
return self
|
197
|
+
end
|
198
|
+
|
199
|
+
alias :merge :push_all
|
200
|
+
|
201
|
+
|
202
|
+
# Return top n-element as a sorted array.
|
203
|
+
def pop_array(n=@size)
|
204
|
+
ary = []
|
205
|
+
n.times{ary.push(pop)}
|
206
|
+
return ary
|
207
|
+
end
|
208
|
+
|
209
|
+
|
210
|
+
# True if there is no more elements left in the priority queue.
|
211
|
+
def empty?
|
212
|
+
return @size.zero?
|
213
|
+
end
|
214
|
+
|
215
|
+
# Remove all elements from the priority queue.
|
216
|
+
def clear
|
217
|
+
@qarray.replace([nil])
|
218
|
+
@size = 0
|
219
|
+
return self
|
220
|
+
end
|
221
|
+
|
222
|
+
# Replace the content of the heap by the new elements.
|
223
|
+
#
|
224
|
+
# The elements object must respond to #to_a, or to be a PQueue itself.
|
225
|
+
def replace(elements)
|
226
|
+
if elements.kind_of?(PQueue)
|
227
|
+
initialize_copy(elements)
|
228
|
+
else
|
229
|
+
@qarray.replace([nil] + elements.to_a)
|
230
|
+
@size = @qarray.size - 1
|
231
|
+
heapify
|
232
|
+
end
|
233
|
+
return self
|
234
|
+
end
|
235
|
+
|
236
|
+
# Return a sorted array, with highest priority first.
|
237
|
+
def to_a
|
238
|
+
old_qarray = @qarray.dup
|
239
|
+
old_size = @size
|
240
|
+
res = pop_array
|
241
|
+
@qarray = old_qarray
|
242
|
+
@size = old_size
|
243
|
+
return res
|
244
|
+
end
|
245
|
+
|
246
|
+
alias :sort :to_a
|
247
|
+
|
248
|
+
# Replace the top element with the given one, and return this top element.
|
249
|
+
#
|
250
|
+
# Equivalent to successively calling #pop and #push(v).
|
251
|
+
def replace_top(v)
|
252
|
+
# replace top element
|
253
|
+
if empty?
|
254
|
+
@qarray[1] = v
|
255
|
+
@size += 1
|
256
|
+
return nil
|
257
|
+
else
|
258
|
+
res = @qarray[1]
|
259
|
+
@qarray[1] = v
|
260
|
+
downheap(1)
|
261
|
+
return res
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
# Return true if the given object is present in the queue.
|
266
|
+
def include?(element)
|
267
|
+
return @qarray.include?(element)
|
268
|
+
end
|
269
|
+
|
270
|
+
# Iterate over the ordered elements, destructively.
|
271
|
+
def each_pop #:yields: popped
|
272
|
+
until empty?
|
273
|
+
yield pop
|
274
|
+
end
|
275
|
+
return nil
|
276
|
+
end
|
277
|
+
|
278
|
+
# Pretty print
|
279
|
+
def inspect
|
280
|
+
"<#{self.class}: size=#{@size}, top=#{top || "nil"}>"
|
281
|
+
end
|
282
|
+
|
283
|
+
###########################
|
284
|
+
### Override Object methods
|
285
|
+
|
286
|
+
# Return true if the queues contain equal elements.
|
287
|
+
def ==(other)
|
288
|
+
return size == other.size && to_a == other.to_a
|
289
|
+
end
|
290
|
+
|
291
|
+
private
|
292
|
+
|
293
|
+
def initialize_copy(other)
|
294
|
+
@gt = other.gt
|
295
|
+
@qarray = other.qarray.dup
|
296
|
+
@size = other.size
|
297
|
+
end
|
298
|
+
end # class PQueue
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
# _____ _
|
303
|
+
# |_ _|__ ___| |_
|
304
|
+
# | |/ _ \/ __| __|
|
305
|
+
# | | __/\__ \ |_
|
306
|
+
# |_|\___||___/\__|
|
307
|
+
#
|
308
|
+
|
309
|
+
=begin #test
|
310
|
+
|
311
|
+
require 'test/unit'
|
312
|
+
|
313
|
+
class TC_PQueue < Test::Unit::TestCase
|
314
|
+
ARY_TEST = [2,6,1,3,8,15,0,-4,7,8,10]
|
315
|
+
ARY_TEST_2 = [25,10,5,13,16,9,16,12]
|
316
|
+
|
317
|
+
def test_initialize
|
318
|
+
assert_nothing_raised { PQueue.new }
|
319
|
+
assert_nothing_raised { PQueue.new([3]) }
|
320
|
+
assert_nothing_raised { PQueue.new(ARY_TEST) }
|
321
|
+
assert_nothing_raised { PQueue.new {|a,b| a<b} }
|
322
|
+
assert_nothing_raised { PQueue.new([3]) {|a,b| a<b} }
|
323
|
+
assert_nothing_raised { PQueue.new(ARY_TEST) {|a,b| a<b} }
|
324
|
+
end
|
325
|
+
|
326
|
+
def test_top
|
327
|
+
assert_equal(ARY_TEST.max, PQueue.new(ARY_TEST).top)
|
328
|
+
assert_nil(PQueue.new.top)
|
329
|
+
end
|
330
|
+
|
331
|
+
def test_pop
|
332
|
+
sorted_ary = ARY_TEST.sort
|
333
|
+
q = PQueue.new(ARY_TEST)
|
334
|
+
ARY_TEST.size.times do
|
335
|
+
assert_equal(sorted_ary.pop, q.pop)
|
336
|
+
end
|
337
|
+
assert_equal(0, q.size)
|
338
|
+
assert_nil(PQueue.new.pop)
|
339
|
+
end
|
340
|
+
|
341
|
+
def test_insertion
|
342
|
+
q = PQueue.new(ARY_TEST)
|
343
|
+
assert_equal(ARY_TEST.size, q.size)
|
344
|
+
|
345
|
+
ret = q.push(24)
|
346
|
+
assert_equal(q, ret)
|
347
|
+
assert_equal(ARY_TEST.size+1, q.size)
|
348
|
+
|
349
|
+
ret = q.push_all(ARY_TEST_2)
|
350
|
+
assert_equal(q, ret)
|
351
|
+
assert_equal(ARY_TEST.size+1+ARY_TEST_2.size, q.size)
|
352
|
+
|
353
|
+
q = PQueue.new(ARY_TEST)
|
354
|
+
r = PQueue.new(ARY_TEST_2)
|
355
|
+
q.push_all(r)
|
356
|
+
assert_equal(ARY_TEST.size + ARY_TEST_2.size, q.size)
|
357
|
+
end
|
358
|
+
|
359
|
+
def test_clear
|
360
|
+
q = PQueue.new(ARY_TEST).clear
|
361
|
+
assert_equal(q, q.clear)
|
362
|
+
assert_equal(0, q.size)
|
363
|
+
end
|
364
|
+
|
365
|
+
def test_replace
|
366
|
+
q = PQueue.new(ARY_TEST)
|
367
|
+
q.replace(ARY_TEST_2)
|
368
|
+
assert_equal(ARY_TEST_2.size, q.size)
|
369
|
+
|
370
|
+
q = PQueue.new(ARY_TEST)
|
371
|
+
q.replace(PQueue.new(ARY_TEST_2))
|
372
|
+
assert_equal(ARY_TEST_2.size, q.size)
|
373
|
+
end
|
374
|
+
|
375
|
+
def test_inspect
|
376
|
+
assert_equal("<PQueue: size=#{ARY_TEST.size}, top=#{ARY_TEST.max}>",
|
377
|
+
PQueue.new(ARY_TEST).inspect)
|
378
|
+
end
|
379
|
+
|
380
|
+
def test_to_a
|
381
|
+
q = PQueue.new(ARY_TEST)
|
382
|
+
assert_equal(ARY_TEST.sort.reverse, q.sort)
|
383
|
+
q = PQueue.new(0..4)
|
384
|
+
assert_equal([4,3,2,1,0], q.sort)
|
385
|
+
end
|
386
|
+
|
387
|
+
def pop_array
|
388
|
+
q = PQueue.new(ARY_TEST)
|
389
|
+
assert_equal(ARY_TEST.sort.reverse[0..5], q.pop_array(5))
|
390
|
+
q = PQueue.new(ARY_TEST)
|
391
|
+
assert_equal(ARY_TEST.sort.reverse, q.pop_array)
|
392
|
+
end
|
393
|
+
|
394
|
+
def test_include
|
395
|
+
q = PQueue.new(ARY_TEST + [21] + ARY_TEST_2)
|
396
|
+
assert_equal(true, q.include?(21))
|
397
|
+
|
398
|
+
q = PQueue.new(ARY_TEST - [15])
|
399
|
+
assert_equal(false, q.include?(15))
|
400
|
+
end
|
401
|
+
|
402
|
+
def test_assert_equal
|
403
|
+
assert_equal(PQueue.new, PQueue.new)
|
404
|
+
assert_equal(PQueue.new(ARY_TEST), PQueue.new(ARY_TEST.sort_by{rand}))
|
405
|
+
end
|
406
|
+
|
407
|
+
def test_replace_top
|
408
|
+
q = PQueue.new
|
409
|
+
assert_nil(q.replace_top(6))
|
410
|
+
assert_equal(6, q.top)
|
411
|
+
|
412
|
+
q = PQueue.new(ARY_TEST)
|
413
|
+
h = PQueue.new(ARY_TEST)
|
414
|
+
q.pop; q.push(11)
|
415
|
+
h.replace_top(11)
|
416
|
+
assert_equal(q, h)
|
417
|
+
end
|
418
|
+
|
419
|
+
def test_dup
|
420
|
+
q = PQueue.new(ARY_TEST)
|
421
|
+
assert_equal(q, q.dup)
|
422
|
+
end
|
423
|
+
|
424
|
+
def test_array_copied
|
425
|
+
ary = ARY_TEST.dup
|
426
|
+
q = PQueue.new(ary)
|
427
|
+
q.pop
|
428
|
+
assert_equal(ARY_TEST, ary)
|
429
|
+
|
430
|
+
ary = ARY_TEST.dup
|
431
|
+
q = PQueue.new
|
432
|
+
q.replace(ary)
|
433
|
+
q.pop
|
434
|
+
assert_equal(ARY_TEST, ary)
|
435
|
+
|
436
|
+
ary = ARY_TEST.dup
|
437
|
+
q = PQueue.new([1])
|
438
|
+
q.push_all(ary)
|
439
|
+
q.pop
|
440
|
+
assert_equal(ARY_TEST, ary)
|
441
|
+
|
442
|
+
q = PQueue.new(ARY_TEST)
|
443
|
+
r = q.dup
|
444
|
+
q.pop
|
445
|
+
assert_not_equal(q, r)
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
=end
|