class Space<T> : IEnumerable<Space<T>> {
public T Filler {
get {
if (!ed) {
ed = true;
return (filler = Top.create());
}
return filler;
}
}
public Space<T> Upper { get; private set; }
public Space<T> Top => Upper?.Top ?? this; private bool ed;
private Func<T> create;
private T filler;
public int[] Chain { get; set; }
public int[] Dementions { get; }
Space<T>[] all; public Space(Func<T> create, int i, params int[] indexes) : this(new int[], new[] { i }.Concat(indexes).ToArray()) {
this.create = create;
} private Space(int[] chain, params int[] indexes) {
Chain = chain;
Dementions = indexes;
var i = indexes[];
all = new Space<T>[i];
var chains = Enumerable.Range(, i).Select(e => chain.Concat(new int[] { e }).ToArray()).ToArray();
if (indexes.Length == ) {
while (i-- > ) {
all[i] = new Space<T>(chains[i]);
all[i].Upper = this;
}
} else {
var _indexes = indexes.Skip().ToArray();
while (i-- > ) {
all[i] = new Space<T>(chains[i], _indexes);
all[i].Upper = this;
}
}
} private Space(int[] chain) {
Chain = chain;
} public Space<T> this[int i, params int[] indexes] {
get {
if (all == null) {
return (Filler as Space<T>)?[i, indexes];
}
if (indexes.Length == ) {
return all[i];
}
if (indexes.Length == ) {
return all[i][indexes[]];
}
return all[i][indexes[], indexes.Skip().ToArray()];
}
} public override string ToString() {
return all?.Aggregate(string.Empty, (a, s) => a + s + ',').Trim(',') ?? Filler.ToString();
} public override bool Equals(object obj) {
if (GetType() != obj?.GetType()) {
return false;
}
return GetHashCode() == obj.GetHashCode();
} public override int GetHashCode() {
if (Upper == null) {
return base.GetHashCode();
}
return Top.GetHashCode() - Chain.GetHashCode();
} public IEnumerator<Space<T>> GetEnumerator() {
return ((IEnumerable<Space<T>>)all).GetEnumerator();
} IEnumerator IEnumerable.GetEnumerator() {
return ((IEnumerable<Space<T>>)all).GetEnumerator();
}
}

自定义泛型N维空间数组的更多相关文章

  1. 自定义N维空间数组

    class Space : IEnumerable<Space> { public object Filler { get { return filler ?? (filler = Top ...

  2. typescript多维对象数组仿List泛型

    定义对象: namespace entity{ export class MyClass{ public value:number; public rect:string; public constr ...

  3. java JDK8 学习笔记——第18章 自定义泛型、枚举与注释

    第十八章 自定义泛型.枚举与注释 18.1 自定义泛型 泛型定义: (1)仅定义在方法上的泛型语法 (2)用来限制泛型可用类型的extends与super关键字(3)?类型通配字符的使用 18.1.1 ...

  4. .NET基础之自定义泛型

    在.NET中泛型使用非常频繁,在控制台应用程序中,默认的引入了System.Collection.Generics名称空间,其中就提供了我们经常使用的泛型:List<T>和Dictiona ...

  5. net 自定义泛型那点事

    泛型概述 泛型是程序设计语言的一种特性.允许程序员在强类型程序设计语言中编写代码时定义一些可变部分,那些部分在使用前必须作出指明.各种程序设计语言和其编译器.运行环境对泛型的支持均不一样.将类型参数化 ...

  6. 分配一维动态数组or 二维动态数组的方法以及学习 new 方法or vector

    先来个开胃菜 // 使用new动态分配存储空间 #include<iostream> using std::cout; int main() { // 第1种方式 int *a=new i ...

  7. Net is as typeof 运行运算符详解 net 自定义泛型那点事

    Net is as typeof 运行运算符详解   概述 在了解运行运算符的前提我们需要了解什么是RTTI ,在任何一门面向对象的语言中,都有RTTI这个概念(即 运行时). RTTI(Run-Ti ...

  8. [转载]C++二维动态数组memset()函数初始化

    来源:https://blog.csdn.net/longhopefor/article/details/20994919 先说说memset函数: void *memset(void *s,int ...

  9. JAVA基础_自定义泛型

    泛型的来源 在Java中,泛型借鉴了C++的模版函数,从而引入了泛型. C++泛型 int add(int x,int y){ return x + y; } float add(float x.fl ...

随机推荐

  1. select2插件的使用

    <select id="prd_tech_for_load" class="selectable" style="width:180px;&qu ...

  2. Solr6.2.0 + zookeeper 集群配置

    zookeeper1 : 192.168.1.103zookeeper2 : 192.168.1.104zookeeper3 : 192.168.1.105solr1 : 192.168.1.106s ...

  3. Apache Commons 工具集

    一.Commons BeanUtils http://jakarta.apache.org/commons/beanutils/index.html 说明:针对Bean的一个工具集.由于Bean往往是 ...

  4. 匹配所有不可见元素,或者type为hidden的元素

    查找隐藏的 tr HTML 代码: <table> <tr style="display:none"><td>Value 1</td> ...

  5. android第三方登陆

    实现QQ.微信.新浪微博和百度第三方登录(Android Studio) 前言: 对于大多数的APP都有第三方登录这个功能,自己也做过几次,最近又有一个新项目用到了第三方登录,所以特意总结了一下关于第 ...

  6. 虚拟主机无法使用fsockopen操作处理方法

    一.如何禁用fsockopen()下面是两种常用的禁用fsockopen的方法.1.修改php.ini,将 disable_functions = 后加入 fsockopen2.修改php.ini,将 ...

  7. Android 网络请求库volley的封装,让请求更方便

    首先封装一下volley 请求 public class CustomRequest extends StringRequest { private static final String TAG = ...

  8. CSS 笔记二(Text/Fonts/Links/Lists)

    CSS Text 1> Text Color used to set the color of the text 2> Text Alignment used to set the hor ...

  9. 利用ksoap调用webservice

    博文参考: http://www.cnblogs.com/shenliang123/archive/2012/07/05/2578586.html http://blog.csdn.net/jimbo ...

  10. treegrid and datagrid ctrl or shift selectRow

    var tg = $('#tg');tg.treegrid({...}); // create treegridvar panel = tg.treegrid('getPanel');var body ...