⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 curia.rb

📁 一个小型的基于Hash的Key=>Value的数据库
💻 RB
📖 第 1 页 / 共 2 页
字号:
  # stored.  If alignment is positive, padding whose size is multiple number of the alignment  # is placed.  If alignment is negative, as `vsiz' is the size of a value, the size of padding  # is calculated with `(vsiz / pow(2, abs(align) - 1))'.  Because alignment setting is not  # saved in a database, you should specify alignment every opening a database.  #  def setalign(align = 0)    mod_setalign(@index, align)  end  ##  # bool = curia.setfbpsiz(size);  # Method: Set the size of the free block pool.  # `size' specifies the size of the free block pool.  If it is undef, the free block pool is not  # used.  # The return value is always true.  # An exception of `Curia::EANY' or its sub classes is thrown if an error occurs.  # The default size of the free block pool is 16.  If the size is greater, the space efficiency  # of overwriting values is improved with the time efficiency sacrificed.  #  def setfbpsiz(size = 0)    mod_setfbpsiz(@index, size)  end  ##  # bool = curia.sync()  # Method: Synchronize updating contents with the files and the devices.  # The return value is always true.  # An exception of `Curia::EANY' or its sub classes is thrown if an error occurs.  # This method is useful when another process uses the connected database directory.  #  def sync()    mod_sync(@index)  end  ##  # bool = curia.optimize(bnum)  # Method: Optimize the database.  # `bnum' specifies the number of the elements of the bucket array.  If it is omitted or not  # more than 0, the default value is specified.  # The return value is always true.  # An exception of `Curia::EANY' or its sub classes is thrown if an error occurs.  # In an alternating succession of deleting and storing with overwrite or concatenate,  # dispensable regions accumulate.  This method is useful to do away with them.  #  def optimize(bnum = -1)    mod_optimize(@index, bnum)  end  ##  # num = curia.fsiz()  # Method: Get the total size of the database files.  # The return value is the total size of the database files.  # An exception of `Curia::EANY' or its sub classes is thrown if an error occurs.  # If the total size is more than 2GB, the return value overflows.  #  def fsiz()    mod_fsiz(@index)  end  ##  # num = curia.bnum()  # Method: Get the total number of the elements of each bucket array.  # The return value is the total number of the elements of each bucket array  # An exception of `Curia::EANY' or its sub classes is thrown if an error occurs.  #  def bnum()    mod_bnum(@index)  end  ##  # num = curia.rnum()  # Method: Get the number of the records stored in the database.  # The return value is the number of the records stored in the database.  # An exception of `Curia::EANY' or its sub classes is thrown if an error occurs.  #  def rnum()    mod_rnum(@index)  end  ##  # num = curia.length()  # Method: An alias of `rnum'.  #  alias length rnum  ##  # num = curia.size()  # Method: An alias of `rnum'.  #  alias size rnum  ##  # bool = curia.writable()  # Method: Check whether the database handle is a writer or not.  # The return value is true if the handle is a writer, false if not.  # An exception of `Curia::EANY' or its sub classes is thrown if an error occurs.  #  def writable()    mod_writable(@index)  end  ##  # bool = curia.fatalerror()  # Method: Check whether the database has a fatal error or not.  # The return value is true if the database has a fatal error, false if not.  # An exception of `Curia::EANY' or its sub classes is thrown if an error occurs.  #  def fatalerror()    mod_fatalerror(@index)  end  ##  # curia.each() do |key, val| ... end  # Iterator Method: Iterate a process with a pair of a key and a value of each record.  #  def each()    MyMutex.synchronize() do      iterinit()      while(true)        begin          break unless key = iternext()          val = get(key)        rescue ENOITEM          break        end        yield(key, val)      end      iterinit()    end    self  end  ##  # curia.each_pair() do |key, val| ... end  # Iterator Method: An alias of `each'.  #  alias each_pair each  ##  # curia.each_key() do |key| ... end  # Iterator Method: Iterate a process with a key of each record.  #  def each_key()    MyMutex.synchronize() do      iterinit()      while(true)        begin          break unless key = iternext()        rescue ENOITEM          break        end        yield(key)      end      iterinit()    end    self  end  ##  # curia.each_value() do |val| ... end  # Iterator Method: Iterate a process with a value of each record.  #  def each_value()    MyMutex.synchronize() do      iterinit()      while(true)        begin          break unless key = iternext()          val = get(key)        rescue ENOITEM          break        end        yield(val)      end      iterinit()    end    self  end  ##  # ary = curia.keys()  # Method: Get an array of all keys.  # The return value is an array of all keys.  # An exception of `Curia::EANY' or its sub classes is thrown if an error occurs.  #  def keys()    ary = Array::new(rnum())    MyMutex.synchronize() do      iterinit()      0.upto(ary.length - 1) do |i|        ary[i] = iternext()      end      iterinit()    end    ary  end  ##  # ary = curia.values()  # Method: Get an array of all values.  # The return value is an array of all values.  # An exception of `Curia::EANY' or its sub classes is thrown if an error occurs.  #  def values()    ary = Array::new(rnum())    MyMutex.synchronize() do      iterinit()      0.upto(ary.length - 1) do |i|        ary[i] = get(iternext())      end      iterinit()    end    ary  end  ##  # str = curia.index(val)  # Method: Retrieve a record with a value.  # `val' specifies a value.  Although it must be an instance of String, binary data is okey.  # The return value is the key of the record with the specified value.  # An exception of `Curia::EANY' or its sub classes is thrown if an error occurs or no record  # corresponds.  # If two or more records correspond, the first found record is selected.  #  def index(val)    key = nil    MyMutex.synchronize() do      iterinit()      while(true)        break unless key = iternext()        (get(key) == val) && break      end      iterinit()    end    key  end  ##  # num = curia.to_int()  # Method: An alias of `rnum'.  #  alias to_int rnum  ##  # num = curia.to_i()  # Method: An alias of `to_int'.  #  alias to_i to_int  ##  # str = curia.to_str()  # Method: Get string standing for the instance.  #  def to_str    if(@index != -1)      sprintf("#<Curia:%#x:name=%s:state=open:bnum=%d:rnum=%d>",              object_id(), @name, bnum(), rnum())    else      sprintf("#<Curia:%#x:name=%s:state=closed>", object_id(), @name)    end  end  ##  # str = curia.to_s()  # Method: An alias of `to_str'.  #  alias to_s to_str  ##  # ary = curia.to_ary()  # Method: Get an array of alternation of each pair of key and value.  #  def to_ary    ary = Array::new(rnum())    i = 0    each() do |key, val|      ary[i] = [key, val]      i += 1    end    ary  end  ##  # ary = curia.to_a()  # Method: An alias of `to_ary'.  #  alias to_a to_ary  ##  # hash = curia.to_hash()  # Method: Get a hash storing all records.  #  def to_hash    hash = Hash::new()    each() do |key, val|      hash[key] = val    end    hash  end  ##  # hash = curia.to_h()  # Method: An alias of `to_hash'.  #  alias to_h to_hash  ##  # str = curia.inspect()  # Method: An alias of `to_str'.  #  alias inspect to_strend#----------------------------------------------------------------# Alias definition of class methods#----------------------------------------------------------------class << Curia  alias open newend# END OF FILE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -