Module: Police::DataFlow::Labeling
- Defined in:
- lib/police/dataflow/labeling.rb
Overview
Label algebra.
Class Method Summary collapse
-
.add_label_to_set(label, label_set) ⇒ Boolean
Adds a label to the set of labels held by an object’s proxy.
-
.bulk_sticky_label(data, sticky_set) ⇒ BasicObject
Applies sticky labels to a piece of data.
-
.dup_set(label_set) ⇒ Hash<Integer,Hash<Police::DataFlow::Label,Boolean>>
Creates a shallow copy of a label set.
-
.merge_sets!(target_set, source_set) ⇒ Boolean
Merges a set of labels into another set.
-
.proxy_class(data) ⇒ Class
The actual class of a proxy object.
Class Method Details
.add_label_to_set(label, label_set) ⇒ Boolean
Adds a label to the set of labels held by an object’s proxy.
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/police/dataflow/labeling.rb', line 70 def self.add_label_to_set(label, label_set) label_class = label.class label_key = label_class.__id__ if label_set.has_key? label_key label_set[label_key][label] = true return false end label_entry = { label => true } label_set[label_key] = label_entry true end |
.bulk_sticky_label(data, sticky_set) ⇒ BasicObject
Applies sticky labels to a piece of data.
This is an version of Police::DataFlow.label optimized for sticky label propagation. User code should not depend on it.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/police/dataflow/labeling.rb', line 120 def self.bulk_sticky_label(data, sticky_set) label_set = data.__police_labels__ if nil == label_set # Unlabeled data. return Police::DataFlow::.proxy(data, dup_set(sticky_set)) end # TODO(pwnall): implement copy-on-write to waste less memory on gated ops if merge_sets! label_set, sticky_set Police::DataFlow::.proxy data.__police_proxied__, label_set else data end end |
.dup_set(label_set) ⇒ Hash<Integer,Hash<Police::DataFlow::Label,Boolean>>
Creates a shallow copy of a label set.
The resulting copy is slightly deeper than what Hash#clone would produce, because the groups are copied as well.
145 146 147 |
# File 'lib/police/dataflow/labeling.rb', line 145 def self.dup_set(label_set) Hash[label_set.map { |k, v| [k, v.dup] } ] end |
.merge_sets!(target_set, source_set) ⇒ Boolean
Merges a set of labels into another set.
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/police/dataflow/labeling.rb', line 93 def self.merge_sets!(target_set, source_set) = false source_set.each do |class_id, label_classes| target_classes = target_set[class_id] if nil == target_classes target_set[class_id] = label_classes.dup = true else target_classes.merge! label_classes end end end |
.proxy_class(data) ⇒ Class
The actual class of a proxy object.
This is necessary because the class method for a proxy object must return the proxied object’s class.
This is intended to help testing the proxying code. It should not be used by client code.
54 55 56 57 58 59 60 |
# File 'lib/police/dataflow/labeling.rb', line 54 def self.proxy_class(data) if data.__police_labels__.nil? nil else data.__police_class__ end end |