sass-site/source/documentation/Sass/Util/SubsetMap.html
2018-10-22 14:13:05 -07:00

852 lines
24 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
Class: Sass::Util::SubsetMap
&mdash; Documentation by YARD 0.9.12
</title>
<link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="../../../assets/css/docs.css" type="text/css" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
hasFrames = window.top.frames.main ? true : false;
relpath = '../../';
framesUrl = "../../frames.html#!Sass/Util/SubsetMap.html";
</script>
<script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>
</head>
<body>
<div id="header">
<div id="menu">
<a href="../../_index.html">Index (S)</a> &raquo;
<span class='title'><span class='object_link'><a href="../../Sass.html" title="Sass (module)">Sass</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Util.html" title="Sass::Util (module)">Util</a></span></span>
&raquo;
<span class="title">SubsetMap</span>
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="../../class_list.html">
Class List
</a>
<a class="full_list_link" id="method_list_link"
href="../../method_list.html">
Method List
</a>
<a class="full_list_link" id="file_list_link"
href="../../file_list.html">
File List
</a>
</div>
<div class="clear"></div>
</div>
<iframe id="search_frame"></iframe>
<div id="content"><h1>Class: Sass::Util::SubsetMap
</h1>
<dl class="box">
<dt class="r1">Inherits:</dt>
<dd class="r1">
<span class="inheritName">Object</span>
<ul class="fullTree">
<li>Object</li>
<li class="next">Sass::Util::SubsetMap</li>
</ul>
<a href="#" class="inheritanceTree">show all</a>
</dd>
<dt class="r2 last">Defined in:</dt>
<dd class="r2 last">.ruby-sass/lib/sass/util/subset_map.rb</dd>
</dl>
<div class="clear"></div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>A map from sets to values. A value is <span class='object_link'><a href="#[]=-instance_method" title="Sass::Util::SubsetMap#[]= (method)">set</a></span> by providing a set (the
“set-set”) and a value, which is then recorded as corresponding to that
set. Values are <span class='object_link'><a href="#[]-instance_method" title="Sass::Util::SubsetMap#[] (method)">accessed</a></span> by providing a set (the “get-set”) and
returning all values that correspond to set-sets that are subsets of the
get-set.</p>
<p>SubsetMap preserves the order of values as they&#39;re inserted.</p>
</div>
</div>
<div class="tags">
<div class="examples">
<p class="tag_title">Examples:</p>
<pre class="example code"><code><span class='id identifier rubyid_ssm'>ssm</span> <span class='op'>=</span> <span class='const'>SubsetMap</span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="#initialize-instance_method" title="Sass::Util::SubsetMap#initialize (method)">new</a></span></span>
<span class='id identifier rubyid_ssm'>ssm</span><span class='lbracket'>[</span><span class='const'>Set</span><span class='lbracket'>[</span><span class='int'>1</span><span class='comma'>,</span> <span class='int'>2</span><span class='rbracket'>]</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Foo</span><span class='tstring_end'>&quot;</span></span>
<span class='id identifier rubyid_ssm'>ssm</span><span class='lbracket'>[</span><span class='const'>Set</span><span class='lbracket'>[</span><span class='int'>2</span><span class='comma'>,</span> <span class='int'>3</span><span class='rbracket'>]</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Bar</span><span class='tstring_end'>&quot;</span></span>
<span class='id identifier rubyid_ssm'>ssm</span><span class='lbracket'>[</span><span class='const'>Set</span><span class='lbracket'>[</span><span class='int'>1</span><span class='comma'>,</span> <span class='int'>2</span><span class='comma'>,</span> <span class='int'>3</span><span class='rbracket'>]</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Baz</span><span class='tstring_end'>&quot;</span></span>
<span class='id identifier rubyid_ssm'>ssm</span><span class='lbracket'>[</span><span class='const'>Set</span><span class='lbracket'>[</span><span class='int'>1</span><span class='comma'>,</span> <span class='int'>2</span><span class='comma'>,</span> <span class='int'>3</span><span class='rbracket'>]</span><span class='rbracket'>]</span> <span class='comment'>#=&gt; [&quot;Foo&quot;, &quot;Bar&quot;, &quot;Baz&quot;]</span></code></pre>
</div>
</div>
<h2>
Instance Method Summary
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
</h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#[]-instance_method" title="#[] (instance method)">#<strong>[]</strong>(set) &#x21d2; Array </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Same as <span class='object_link'><a href="#get-instance_method" title="Sass::Util::SubsetMap#get (method)">#get</a></span>, but doesn&#39;t return the subsets of the argument for
which values were found.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#[]=-instance_method" title="#[]= (instance method)">#<strong>[]=</strong>(set, value) &#x21d2; Object </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Associates a value with a set.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#each_value-instance_method" title="#each_value (instance method)">#<strong>each_value</strong> {|Object| ... } &#x21d2; Object </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Iterates over each value in the subset map.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#empty%3F-instance_method" title="#empty? (instance method)">#<strong>empty?</strong> &#x21d2; Boolean </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Whether or not this SubsetMap has any key-value pairs.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#get-instance_method" title="#get (instance method)">#<strong>get</strong>(set) &#x21d2; Array&lt;(Object, #to_set)&gt; </a>
</span>
<span class="summary_desc"><div class='inline'>
<p>Returns all values associated with subsets of `set`.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong> &#x21d2; SubsetMap </a>
</span>
<span class="note title constructor">constructor</span>
<span class="summary_desc"><div class='inline'>
<p>Creates a new, empty SubsetMap.</p>
</div></span>
</li>
</ul>
<div id="constructor_details" class="method_details_list">
<h2>Constructor Details</h2>
<div class="method_details first">
<h3 class="signature first" id="initialize-instance_method">
#<strong>initialize</strong> &#x21d2; <tt><span class='object_link'><a href="" title="Sass::Util::SubsetMap (class)">SubsetMap</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Creates a new, empty SubsetMap.</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
23
24
25
26</pre>
</td>
<td>
<pre class="code"><span class="info file"># File '.ruby-sass/lib/sass/util/subset_map.rb', line 23</span>
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span>
<span class='ivar'>@hash</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
<span class='ivar'>@vals</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
<div id="constructor_details" class="method_details_list">
<h2>Constructor Details</h2>
<div class="method_details first">
<h3 class="signature first" id="initialize-instance_method">
#<strong>initialize</strong> &#x21d2; <tt><span class='object_link'><a href="" title="Sass::Util::SubsetMap (class)">SubsetMap</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Creates a new, empty SubsetMap.</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
23
24
25
26</pre>
</td>
<td>
<pre class="code"><span class="info file"># File '.ruby-sass/lib/sass/util/subset_map.rb', line 23</span>
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span>
<span class='ivar'>@hash</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
<span class='ivar'>@vals</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
<div id="instance_method_details" class="method_details_list">
<h2>Instance Method Details</h2>
<div class="method_details first">
<h3 class="signature first" id="[]-instance_method">
#<strong>[]</strong>(set) &#x21d2; <tt>Array</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Same as <span class='object_link'><a href="#get-instance_method" title="Sass::Util::SubsetMap#get (method)">#get</a></span>, but doesn&#39;t return the subsets of the argument for
which values were found.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>set</span>
<span class='type'>(<tt>Set</tt>)</span>
&mdash;
<div class='inline'>
<p>The set to use as the map key.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Array</tt>)</span>
&mdash;
<div class='inline'>
<p>The array of all values associated with subsets of `set`, in insertion
order.</p>
</div>
</li>
</ul>
<p class="tag_title">See Also:</p>
<ul class="see">
<li><span class='object_link'><a href="#get-instance_method" title="Sass::Util::SubsetMap#get (method)">#get</a></span></li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
96
97
98</pre>
</td>
<td>
<pre class="code"><span class="info file"># File '.ruby-sass/lib/sass/util/subset_map.rb', line 96</span>
<span class='kw'>def</span> <span class='op'>[]</span><span class='lparen'>(</span><span class='id identifier rubyid_set'>set</span><span class='rparen'>)</span>
<span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='id identifier rubyid_set'>set</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_v'>v</span><span class='comma'>,</span> <span class='id identifier rubyid__'>_</span><span class='op'>|</span> <span class='id identifier rubyid_v'>v</span><span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="[]=-instance_method">
#<strong>[]=</strong>(set, value) &#x21d2; <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Associates a value with a set. When `set` or any of its supersets is
accessed, `value` will be among the values returned.</p>
<p>Note that if the same `set` is passed to this method multiple times, all
given `value`s will be associated with that `set`.</p>
<p>This runs in `O(n)` time, where `n` is the size of `set`.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>set</span>
<span class='type'>(<tt>#to_set</tt>)</span>
&mdash;
<div class='inline'>
<p>The set to use as the map key. May not be empty.</p>
</div>
</li>
<li>
<span class='name'>value</span>
<span class='type'>(<tt>Object</tt>)</span>
&mdash;
<div class='inline'>
<p>The value to associate with `set`.</p>
</div>
</li>
</ul>
<p class="tag_title">Raises:</p>
<ul class="raise">
<li>
<span class='type'>(<tt>ArgumentError</tt>)</span>
&mdash;
<div class='inline'>
<p>If `set` is empty.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
47
48
49
50
51
52
53
54
55
56</pre>
</td>
<td>
<pre class="code"><span class="info file"># File '.ruby-sass/lib/sass/util/subset_map.rb', line 47</span>
<span class='kw'>def</span> <span class='op'>[]=</span><span class='lparen'>(</span><span class='id identifier rubyid_set'>set</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>SubsetMap keys may not be empty.</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_set'>set</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
<span class='id identifier rubyid_index'>index</span> <span class='op'>=</span> <span class='ivar'>@vals</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span>
<span class='ivar'>@vals</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_value'>value</span>
<span class='id identifier rubyid_set'>set</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='op'>|</span>
<span class='ivar'>@hash</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
<span class='ivar'>@hash</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='rbracket'>]</span> <span class='op'>&lt;&lt;</span> <span class='lbracket'>[</span><span class='id identifier rubyid_set'>set</span><span class='comma'>,</span> <span class='id identifier rubyid_set'>set</span><span class='period'>.</span><span class='id identifier rubyid_to_set'>to_set</span><span class='comma'>,</span> <span class='id identifier rubyid_index'>index</span><span class='rbracket'>]</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="each_value-instance_method">
#<strong>each_value</strong> {|Object| ... } &#x21d2; <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Iterates over each value in the subset map. Ignores keys completely. If
multiple keys have the same value, this will return them multiple times.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Yields:</p>
<ul class="yield">
<li>
<span class='type'>(<tt>Object</tt>)</span>
&mdash;
<div class='inline'>
<p>Each value in the map.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
104
105
106</pre>
</td>
<td>
<pre class="code"><span class="info file"># File '.ruby-sass/lib/sass/util/subset_map.rb', line 104</span>
<span class='kw'>def</span> <span class='id identifier rubyid_each_value'>each_value</span>
<span class='ivar'>@vals</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='kw'>yield</span> <span class='id identifier rubyid_v'>v</span><span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="empty?-instance_method">
#<strong>empty?</strong> &#x21d2; <tt>Boolean</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Whether or not this SubsetMap has any key-value pairs.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Boolean</tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
31
32
33</pre>
</td>
<td>
<pre class="code"><span class="info file"># File '.ruby-sass/lib/sass/util/subset_map.rb', line 31</span>
<span class='kw'>def</span> <span class='id identifier rubyid_empty?'>empty?</span>
<span class='ivar'>@hash</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="get-instance_method">
#<strong>get</strong>(set) &#x21d2; <tt>Array&lt;(Object, #to_set)&gt;</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Returns all values associated with subsets of `set`.</p>
<p>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 associations in the map. However,
unless many keys in the map overlap with `set`, `m` will typically be much
smaller.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>set</span>
<span class='type'>(<tt>Set</tt>)</span>
&mdash;
<div class='inline'>
<p>The set to use as the map key.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Array&lt;(Object, #to_set)&gt;</tt>)</span>
&mdash;
<div class='inline'>
<p>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.</p>
</div>
</li>
</ul>
<p class="tag_title">See Also:</p>
<ul class="see">
<li><span class='object_link'><a href="#[]-instance_method" title="Sass::Util::SubsetMap#[] (method)">#[]</a></span></li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87</pre>
</td>
<td>
<pre class="code"><span class="info file"># File '.ruby-sass/lib/sass/util/subset_map.rb', line 73</span>
<span class='kw'>def</span> <span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='id identifier rubyid_set'>set</span><span class='rparen'>)</span>
<span class='id identifier rubyid_res'>res</span> <span class='op'>=</span> <span class='id identifier rubyid_set'>set</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='op'>|</span>
<span class='id identifier rubyid_subsets'>subsets</span> <span class='op'>=</span> <span class='ivar'>@hash</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='rbracket'>]</span>
<span class='kw'>next</span> <span class='kw'>unless</span> <span class='id identifier rubyid_subsets'>subsets</span>
<span class='id identifier rubyid_subsets'>subsets</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_subenum'>subenum</span><span class='comma'>,</span> <span class='id identifier rubyid_subset'>subset</span><span class='comma'>,</span> <span class='id identifier rubyid_index'>index</span><span class='op'>|</span>
<span class='kw'>next</span> <span class='kw'>unless</span> <span class='id identifier rubyid_subset'>subset</span><span class='period'>.</span><span class='id identifier rubyid_subset?'>subset?</span><span class='lparen'>(</span><span class='id identifier rubyid_set'>set</span><span class='rparen'>)</span>
<span class='lbracket'>[</span><span class='id identifier rubyid_index'>index</span><span class='comma'>,</span> <span class='id identifier rubyid_subenum'>subenum</span><span class='rbracket'>]</span>
<span class='kw'>end</span>
<span class='kw'>end</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='lparen'>(</span><span class='int'>1</span><span class='rparen'>)</span>
<span class='id identifier rubyid_res'>res</span><span class='period'>.</span><span class='id identifier rubyid_compact!'>compact!</span>
<span class='id identifier rubyid_res'>res</span><span class='period'>.</span><span class='id identifier rubyid_uniq!'>uniq!</span>
<span class='id identifier rubyid_res'>res</span><span class='period'>.</span><span class='id identifier rubyid_sort!'>sort!</span>
<span class='id identifier rubyid_res'>res</span><span class='period'>.</span><span class='id identifier rubyid_map!'>map!</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_i'>i</span><span class='comma'>,</span> <span class='id identifier rubyid_s'>s</span><span class='op'>|</span> <span class='lbracket'>[</span><span class='ivar'>@vals</span><span class='lbracket'>[</span><span class='id identifier rubyid_i'>i</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_s'>s</span><span class='rbracket'>]</span><span class='rbrace'>}</span>
<span class='id identifier rubyid_res'>res</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
Generated on Mon Oct 22 13:21:00 2018 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.12 (ruby-2.5.3).
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-535380-14', 'sass-lang.com');
ga('send', 'pageview');
</script>
</body>
</html>