mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Allow SubsetMap to use non-Set keys.
This commit is contained in:
parent
c07cd09adf
commit
dcc1721dab
1 changed files with 7 additions and 6 deletions
|
@ -41,7 +41,7 @@ module Haml
|
||||||
#
|
#
|
||||||
# This runs in `O(n)` time, where `n` is the size of `set`.
|
# This runs in `O(n)` time, where `n` is the size of `set`.
|
||||||
#
|
#
|
||||||
# @param set [Set] The set to use as the map key. May not be empty.
|
# @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`.
|
# @param value [Object] The value to associate with `set`.
|
||||||
# @raise [ArgumentError] If `set` is empty.
|
# @raise [ArgumentError] If `set` is empty.
|
||||||
def []=(set, value)
|
def []=(set, value)
|
||||||
|
@ -51,7 +51,7 @@ module Haml
|
||||||
@vals << value
|
@vals << value
|
||||||
set.each do |k|
|
set.each do |k|
|
||||||
@hash[k] ||= []
|
@hash[k] ||= []
|
||||||
@hash[k] << [set, index]
|
@hash[k] << [set, set.to_set, index]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,17 +64,18 @@ module Haml
|
||||||
# `m` will typically be much smaller.
|
# `m` will typically be much smaller.
|
||||||
#
|
#
|
||||||
# @param set [Set] The set to use as the map key.
|
# @param set [Set] The set to use as the map key.
|
||||||
# @return [Array<(Object, Set)>] An array of pairs,
|
# @return [Array<(Object, #to_set)>] An array of pairs,
|
||||||
# where the first value is the value associated with a subset of `set`,
|
# where the first value is the value associated with a subset of `set`,
|
||||||
# and the second value is that 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.
|
# This array is in insertion order.
|
||||||
# @see #[]
|
# @see #[]
|
||||||
def get(set)
|
def get(set)
|
||||||
res = set.map do |k|
|
res = set.map do |k|
|
||||||
next unless subsets = @hash[k]
|
next unless subsets = @hash[k]
|
||||||
subsets.map do |subset, index|
|
subsets.map do |subenum, subset, index|
|
||||||
next unless subset.subset?(set)
|
next unless subset.subset?(set)
|
||||||
[index, subset]
|
[index, subenum]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
res.flatten!(1)
|
res.flatten!(1)
|
||||||
|
|
Loading…
Add table
Reference in a new issue