### Home Classes Methods

### In Files

- lib/sass/util/subset_map.rb

### Parent

Object

### Methods

- ::new
- #[]
- #[]=
- #each_value
- #empty?
- #get

### Class/Module Index

Quicksearch

- Sass
- Sass::CSS
- Sass::CacheStores
- Sass::CacheStores::Base
- Sass::CacheStores::Chain
- Sass::CacheStores::Filesystem
- Sass::CacheStores::Memory
- Sass::CacheStores::Null
- Sass::Callbacks
- Sass::Callbacks::InstanceMethods
- Sass::Engine
- Sass::Engine::Line
- Sass::Environment
- Sass::Exec
- Sass::Exec::Generic
- Sass::Exec::Sass
- Sass::Exec::SassConvert
- Sass::Exec::Scss
- Sass::Importers
- Sass::Importers::Base
- Sass::Importers::Filesystem
- Sass::Logger
- Sass::Logger::Base
- Sass::Logger::LogLevel
- Sass::Logger::LogLevel::ClassMethods
- Sass::Media
- Sass::Media::Query
- Sass::Media::QueryList
- Sass::Plugin
- Sass::Plugin::Compiler
- Sass::Plugin::Configuration
- Sass::Plugin::MerbBootLoader
- Sass::Plugin::Rack
- Sass::Plugin::StalenessChecker
- Sass::Repl
- Sass::SCSS
- Sass::SCSS::CssParser
- Sass::SCSS::Parser
- Sass::SCSS::RX
- Sass::SCSS::ScriptLexer
- Sass::SCSS::ScriptParser
- Sass::SCSS::StaticParser
- Sass::Script
- Sass::Script::ArgList
- Sass::Script::Bool
- Sass::Script::Color
- Sass::Script::CssLexer
- Sass::Script::CssParser
- Sass::Script::Funcall
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Interpolation
- Sass::Script::Lexer
- Sass::Script::List
- Sass::Script::Literal
- Sass::Script::Node
- Sass::Script::Null
- Sass::Script::Number
- Sass::Script::Operation
- Sass::Script::Parser
- Sass::Script::String
- Sass::Script::StringInterpolation
- Sass::Script::UnaryOperation
- Sass::Script::Variable
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Interpolation
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::SelectorPseudoClass
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::Shared
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- Sass::Tree::MediaNode
- Sass::Tree::MixinDefNode
- Sass::Tree::MixinNode
- Sass::Tree::Node
- Sass::Tree::PropNode
- Sass::Tree::ReturnNode
- Sass::Tree::RootNode
- Sass::Tree::RuleNode
- Sass::Tree::SupportsNode
- Sass::Tree::TraceNode
- Sass::Tree::VariableNode
- Sass::Tree::Visitors
- Sass::Tree::Visitors::Base
- Sass::Tree::Visitors::CheckNesting
- Sass::Tree::Visitors::Convert
- Sass::Tree::Visitors::Cssize
- Sass::Tree::Visitors::DeepCopy
- Sass::Tree::Visitors::Extend
- Sass::Tree::Visitors::Perform
- Sass::Tree::Visitors::SetOptions
- Sass::Tree::Visitors::ToCss
- Sass::Tree::WarnNode
- Sass::Tree::WhileNode
- Sass::UnitConversionError
- Sass::Util
- Sass::Util::MultibyteStringScanner
- Sass::Util::StaticConditionalContext
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object

No matching classes.

# Sass::Util::SubsetMap

A map from sets to values. A value is {#[]= set} by providing a set (the "set-set") and a value, which is then recorded as corresponding to that set. Values are {#[] accessed} by providing a set (the "get-set") and returning all values that correspond to set-sets that are subsets of the get-set.

SubsetMap preserves the order of values as they're inserted.

@example

    ssm = SubsetMap.new
    ssm[Set[1, 2]] = "Foo"
    ssm[Set[2, 3]] = "Bar"
    ssm[Set[1, 2, 3]] = "Baz"

    ssm[Set[1, 2, 3]] #=> ["Foo", "Bar", "Baz"]

### Public Class Methods

new() click to toggle source

Creates a new, empty SubsetMap.

    # File lib/sass/util/subset_map.rb, line 23
    def initialize
      @hash = {}
      @vals = []
    end

### Public Instance Methods

[](set) click to toggle source

Same as {#get}, but doesn't return the subsets of the argument for which values were found.

@param set [Set] The set to use as the map key. @return [Array] The array of all values

    associated with subsets of `set`, in insertion order.

@see get

    # File lib/sass/util/subset_map.rb, line 96
    def [](set)
      get(set).map {|v, _| v}
    end

[]=(set, value) click to toggle source

Associates a value with a set. When `set` or any of its supersets is accessed, `value` will be among the values returned.

Note that if the same `set` is passed to this method multiple times, all given `value`s will be associated with that `set`.

This runs in `O(n)` time, where `n` is the size of `set`.

@param set [to_set] The set to use as the map key. May not be empty. @param value [Object] The value to associate with `set`. @raise [ArgumentError] If `set` is empty.

    # File lib/sass/util/subset_map.rb, line 47
    def []=(set, value)
      raise ArgumentError.new("SubsetMap keys may not be empty.") if set.empty?

      index = @vals.size
      @vals << value
      set.each do |k|
        @hash[k] ||= []
        @hash[k] << [set, set.to_set, index]
      end
    end

each_value() click to toggle source

Iterates over each value in the subset map. Ignores keys completely. If multiple keys have the same value, this will return them multiple times.

@yield [Object] Each value in the map.

    # File lib/sass/util/subset_map.rb, line 104
    def each_value
      @vals.each {|v| yield v}
    end

empty?() click to toggle source

Whether or not this SubsetMap has any key-value pairs.

@return [Boolean]

    # File lib/sass/util/subset_map.rb, line 31
    def empty?
      @hash.empty?
    end

get(set) click to toggle source

Returns all values associated with subsets of `set`.

In the worst case, this runs in `O(m*max(n, log m))` time, where `n` is the size of `set` and `m` is the number of assocations in the map. However, unless many keys in the map overlap with `set`, `m` will typically be much smaller.

@param set [Set] The set to use as the map key. @return [Array<(Object, to_set)>] An array of pairs,

    where the first value is the value associated with a subset of `set`,
    and the second value is that subset of `set`
    (or whatever `#to_set` object was used to set the value)
    This array is in insertion order.

@see #[]

    # File lib/sass/util/subset_map.rb, line 73
    def get(set)
      res = set.map do |k|
        next unless subsets = @hash[k]
        subsets.map do |subenum, subset, index|
          next unless subset.subset?(set)
          [index, subenum]
        end
      end
      res = Sass::Util.flatten(res, 1)
      res.compact!
      res.uniq!
      res.sort!
      res.map! {|i, s| [@vals[i], s]}
      return res
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.