第七章(字典)

字典是“键-值”结构,也是用数组存储,数组下标就是“键”

//字典类
			function Dictionary(){
//				var tag=0;
				this.datastore=new Array();
				this.add=add;
				this.find=find;
				this.remove=remove;
				this.showAll=showAll;
				this.count=count;
				this.clear=clear;
				this.sortKey=sortKey;
				this.sortValue=sortValue;
//				this.next=next;
			}
//			//下一个键
//			function next(){
//				tag++;
//				console.log(tag);
//				if(tag<this.datastore.count) this.tag++;
//				var flag=0;
//				for(var key in this.datastore)
//				{
//					if(flag==tag) 
//					{	console.log(key+"->"+ this.datastore[key]);
//						break;
//					}
//					else flag++;
//				}
//				return tag;
//			}
			//按键增加
			function add(key,value){
				this.datastore[key]=value;
			}
			//按键查找
			function find(key){
				return this.datastore[key];
			}
			//按键删除
			function remove(key){
				delete this.datastore[key];
			}
			//显示所有键值
			function showAll(){
				for(var key in this.datastore){
					console.log(key+"->"+this.datastore[key]);
				}
			}
			//统计个数
			function count(){
				var n=0;
				//不能用length,因为当键的类型为字符串是,length属性就不管用了
//				n=this.datastore.length; 
				for(var key in this.datastore) n++;
				return n;
			}
			//清除所有的键值
			function clear(){
				for(var key in this.datastore){
					delete this.datastore[key];
				}
			}
			//按键排序显示,但是并不能对原数组进行排序
			function sortKey(){
				//对键值数组来说,sort方法同样无效
				//对键进行排序,返回的也是新的数组(键,并不包含值),并且对原数组对没有任何影响
				console.log("按键排序:");
				var sidc=Object.keys(this.datastore).sort();
				for(var i=0;i<sidc.length;i++){
					console.log(sidc[i]+"->"+this.datastore[sidc[i]]);
				}
			}
			//按值排序显示,如果有更好的方法请告知
			function sortValue(){
				//创建值数组存放只原数组中的值
				var i=0;
				var arry_temp=[];
				for(var key in this.datastore){
					arry_temp[i]=this.datastore[key];	
					i++;
				}
				
				//对值数组进行排序
				arry_temp.sort(function(a,b){return a-b});
				console.log("对值排序:");
				
				//从原数组中找与值数组值相等的
				for(i=0;i<arry_temp.length;){
					for(key in this.datastore){
						if(this.datastore[key]==arry_temp[i]){
						console.log(key+"->"+this.datastore[key]);
						i++;
						}	
					}
				}	
			}
			var pbook=new Dictionary();
			pbook.add("mike","923");
			pbook.add("mike2","345");
			pbook.add("mike3","567");
			pbook.add("mike4","789");
			pbook.add("amike4","789");
			
			console.log(pbook.find("mike2"));
			pbook.remove("mike2");
			pbook.showAll();
			console.log(pbook.count());
			pbook.sortKey();
			pbook.sortValue();


数据字典(Data Dictionary, DD),在第七章数据库设计中是一个核心的概念,它包含了关于数据库系统所有重要信息的详细描述和组织。数据字典通常由以下几个主要部分构成: 1. **实体(Entities)**:描述现实世界中的客观事物,如用户、订单、产品等,每个实体都有其属性(字段)和标识符。 2. **属性(Properties)**:定义了实体的具体特征,例如用户的姓名、电话号码、电子邮件地址等。 3. **键(Key)**:用于唯一标识每个记录的特殊属性或组合,如主键、外键等。 4. **联系(Relationships)**:描述不同实体之间的联系或依赖,比如一对一、一对多、多对多的关系。 5. **数据类型(Data Types)**:说明属性值可能取什么类型,如整数、字符串、日期等。 6. **域(Domains)**:为特定属性预定义的一组可能值,限制了该属性的合法输入范围。 7. **索引(Indexes)**:提高查询性能的数据结构,对经常用于查找的列创建索引。 8. **视图(Views)**:虚拟表,由基础表基于某种逻辑关系创建,只显示需要的信息给用户。 9. **存储过程(Procedures)**:预先编写的数据库操作集合,可执行复杂的任务。 10. **触发器(Triggers)**:自动执行的规则,当满足特定条件时,对数据进行操作,如更新或插入后执行的操作。 11. **安全性和权限设置**:定义谁有权访问哪些数据以及如何访问。 了解并维护好数据字典对于数据库的设计、管理和优化至关重要,因为它提供了对整个系统的统一理解框架。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值