快速查询List中指定的数据
| (1,1) (xIndex,yIndex) | (2,1) | (3,1) | (。。。,。。。) |
| (1,2) | (2,2) | (3,2) | (。。。,。。。) |
| (1,3) | (2,3) | (3,3) | (。。。,。。。) |
| (。。。,。。。) | (。。。,。。。) | (。。。,。。。) | (10000,50) |



.png)
//传统遍历
var objPoints = from b in listPoints where b.xIndex == Convert.ToInt32(this.tbX.Text.Trim().ToString()) select b;
foreach (var item in objPoints)
{
showPoints(item); //显示当前点的text属性值;
}
hsTemp.Clear();//清空哈希表
int TempCount = listPoints.Count;
; i < TempCount; i++)
{
if (hsTemp.ContainsKey(listPoints[i].xIndex.ToString()))//如果哈希表中存在key值
{
hsTemp[listPoints[i].xIndex.ToString()] += "," + i.ToString();//这里和数组结构类似,改变索引值对应的value值信息
}
else
{
hsTemp.Add(listPoints[i].xIndex.ToString(), i);
}
}
this.richTextBox1.Text = "新方法查询结果:\n";
//objPonit = new MyPoint();
string currentPX = this.tbX.Text.Trim().ToString();
if (listPoints != null && currentPX != null)
{
int TempCount = listPoints.Count;
&& hsTemp.Count <= )//如果list中有数据而哈希表中却没有数据
{
FlushTempIndex();
}
if (hsTemp.ContainsKey(currentPX))
{
string[] arrTempIndex = hsTemp[currentPX].ToString().Split(',');//可以直接将分好的数据放到数组中去
int TempIndexCount = arrTempIndex.Length;
;
; i < TempIndexCount; i++)
{
if (int.TryParse(arrTempIndex[i], out TempIndex) && TempIndex < TempCount)
{
showPoints(listPoints[TempIndex]);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 快速查询数据.Models
{
public class MyPoint
{
public int xIndex { get; set; }
public int yIndex { get; set; }
public string text { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using 快速查询数据.Models;
using System.Collections;
namespace 快速查询数据
{
public partial class Form1 : Form
{
List<MyPoint> listPoints = new List<MyPoint>();
private Hashtable hsTemp = new Hashtable();
MyPoint objPonit = null;
public Form1()
{
InitializeComponent();
this.tbY.Enabled = false;
generaPoints();
}
//生成数据源
private void generaPoints()
{
;
; i <= ; i++)
{
; j <= ; j++)
{
objPonit = new MyPoint() { xIndex=i,yIndex=j,text=""+count};
count++;
listPoints.Add(objPonit);
}
}
}
//执行查询
private void btQuery_Click(object sender, EventArgs e)
{
this.richTextBox1.Text = null;
DateTime beforDT = System.DateTime.Now;
//耗时巨大的代码
method2();
DateTime afterDT = System.DateTime.Now;
TimeSpan ts = afterDT.Subtract(beforDT);
this.textBox1.Text = ts.TotalMilliseconds.ToString()+" ms";
}
//显示
private void showPoints(MyPoint objMyPoint)
{
this.richTextBox1.Text += "," + objMyPoint.text;
}
/// <summary>
/// LinQ查询
/// </summary>
private void method1()
{
this.richTextBox1.Text = "传统方法查询结果:\n";
var objPoints = from b in listPoints where b.xIndex == Convert.ToInt32(this.tbX.Text.Trim().ToString()) select b;
foreach (var item in objPoints)
{
showPoints(item);
}
}
/// <summary>
/// List和Hashtable集合查询
/// </summary>
private void method2()
{
this.richTextBox1.Text = "新方法查询结果:\n";
//objPonit = new MyPoint();
string currentPX = this.tbX.Text.Trim().ToString();
if (listPoints != null && currentPX != null)
{
int TempCount = listPoints.Count;
&& hsTemp.Count <= )//如果list中有数据而哈希表中却没有数据
{
FlushTempIndex();
}
if (hsTemp.ContainsKey(currentPX))
{
string[] arrTempIndex = hsTemp[currentPX].ToString().Split(',');//可以直接将分好的数据放到数组中去
int TempIndexCount = arrTempIndex.Length;
;
; i < TempIndexCount; i++)
{
if (int.TryParse(arrTempIndex[i], out TempIndex) && TempIndex < TempCount)
{
showPoints(listPoints[TempIndex]);
}
}
}
}
}
public void FlushTempIndex()
{
hsTemp.Clear();//清空哈希表
int TempCount = listPoints.Count;
; i < TempCount; i++)
{
if (hsTemp.ContainsKey(listPoints[i].xIndex.ToString()))//如果哈希表中存在key值
{
hsTemp[listPoints[i].xIndex.ToString()] += "," + i.ToString();//这里和数组结构类似,改变索引值对应的value值信息
}
else
{
hsTemp.Add(listPoints[i].xIndex.ToString(), i);
}
}
}
}
}
快速查询List中指定的数据的更多相关文章
- mssql sqlserver 禁止删除数据表中指定行数据(转自:http://www.maomao365.com/?p=5323)
转自:http://www.maomao365.com/?p=5323 摘要:下文主要讲述,如何禁止删除数据表中指定行数据 最近收到用户一个需求,禁止所有人删除”表A”中,ID 为1.2.3.4.5的 ...
- 每日学习心得:SharePoint 为列表中的文件夹添加子项(文件夹)、新增指定内容类型的子项、查询列表中指定的文件夹下的内容
前言: 这里主要是针对列表中的文件下新增子项的操作,同时在新建子项时,可以为子项指定特定的内容类型,在某些时候需要查询指定的文件夹下的内容,针对这些场景都一一给力示例和说明,都是一些很小的知识点,希望 ...
- SQL查询显示行号、随机查询、取指定行数据
转自:walkingp 1.显示行号 如果数据没有删除的情况下主键与行号是一致的,但在删除某些数据,行号就与主键不一致了,这时需要查询行号就需要用新的方法,在SQL Server2005之前,需要使用 ...
- 快速向表中插入大量数据Oracle中append与Nologging
来源于:http://blog.sina.com.cn/s/blog_61cd89f60102e7gi.html 当需要对一个非常大的表INSERT的时候,会消耗非常多的资源,因为update表的时候 ...
- 用Spark查询HBase中的表数据
java代码如下: package db.query; import org.apache.commons.logging.Log; import org.apache.commons.logging ...
- 【Linux】查询文件中指定字符串的记录
语法 cat 文件 |grep 查询字符串 例如现在有文件file.dat,文件中内容如下: zhangsan Lisi wangwu123 wangwu890 zhangsan28290 现在想从文 ...
- Mysql快速删除表中重复的数据
表结构 CREATE TABLE T_VENDOR ( ID ) NOT NULL AUTO_INCREMENT COMMENT 'ID', COUNTRY ) DEFAULT NULL COMMEN ...
- 超实用--删除MYSQL中指定的数据的全部表
作过的人都知道,重复测试数据库的苦恼. 用法:# Usage: ./script user password dbnane mysql.nixcraft.in ~~~~~~~~~~~~~ #!/bin ...
- Java快速向数据库中插入大量数据 比如10万条以上
String sql = "insert into table *****"; //必须要有这句,要不然效果不明显 con.setAutoCommit(false); ps = c ...
随机推荐
- Azure IoT Hub和Event Hub相关的技术系列-索引篇
Azure IoT Hub和Event Hub相关的技术系列,最近已经整理了不少了,统一做一个索引链接,置顶. Azure IoT 技术研究系列1-入门篇 Azure IoT 技术研究系列2-设备注册 ...
- 022 component(组件)关联映射
Component关联映射: 目前有两个类如下: 值对象没有标识,而实体对象具有标识,值对象属于某一个实体,使用它重复使用率提升,而且更清析. 以上关系的映射称为component(组件)关联映射 在 ...
- MyBatis-3.2.2
note SqlSessionFactory 它是一个线程安全的 SqlSession 线程非安全,不能做类的公用变量 当数据库字段和实体对象名称不一至时,通过sql的字段命名别名,别名跟实体对象属性 ...
- 快速找到ARP病毒源
第一招:使用Sniffer抓包 在网络内任意一台主机上运行抓包软件,捕获所有到达本机的数据包.如果发现有某个IP不断发送请求包,那么这台电脑一般就是病毒源.原理:无论何种ARP病毒变种,行为方式有两种 ...
- sh脚本异常,binsh^M bad interpreter No such file or directory
错误 在Linux中执行.sh脚本,出现如下异常 /bin/sh^M: bad interpreter: No such file or directory 原因 在windows系统中编辑的.sh文 ...
- OAuth 2.0 / RCF6749 协议解读
OAuth是第三方应用授权的开放标准,目前版本是2.0版,以下将要介绍的内容和概念主要来源于该版本.恐篇幅太长,OAuth 的诞生背景就不在这里赘述了,可参考 RFC 6749 . 四种角色定义: R ...
- shell中如何进行算术运算
A=3 B=6 1.let算术运算表达式 let C=$A+$B2.$[算术运算表达式] C=$[$A+$B] 3.$(()) C=$(($A+$NB))
- C#码农的大数据之路 - 使用Ambari自动化安装HDP2.6(基于Ubuntu16.04)并运行.NET Core编写的MR作业
准备主机 准备3台主机,名称作用如下: 昵称 Fully Qualified Domain Name IP 作用 Ubuntu-Parrot head1.parrot 192.168.9.126 Am ...
- Spring框架之IOC(控制反转)
[TOC] 第一章Spring框架简介 IOC(控制反转)和AOP(面向方面编程)作为Spring框架的两个核心,很好地实现了解耦合.所以,简单来说,Spring是一个轻量级的控制反转(IoC)和面向 ...
- node.js零基础详细教程(3):npm包管理、git github的使用
第三章 建议学习时间4小时 课程共10章 学习方式:详细阅读,并手动实现相关代码 学习目标:此教程将教会大家 安装Node.搭建服务器.express.mysql.mongodb.编写后台业务逻辑 ...