EnumerableInfo.vala 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. namespace Invercargill {
  2. public class EnumerableInfo {
  3. public int? count { get; private set; }
  4. public Type enumerable_type { get; private set; }
  5. public Type element_type { get; private set; }
  6. public EnumerableCategory category { get; private set; }
  7. public Enumerable<EnumerableInfo> sources { get; private set; }
  8. public Enumerable<EnumerableInfo> ultimate_sources { get; private set; }
  9. public EnumerableInfo(int? count, Type enumerable_type, Type value_type, EnumerableCategory category, ReadOnlyCollection<EnumerableInfo> sources, Enumerable<EnumerableInfo> ultimate_sources) {
  10. this.count = count;
  11. this.enumerable_type = enumerable_type;
  12. this.element_type = value_type;
  13. this.category = category;
  14. this.sources = sources;
  15. this.ultimate_sources = ultimate_sources.cache();
  16. }
  17. public EnumerableInfo.infer(Enumerable enumerable, EnumerableCategory category, Enumerable<Enumerable> sources) {
  18. this.count = enumerable.peek_count();
  19. this.enumerable_type = enumerable.get_type();
  20. this.element_type = enumerable.element_type;
  21. this.category = category;
  22. this.sources = sources.select<EnumerableInfo>(s => s.get_info()).to_series().seal();
  23. this.ultimate_sources = this.sources
  24. .where(s => s.ultimate_sources.no())
  25. .concat(this.sources.select_many(s => s.ultimate_sources));
  26. }
  27. public EnumerableInfo.infer_single(Enumerable enumerable, EnumerableCategory category, Enumerable source) {
  28. this.count = enumerable.peek_count();
  29. this.enumerable_type = enumerable.get_type();
  30. this.element_type = enumerable.element_type;
  31. this.category = category;
  32. var source_info = source.get_info();
  33. this.sources = single(source_info);
  34. this.ultimate_sources = source_info.sources.any() ? source_info.ultimate_sources : single(source_info);
  35. }
  36. public EnumerableInfo.infer_ultimate(Enumerable enumerable, EnumerableCategory category) {
  37. this.count = enumerable.peek_count();
  38. this.enumerable_type = enumerable.get_type();
  39. this.element_type = enumerable.element_type;
  40. this.category = category;
  41. this.sources = empty<EnumerableInfo>();
  42. this.ultimate_sources = this.sources;
  43. }
  44. }
  45. public enum EnumerableCategory {
  46. IN_MEMORY,
  47. EXTERNAL,
  48. COMPUTED,
  49. CACHED,
  50. PROXY;
  51. }
  52. }