attributes.dart 642 B

1234567891011121314151617181920212223
  1. typedef Attributes = Map<String, dynamic>;
  2. int hashAttributes(Attributes attributes) {
  3. return Object.hashAllUnordered(
  4. attributes.entries.map((e) => Object.hash(e.key, e.value)));
  5. }
  6. Attributes invertAttributes(Attributes? attr, Attributes? base) {
  7. attr ??= {};
  8. base ??= {};
  9. final Attributes baseInverted = base.keys.fold({}, (memo, key) {
  10. if (base![key] != attr![key] && attr.containsKey(key)) {
  11. memo[key] = base[key];
  12. }
  13. return memo;
  14. });
  15. return attr.keys.fold(baseInverted, (memo, key) {
  16. if (attr![key] != base![key] && base.containsKey(key)) {
  17. memo[key] = null;
  18. }
  19. return memo;
  20. });
  21. }