软件模块 as 硬件模块: 输入 + 输出 + 状态 + 配置

                @config
                   |
                   v
             +-----------+
             |           |
   @input => | @state    | => @output
             |           |
             +-----------+
                   ^
                   |
                 @action

以 Bloom-Filter 的描述为例,看起来有点像这样。

namespace eval bloom-filter {
   @input  item
   @output exist

   @config hasher_list [list]
   @config M           1000

   @state checklist    [lrepeat $M 0]


   @action add {item} {
      foreach hasher $hasher_list {
         set idx [$hasher $item]
         lset checklist $idx 1
      }
   }

   @action exist {item} => @output exist {
      set exist true

      foreach hasher $hasher_list {
         set idx [$hasher $item]
         if {[lindex $checklist $idx]==0} {
            set exist false
            break
         }
      }

      return $exist
   }
}

相关资源