Wednesday 15 January 2014

inline - How to separate Ruby inlineC code to multiple files? -


I would like to move the matches macro and bitmap to a different file because I use these many places and I repeat How to avoid code that can be done?

  Two # To calculate the distance of Levenshatin between the given stars, "Inline" # is required for the class. # Http://en.wikipedia.org/wiki/Levenshtein_distance Category Levenshtein BYTES_IN_INT = 4 DF self.distance (S, T) Return 0 If S == T; Return t.length if s.length == 0; Return s.length if t.length == 0; V0 = "\ 0" * (t.length + 1) * BYTES_IN_INT v1 = "\ 0" * (T. Long + 1) * BYTES_IN_INT + L = self. L.distance_C (s, t, s.length, t Length, v0, v1) end # >> gt;> gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; & Gt; Ruby Inline C code & lt; & Lt; & Lt; & Lt; & Lt; & Lt; & Lt; & Lt; & Lt; & Lt; & Lt; & Lt; & Lt; & Lt; Inline | Manufacturer | #Macro to match nucleotides with ambiguity code. Builder. Prefix% {#} (at bit) (bitmap [a] and bitmap [b])! = 0)} # bitmap to match nucleotides with ambiguity code # Each value is set from left to bits: Bit Paus 1 for A, # Bit Paus 2 for T, bit Paus 3 for C, and G. Bit paus 4 for builder Prefix% {charge bitmap [256] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,14, 4, 11, 0, 0, 8, 7, 0, 0 , 10, 0, 5, 15, 0, 0, 0, 9, 12, 2, 2,13, 3, 0, 6, 0, 0, 0, 0, 0, 0, 0, 1,14, 4 , 11, 0, 0, 8, 7, 0, 0, 10, 0, 5, 15, 0, 0, 9, 12, 2, 2,13, 3, 0, 6, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0}; } Builder.prefix% {signed int min (unsigned int one, unsigned int b, unsigned int c) {unsigned int m = a; If (m> B) m = b; If (M> C) M = C; Refund M; }} Builder.c% {VALUE distance_C (VALUE _s, // string VALUE _t, // string VALUE _s_len, // string length VALUE _t_len, // string length VALUE _v0, // score vector VALUE _v1 // score Vector) {char * s = (four *) string valueprouts (_s); Four * t = (four *) stringvalueprint (_t); Unsigned int s_len = FIX2UINT (_s_len); Unsigned int t_len = FIX2UINT (_t_len); Unsigned int * v0 = (unsigned int *) StringValuePtr (_v0); Unsigned int * v1 = (unsigned int *) StringValuePtr (_v1); Unsigned int i = 0; Unsigned int j = 0; Unsigned int cost = 0; For (i = 0; i & lt; t_len + 1; i ++) v0 [i] = i; For (i = 0; i    

builder.prefix is just one Call method, so that you can make a Ruby method that calls it with your macro and character array, and then add it to any class, which wanted to use those C snippets inline. For example

  module mix comon cdff add_match_macro inline_builder inline_builder. Prefix% {# Detefane Match (A, B) (Bitmap [A] and Bitmap [B])! = 0)} End End   

In your example code you can use it For the beginning of the class

  class Levenshtein expansion MixinCommonC   

(This extension and is not included , because the class against the inline is being called, so only sections of the block can access square methods) < P> Where Worst Do not you call builder.prefix :

  add_match_macro (builder)    

No comments:

Post a Comment