### Home Classes Methods

### In Files

- lib/rbot/maskdb.rb

### Parent

Object

### Methods

- ::new
- #add
- #empty?
- #find
- #find_helper
- #remove

### Class/Module Index

Quicksearch

- Irc
- Irc::AsciiCasemap
- Irc::BanlistMessage
- Irc::BasicUserMessage
- Irc::Bot
- Irc::Bot::Auth
- Irc::Bot::Auth::BotOwnerClass
- Irc::Bot::Auth::BotUser
- Irc::Bot::Auth::Command
- Irc::Bot::Auth::DefaultBotUserClass
- Irc::Bot::Auth::InvalidPassword
- Irc::Bot::Auth::ManagerClass
- Irc::Bot::Auth::PermissionSet
- Irc::Bot::Config
- Irc::Bot::Config::ArrayValue
- Irc::Bot::Config::BooleanValue
- Irc::Bot::Config::EnumValue
- Irc::Bot::Config::FloatValue
- Irc::Bot::Config::IntegerValue
- Irc::Bot::Config::ManagerClass
- Irc::Bot::Config::StringValue
- Irc::Bot::Config::Value
- Irc::Bot::Config::Wizard
- Irc::Bot::DataFilter
- Irc::Bot::DataStream
- Irc::Bot::Language
- Irc::Bot::MessageMapper
- Irc::Bot::MessageMapper::Failure
- Irc::Bot::MessageMapper::FriendlyFailure
- Irc::Bot::MessageMapper::NoActionFailure
- Irc::Bot::MessageMapper::NoMatchFailure
- Irc::Bot::MessageMapper::NotPrivateFailure
- Irc::Bot::MessageMapper::NotPublicFailure
- Irc::Bot::MessageMapper::PartialMatchFailure
- Irc::Bot::MessageParameter
- Irc::Bot::MessageTemplate
- Irc::Bot::Plugins
- Irc::Bot::Plugins::BotModule
- Irc::Bot::Plugins::CoreBotModule
- Irc::Bot::Plugins::Plugin
- Irc::Bot::Plugins::PluginManagerClass
- Irc::Bot::Plugins::RecurseTooDeep
- Irc::Bot::Plugins::RemoteBotModule
- Irc::Bot::Plugins::RemoteCoreBotModule
- Irc::Bot::Plugins::RemotePlugin
- Irc::Bot::Registry
- Irc::Bot::Registry::Accessor
- Irc::Bot::RemoteDispatcher
- Irc::Bot::RemoteMessage
- Irc::Bot::RemoteObject
- Irc::Bot::Wordlist
- Irc::BotConfig
- Irc::Casemap
- Irc::Channel
- Irc::Channel::Mode
- Irc::Channel::ModeHash
- Irc::Channel::ModeTypeA
- Irc::Channel::ModeTypeB
- Irc::Channel::ModeTypeC
- Irc::Channel::ModeTypeD
- Irc::Channel::Topic
- Irc::Channel::UserMode
- Irc::ChannelList
- Irc::Client
- Irc::DBHash
- Irc::DBTree
- Irc::InviteMessage
- Irc::JoinMessage
- Irc::KickMessage
- Irc::MessageQueue
- Irc::ModeChangeMessage
- Irc::MotdMessage
- Irc::NamesMessage
- Irc::Netmask
- Irc::NetmaskDb
- Irc::NetmaskDb::Tree
- Irc::NetmaskList
- Irc::NickMessage
- Irc::NoSuchTargetMessage
- Irc::NoticeMessage
- Irc::PartMessage
- Irc::PrivMessage
- Irc::QueueRing
- Irc::QuitMessage
- Irc::RfcCasemap
- Irc::Server
- Irc::ServerOrCasemap
- Irc::Socket
- Irc::Socket::IdentityFilter
- Irc::StrictRfcCasemap
- Irc::TopicMessage
- Irc::UnknownMessage
- Irc::User
- Irc::UserList
- Irc::UserMessage
- Irc::Utils
- Irc::Utils::HttpUtil
- Irc::Utils::HttpUtil::CachedObject
- Irc::Utils::ParseTime
- Irc::WelcomeMessage
- Irc::WhoisMessage
- BDB
- BDB::CIBtree
- MonitorMixin
- MonitorMixin::ConditionVariable
- Net
- Net::HTTPResponse
- Regexp
- Regexp::Irc
- Singleton
- Singleton::SingletonClassMethods
- Timer
- Timer::Action
- TokyoCabinet
- TokyoCabinet::CIBDB
- UnicodePlugin
- UnicodePlugin::UnicodeFilter
- Array
- ArrayOf
- AuthModule
- BasicsModule
- ConditionVariable
- ConfigModule
- DottedIndex
- Enumerable
- Exception
- FiltersModule
- GetText
- GetTextVersionError
- HttpUtilPlugin
- IrcLogModule
- Module
- Numeric
- Object
- Range
- RemoteModule
- ServerError
- String
- Symbol
- UserDataModule
- WordlistModule
- YAML

No matching classes.

# Irc::NetmaskDb::Tree

helper backend class: generic nested radix tree

### Attributes

chi[R]
pre[R]

### Public Class Methods

new(pre = '', chi = Hash.new) click to toggle source

    # File lib/rbot/maskdb.rb, line 7
    def initialize(pre = '', chi = Hash.new)
      @pre = pre
      @chi = chi
    end

### Public Instance Methods

add(val, *prefs) click to toggle source

    # File lib/rbot/maskdb.rb, line 12
    def add(val, *prefs)
      str = prefs.shift or raise 'empty prefs'
      @pre = str.dup if @chi.empty?

      n = 0
      @pre.size.times do
        break if @pre[n] != str[n]
        n += 1
      end

      rest = str.slice(n .. -1)

      if n != @pre.size
        prest = @pre.slice!(n .. -1)
        pc = prest.slice! 0
        @chi = {pc => Tree.new(prest, @chi)}
      end

      c = rest.slice!(0)

      if c
        (@chi[c] ||= Tree.new).add(val, rest, *prefs)
      else
        if prefs.empty?
          (@chi[''] ||= Array.new).push val
        else
          (@chi[''] ||= Tree.new).add(val, *prefs)
        end
      end
    end

empty?() click to toggle source

    # File lib/rbot/maskdb.rb, line 43
    def empty?
      @chi.empty?
    end

find(*prefs) click to toggle source

    # File lib/rbot/maskdb.rb, line 71
    def find(*prefs)
      str = prefs.shift or raise 'empty prefs?'
      self.find_helper(str, *prefs) + self.find_helper(str.reverse, *prefs)
    end

remove(*prefs, &block) click to toggle source

    # File lib/rbot/maskdb.rb, line 47
    def remove(*prefs, &block)
      str = prefs.shift or raise 'empty prefs?'
      return nil unless @pre.empty? or str.index(@pre) == 0
      c = str.slice(@pre.size) || ''
      return nil unless @chi.include? c
      if c == ''
        if prefs.empty?
          @chi[c].reject!(&block)
        else
          @chi[c].remove(*prefs, &block)
        end
      else
        @chi[c].remove(str.slice((@pre.size + 1) .. -1), *prefs, &block)
      end
      @chi.delete(c) if @chi[c].empty?

      if @chi.size == 1
        k = @chi.keys.shift
        return nil if k == ''
        @pre << k << @chi[k].pre
        @chi = @chi[k].chi
      end
    end

### Protected Instance Methods

find_helper(*prefs) click to toggle source

    # File lib/rbot/maskdb.rb, line 77
    def find_helper(*prefs)
      str = prefs.shift or raise 'empty prefs?'
      return [] unless @pre.empty? or str.index(@pre) == 0
      # puts "#{self.inspect}: #{str} == #{@pre} pfx matched"
      if !@chi.include? ''
        matches = []
      elsif Array === @chi['']
        matches = @chi['']
      else
        matches = @chi[''].find(*prefs)
      end

      c = str.slice(@pre.size)

      more = []
      if c and @chi.include?(c)
        more = @chi[c].find_helper(str.slice((@pre.size + 1) .. -1), *prefs)
      end
      return more + matches
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.