.net collection tips
1.数组对象都是Array的子类,Array是一个抽象类,不能显示实例化,Array提供了大量操作数组的静态方法
2.ArrayList其实是内部封装了一个array,实现了IList的接口。add remove在内部还是调用array的方法。
于Array最大的区别是,ArrayList的长度是自管理的,Array的长度是固定的。
3.synclist本质上还是用lock操作icollect的syncroot System.Threading.Interlocked.CompareExchange<Object>(ref _syncRoot, new Object(), null);
4.arraylist提供了ilist的一些功能。为什么是在arraylist中提供呢?比如封装一个ReadOnly的list,封装一个FixedSize的list,封装一个Synchronized的list
也就是针对ilist的IsFixedSize和IsReadOnly还有icollection的IsReadOnly的属性,都提供了一个额外的类
但arraylist也针对自身封装了ReadOnly的arraylist,封装了FixedSize的arraylist和Synchronized的arraylist
arraylist还提供了一个list到arraylist的adapter功能
5.对于一个synchronized的arraylist,任何一个方法都是lock的,包括查询方法也是。
对于一个synchronized的ilist,任何一个方法都是lock的,包括查询方法也是。
6.对于一个FixedSize的arraylist,任何可能导致长度变化的方法都会抛出异常
7.List.GetRange返回的arraylist是原arralist的一部分,对该arraylist操作会影响到原arraylist
8.version每次在数据有变化的时候都会自增加一,这样在通过Enumerator遍历的时候进行核对。
9.IDictionary中的GetEnumerator是一个new接口,和IEnumerable不一样
10.DictionaryEntry是dictionary转换到array用的,array就是entry的数组,entry的key value是可读写的。
KeyValuePair是dictionary遍历用的。KeyValuePair的key value是只读的。
11.HashTable的本质也还是一个数组,不过数组对象是一个内部的bucket
HashTable的长度是预定定义好一些数字,然后根据算法从数字中找到一个合适的。
12.泛型List只是提供了synch的封装,没有对应的fixedsizelist和readonlylist
13.泛型stack queue linkedlist sortedlist sortedset storeddictionary都是属于sys的扩展
14.linkedlist是闭环的双向链表
15.SortedSet是用红黑树实现的,SortedDictionary是基于sortedset实现的
16.Dictionary的实现
int[] buckets, Entry[] entries
查找:根据key的hash算法得到一个index,取得buckets[index]的值,假设为bucketIndex,
如果bucketIndex不为空,检索entries[bucketIndex](根据key和hash判断)是否是所要查找对象,如果是则返回。
即是说,在不冲突的情况下,buckets存放的是真实的entry在entries中的索引!
如果冲突的话,根据entries[bucketIndex]的next得到下一个bucketIndex,再次检索,知道next的属性为零。
插入:创建一个entry保存数据然后存入到entries中,得到这个entry在entries中的索引entryIndex,
然后根据key的hash算法得到一个index,取得buckets[index]的值,假设为bucketIndex,
如果bucketIndex为空,则buckets[index]=entryIndex;
如果bucketIndex,不为空,则entry.next=bucketIndex; buckets[index]=entryIndex;
删除:链表的删除
本质上还是链表法处理hash冲突,一般的链表法是一个hash对应一个链表,而.net中是用唯一的一个entries数据处理所有的链表。非常巧妙!
插入了n个entry后,entries中一定有n个数据,但buckets中不一定存有n个数据,因为hash可能冲突,但buckets的数据个数一定是小于n的
.net collection tips的更多相关文章
- Unity性能优化(3)-官方教程Optimizing garbage collection in Unity games翻译
本文是Unity官方教程,性能优化系列的第三篇<Optimizing garbage collection in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...
- Unity优化方向——优化Unity游戏中的垃圾回收(译)
介绍 当我们的游戏运行时,它使用内存来存储数据.当不再需要该数据时,存储该数据的内存将被释放,以便可以重用.垃圾是用来存储数据但不再使用的内存的术语.垃圾回收是该内存再次可用以进行重用的进程的名称. ...
- Simple Tips for Collection in Python
I believe that the following Python code is really not hard to understand. But I think we should use ...
- Tips collection of iOS development
<转>UITableView当数据很少的时候,去掉多余的cell分割线 在tableView初始化的时候 UIView *v = [[UIViewalloc] initWithFram ...
- android 官方文档 JNI TIPS
文章地址 http://developer.android.com/training/articles/perf-jni.html JNI Tips JNI is the Java Native I ...
- Matlab tips and tricks
matlab tips and tricks and ... page overview: I created this page as a vectorization helper but it g ...
- 【转】必需知道的 SharePoint 权限 Tips
SharePoint Tips about Permissions: What you need to know I have been writing tips about Shar ...
- 10个加速Table Views开发的Tips(转)
本文由CocoaChina译者yake_099(博客)翻译,作者:David McGraw原文:10 Actionable Performance Tips To Speed Up Your Tabl ...
- Java Tips and Best practices to avoid NullPointerException
A NullPointerException in Java application is best way to solve it and that is also key to write rob ...
随机推荐
- 2017 ACM/ICPC Asia Regional Shenyang Online array array array
2017-09-15 21:05:41 writer:pprp 给出一个序列问能否去掉k的数之后使得整个序列不是递增也不是递减的 先求出LIS,然后倒序求出最长递减子序列长度,然后判断去k的数后长度是 ...
- 解题报告:hdu1013 Digital Roots
2017-09-07 22:02:01 writer:pprp 简单的水题,但是需要对最初的部分进行处理,防止溢出 /* @theme: hdu 1013 Digital roots @writer: ...
- C# Memcached 缓存
之前做的功能,程序可能有不足之处,但还是要记录下 ICacheStrategy.cs文件 public interface ICacheStrategy { /// <summary> / ...
- SSH密钥登陆免密码方法
原帖地址:http://ask.apelearn.com/question/798 用Putty实现A机器远程登陆B机器,具体实现请看链接:http://www.cnblogs.com/ImJerry ...
- 最简js深浅拷贝说明
1.浅拷贝 浅拷贝是拷贝引用,拷贝后的引用都是指向同一个对象的实例,彼此之间的操作会互相影响. 浅拷贝分两种情况: 1.直接拷贝源对象的引用 2. 源对象拷贝实例,但其属性对象(类型为Object, ...
- 在activity之间传递数据
在activity之间传递数据 一.简介 二.通过intent传递数据 1.在需要传数据的界面调用 intent.putExtra("data1", "我是fry&quo ...
- Mysql(基础篇)
linux下的mysql操作 1.# 打开 MySQL 服务 sudo service mysql start 2.#使用 root 用户登录,密码为空 mysql -u root 3.创建数据库 C ...
- linux正则表达式回忆记录
好久没用linux grep相关正则表达式,现在简单记录下. grep简介 grep 是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来.通常grep有三种版本grep.egr ...
- jdk动态代理使用及原理
jdk动态代理的使用 1.创建实现InvocationHandler接口的类,实现invoke(Object proxy, Method method, Object[] args)接口,其中invo ...
- Error:Cannot access first() element from an empty List
解决方案: bintray版本问题,修改为: classpath 'com.novoda:bintray-release:0.3.4' 如下: buildscript { repositories { ...