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

📄 depot.rb

📁 harvest是一个下载html网页得机器人
💻 RB
📖 第 1 页 / 共 2 页
字号:
  def sync()    mod_sync(@index)  end  ##  # bool = depot.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 `Depot::EANY' or its sub classes is thrown if an error occures.  # 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 = depot.fsiz()  # Method: Get the size of the database file.  # The return value is the size of the database file.  # An exception of `Depot::EANY' or its sub classes is thrown if an error occures.  #  def fsiz()    mod_fsiz(@index)  end  ##  # num = depot.bnum()  # Method: Get the number of the elements of the bucket array.  # The return value is the number of the elements of the bucket array  # An exception of `Depot::EANY' or its sub classes is thrown if an error occures.  #  def bnum()    mod_bnum(@index)  end  ##  # num = depot.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 `Depot::EANY' or its sub classes is thrown if an error occures.  #  def rnum()    mod_rnum(@index)  end  ##  # num = depot.length()  # Method: An alias of `rnum'.  #  alias length rnum  ##  # num = depot.size()  # Method: An alias of `rnum'.  #  alias size rnum  ##  # bool = depot.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 `Depot::EANY' or its sub classes is thrown if an error occures.  #  def writable()    mod_writable(@index)  end  ##  # bool = depot.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 `Depot::EANY' or its sub classes is thrown if an error occures.  #  def fatalerror()    mod_fatalerror(@index)  end  ##  # depot.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          key = iternext()          val = get(key)        rescue ENOITEM          break        end        yield(key, val)      end      iterinit()    end    self  end  ##  # depot.each_pair() do |key, val| ... end  # Iterator Method: An alias of `each'.  #  alias each_pair each  ##  # depot.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          key = iternext()        rescue ENOITEM          break        end        yield(key)      end      iterinit()    end    self  end  ##  # depot.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          val = get(iternext())        rescue ENOITEM          break        end        yield(val)      end      iterinit()    end    self  end  ##  # ary = depot.keys()  # Method: Get an array of all keys.  # The return value is an array of all keys.  # An exception of `Depot::EANY' or its sub classes is thrown if an error occures.  #  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 = depot.values()  # Method: Get an array of all values.  # The return value is an array of all values.  # An exception of `Depot::EANY' or its sub classes is thrown if an error occures.  #  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 = depot.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 `Depot::EANY' or its sub classes is thrown if an error occures 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)        key = iternext()        (get(key) == val) && break      end      iterinit()    end    key  end  ##  # num = depot.to_int()  # Method: An alias of `rnum'.  #  alias to_int rnum  ##  # num = depot.to_i()  # Method: An alias of `to_int'.  #  alias to_i to_int  ##  # str = depot.to_str()  # Method: Get string standing for the instance.  #  def to_str    if(@index != -1)      sprintf("#<Depot:%#x:name=%s:state=open:bnum=%d:rnum=%d>",              object_id(), @name, bnum(), rnum())    else      sprintf("#<Depot:%#x:name=%s:state=closed>", object_id(), @name)    end  end  ##  # str = depot.to_s()  # Method: An alias of `to_str'.  #  alias to_s to_str  ##  # ary = depot.to_ary()  # Method: Get an array of alternation of each pair of a key and a value.  #  def to_ary    ary = Array::new(rnum())    i = 0    each() do |key, val|      ary[i] = [key, val]      i += 1    end    ary  end  ##  # ary = depot.to_a()  # Method: An alias of `to_ary'.  #  alias to_a to_ary  ##  # hash = depot.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 = depot.to_h()  # Method: An alias of `to_hash'.  #  alias to_h to_hash  ##  # str = depot.inspect()  # Method: An alias of `to_str'.  #  alias inspect to_strend#----------------------------------------------------------------# Alias definition of class methods#----------------------------------------------------------------class << Depot  alias open newend# END OF FILE

⌨️ 快捷键说明

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