[#9437] ruby 1.1c4 released — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

17 messages 1998/09/03

[#9570] ruby-gtk-0.11 — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

16 messages 1998/09/16

[#9573] filter — gotoken@... (GOTO Kentaro)

ごとけんです

34 messages 1998/09/16
[#9575] Re: filter — Shin-ichro Hara <sinara@...> 1998/09/17

原です。

[#9577] Re: filter — Shin-ichro Hara <sinara@...> 1998/09/17

原です。

[#9613] can't clone Fixnum — Kikutani Makoto <kikutani@...>

前田さんのruby-jedパッチをJed 0.98.7+J0.5.3に無理やりあてて

27 messages 1998/09/19
[#9622] Re: can't clone Fixnum — shugo@... (MAEDA Shugo) 1998/09/21

前田です。

[#9633] Re: can't clone Fixnum — Kikutani Makoto <kikutani@...> 1998/09/22

Mon, Sep 21, 1998 at 06:44:30PM +0900 において

[#9635] Re: can't clone Fixnum — matz@... (Yukihiro Matsumoto) 1998/09/22

まつもと ゆきひろです

[#9637] Re: can't clone Fixnum — Kikutani Makoto <kikutani@...> 1998/09/22

回答どうもです。

[#9640] Re: can't clone Fixnum — matz@... (Yukihiro Matsumoto) 1998/09/22

まつもと ゆきひろです

[#9647] Re: can't clone Fixnum — Kikutani Makoto <kikutani@...> 1998/09/22

Tue, Sep 22, 1998 at 01:07:22PM +0900 において

[#9650] Re: can't clone Fixnum — matz@... (Yukihiro Matsumoto) 1998/09/22

まつもと ゆきひろです

[#9626] nif.rb (ver0.14) — Wakou Aoyama <wakou@...>

青山です。

35 messages 1998/09/21
[#9628] Re: nif.rb (ver0.14) — WATANABE Tetsuya <tetsu@...> 1998/09/22

渡辺哲也です。

[#9638] Re: nif.rb (ver0.14) — SHUDOH Kazuyuki <shudoh@...> 1998/09/22

渡辺哲也さん wrote:

[#9642] Re: nif.rb (ver0.14) — Kikutani Makoto <kikutani@...> 1998/09/22

Tue, Sep 22, 1998 at 12:58:23PM +0900 において

[#9703] Re: nif.rb (ver0.14) — hisanori@... 1998/09/24

松尾です。

[#9704] Re: nif.rb (ver0.14) — matz@... (Yukihiro Matsumoto) 1998/09/24

まつもと ゆきひろです

[#9705] Re: nif.rb (ver0.14) — hisanori@... 1998/09/24

松尾です。こんばんは。

[#9706] Re: nif.rb (ver0.14) — matz@... (Yukihiro Matsumoto) 1998/09/24

まつもと ゆきひろです

[#9723] Re: nif.rb (ver0.14) — hisanori@... 1998/09/25

松尾です。こんにちは。

[#9724] pstore.rb(Re: Re: nif.rb (ver0.14)) — matz@... (Yukihiro Matsumoto) 1998/09/25

まつもと ゆきひろです

[#9670] how to create a instance dinamically using String class. — Masato Taruishi <taru@...>

18 messages 1998/09/22
[#9671] Re: how to create a instance dinamically using String class. — ttate@... 1998/09/22

立石です。

[#9677] Re: how to create a instance dinamically using String class. — keiju@... (Keiju ISHITSUKA) 1998/09/23

けいじゅ@日本ラショナルソフトウェアです.

[#9678] Re: how to create a instance dinamically using String class. — Masato Taruishi <taru@...> 1998/09/23

[#9702] [HAMATTA!] != — Shin-ichro Hara <sinara@...>

原です。

16 messages 1998/09/24

[#9770] ruby-jed SEGV — Kikutani Makoto <kikutani@...>

きくたにです。

16 messages 1998/09/29

[ruby-list:9722] Re: nif.rb (ver0.14)

From: matz@... (Yukihiro Matsumoto)
Date: 1998-09-25 04:12:46 UTC
List: ruby-list #9722
まつもと ゆきひろです

In message "[ruby-list:9706] Re: nif.rb (ver0.14)"
    on 98/09/24, Yukihiro Matsumoto <matz@netlab.co.jp> writes:

||といってもフルに機能を使ったわけではないので、適当なものを「これがOODB
||です」といって渡されればその機能の範囲内で納得してしまうかも。
|
|lib/pstore.rbを渡して納得…できないでしょうね.o_dbm.rbの方
|では…やっぱり無理かなあ.o_dbm.rbの方はcontribにあります.

pstore.rbはトランザクション毎に全部のデータをメモリに読み書
きするんでデータ量が増えるとだめでしょうね.ある程度の規模で
も動作するdbmを使ったdstore.rbってのを作ってみました.

こういうのが10分で作れるのがRubyの良いところですね.

--
#
# How to use:
#
# db = DStore.new("/tmp/foo")
# db.transaction do
#   p db.roots
#   ary = db["root"] = [1,2,3,4]
#   ary[0] = [1,1.5]
# end

# db.transaction do
#   p db["root"]
# end

require "marshal"
require "dbm"

class DStore
  class Error < StandardError
  end

  def initialize(file)
    @dbm = DBM.open(file)
    @transaction = false
    @filename = file
    @abort = false
  end

  def in_transaction
    raise Error, "not in transaction" unless @transaction
  end
  private :in_transaction

  def [](name)
    in_transaction
    value = @table[name]
    if value == nil
      value = @dbm[name]
      if value == nil
	raise Error, "undefined root name `%s'" % name
      end
      @table[name] = value = Marshal.load(value)
    end
    value
  end
  def []=(name, value)
    in_transaction
    unless name.kind_of? String
      raise TypeError, "root name should be String"
    end
    @table[name] = value
  end

  def roots
    in_transaction
    @dbm.keys
  end
  def root?(name)
    in_transaction
    @table.key? name or @dbm.key? name
  end
  def path
    @filename
  end

  def commit
    @abort = false
    throw :pstore_abort_transaction
  end
  def abort
    @abort = true
    throw :pstore_abort_transaction
  end

  def transaction
    raise Error, "nested transaction" if @transaction
    begin
      @transaction = true
      value = nil
      @table = {}
      begin
	catch(:pstore_abort_transaction) do
	  value = yield(self)
	end
      rescue Exception
	@abort = true
	raise
      ensure
	for k, v in @table
	  @dbm[k] = Marshal.dump(v)
	end
	@abort = false
      end
    ensure
      @transaction = false
    end
    value
  end
end

if __FILE__ == $0
  db = DStore.new("/tmp/foo")
  db.transaction do
    p db.roots
    ary = db["root"] = [1,2,3,4]
    ary[0] = [1,1.5]
  end

  db.transaction do
    p db["root"]
  end
end

In This Thread