`

pike数据类型-- mapping

阅读更多



      mappings只是特殊的数组(array).mapping比较慢,并且消耗内存也比较大,因此,mappiing不能完全取代数组.特殊的是,不止整数,所有类型都可以做索引.我们可以想象mapping是这样:
mapping中每一个元素都是key-value对.具有很方便的查找功能,这种功能可以很快的找到任何一个key所对应的value.现在,假如我们把mapping叫做m,m[i]会很快的找到key为i的value.假如key没有找到,会返回0.假如我们对已有的key赋值,他会覆盖原来的值.如果被赋值的key不存在,则一对新的key-value会添加到mapping中, 定义一个常量的mapping是很简单的:
     ([])     //空mapping
     ([1:2])    //
     (["one":1,"two",2])    //
     ([1:({2.0})],"":([]))    //
     和数组相比,mapping可以可以是任意类型的值.最大的不同是key也可以是任意类型.另外需要注意的是key-value对没有一定的顺序.你不能指定第十四对key-value,因为没法区别那对是第十四.因此,不能对mapping做排序操作.下面是mapping的一些重要操作:
m[index]
       可以重新赋值,增加值.
+,-,|,&,^
       和数组一样,这些操作符,也可以使用,不同的是,mapping作用于key.在一些特殊情况,当value从两个mapping值取得时候,它会选择操作符右边的值.这样它使用起来比+=方便多了.看一些例子:
      ([1:3,3:1]) +  ([2:5, 3:7]) => ([1:3,2:5,3:7])
      ([1:3,3:1]) -  ([2:5, 3:7]) => ([1:3])
      ([1:3,3:1]) | ([2:5, 3:7]) => ([1:3,2:5,3:7])
      ([1:3,3:1]) & ([2:5, 3:7]) => ([3:7])
      ([1:3,3:1]) ^ ([2:5, 3:7]) => ([1:3,2:5])
a==b
     相同是返回1,否则返回0
a!=b
     不等时返回1,否则返回1
array indices(mapping m)
     返回m的所有包含有所有key的数组
mixed m_delete(mapping m,mixed ind)
     移除key为ind的key-value对,返回ind对应的value
int mappingp(mixed m)
     判断m是否为mapping类型,是返回1,否则返回0
mapping mkmapping(array ind,array val)
     把数组ind和val构造一个mapping, ([ind[0]:val[0],ind[1]:val[1],...,ind[i],val[i]])

mapping replace(mapping m,mixed from, mixed to)

     把m中所有value为from的全部替换成to,并且生成新的mapping

mixed search(mapping m,mixed val)

     返回第一对值为val的key

int sizeof(mapping m)

    返回mapping的key-value的对数

array values(mapping m)

     同indices,不同的是放回的是所有value的数组.如果同一个mapping连续操作indices和values,两者之间没有任何操作,得到的数组顺序是相同的.它们可以作为mkmapping的两个参数,重新组成mapping m.

int zefo_type(mixed t)

     当在mapping中找不到某个key的时候,会返回0.但是,问题是假如0在mapping中也是value的时候怎么办.这个方法就是告诉你两者间的区别.zero_type(m[ind])返回1,说明这个ind不存在与mapping m中,如果存在,则返回1以外的其他数字.

 

 

  下面是原文:

引用
Mappings are are really just more generic arrays. However, they are slower and use more memory than arrays, so they cannot replace arrays completely. What makes mappings special is that they can be indexed on other things than integers. We can imagine that a mapping looks like this:



Each index-value pair is floating around freely inside the mapping. There is exactly one value for each index. We also have a (magical) lookup function. This lookup function can find any index in the mapping very quickly. Now, if the mapping is called m and we index it like this: m [ i ] the lookup function will quickly find the index i in the mapping and return the corresponding value. If the index is not found, zero is returned instead. If we on the other hand assign an index in the mapping the value will instead be overwritten with the new value. If the index is not found when assigning, a new index-value pair will be added to the mapping. Writing a constant mapping is easy:





([ ]) // Empty mapping

([ 1:2 ]) // Mapping with one index-value pair, the 1 is the index

([ "one":1, "two":2 ]) // Mapping which maps words to numbers

([ 1:({2.0}), "":([]), ]) // Mapping with lots of different types





As with arrays, mappings can contain any type. The main difference is that the index can be any type too. Also note that the index-value pairs in a mapping are not stored in a specific order. You can not refer to the fourteenth key-index pair, since there is no way of telling which one is the fourteenth. Because of this, you cannot use the range operator on mappings.



The following operators and functions are important:



indexing ( m [ ind ] )

As discussed above, indexing is used to retrieve, store and add values to the mapping.

addition, subtraction, union, intersection and xor

All these operators works exactly as on arrays, with the difference that they operate on the indices. In those cases when the value can come from either mapping, it will be taken from the right side of the operator. This makes it easier to add new values to a mapping with +=. Some examples:

([1:3, 3:1]) + ([2:5, 3:7]) returns ([1:3, 2:5, 3:7 ])

([1:3, 3:1]) - ([2:5, 3:7]) returns ([1:3])

([1:3, 3:1]) | ([2:5, 3:7]) returns ([1:3, 2:5, 3:7 ])

([1:3, 3:1]) & ([2:5, 3:7]) returns ([3:7])

([1:3, 3:1]) ^ ([2:5, 3:7]) returns ([1:3, 2:5])



same ( a == b )

Returns 1 if a is the same mapping as b, 0 otherwise.

not same ( a != b )

Returns 0 if a is the same mapping as b, 1 otherwise.

array indices(mapping m)

Indices returns an array containing all the indices in the mapping m.

mixed m_delete(mapping m, mixed ind)

This function removes the index-value pair with the index ind from the mapping m. It will return the value that was removed.

int mappingp(mixed m)

This function returns 1 if m is a mapping, 0 otherwise.

mapping mkmapping(array ind, array val)

This function constructs a mapping from the two arrays ind and val. Element 0 in ind and element 0 in val becomes one index-value pair. Element 1 in ind and element 1 in val becomes another index-value pair, and so on..

mapping replace(mapping m, mixed from, mixed to)

This function creates a copy of the mapping m with all values equal to from replaced by to.

mixed search(mapping m, mixed val)

This function returns the index of the 'first' index-value pair which has the value val.

int sizeof(mapping m)

Sizeof returns how many index-value pairs there are in the mapping.

array values(mapping m)

This function does the same as indices, but returns an array with all the values instead. If indices and values are called on the same mapping after each other, without any other mapping operations in between, the returned arrays will be in the same order. They can in turn be used as arguments to mkmapping to rebuild the mapping m again.

int zero_type(mixed t)

When indexing a mapping and the index is not found, zero is returned. However, problems can arise if you have also stored zeroes in the mapping. This function allows you to see the difference between the two cases. If zero_type(m [ ind ]) returns 1, it means that the value was not present in the mapping. If the value was present in the mapping, zero_type will return something else than 1.









 

0
0
分享到:
评论

相关推荐

    centos-release-openstack-pike-1-0.el7.x86_64.rpm

    centos7下centos-release-openstack-pike

    华硕 Z9PE-D16C2L (pike 2008)-W2k3_x64驱动

    华硕Z9PE-D16C2L是一款高性能的工作站级或服务器级主板,它支持Intel的Pike 2008平台,这是一个针对数据中心和服务器应用的解决方案。在Windows Server 2003这样的操作系统上,安装正确的驱动是确保硬件正常运行和...

    pike-for-sublime:Sublime文本编辑器的派克语法定义

    安装pike-for-sublime 或者,将软件包从下载或克隆到您的Packages/User文件夹中。 贡献 Sublime使用XML文件进行语法定义,但是编写起来很累。 Pike语法定义以JSON(类似)格式编写,然后通过创建XML文件的to-

    TRS_Portable Type_Pike_manual-china

    TRS_PORTABLE TYPE PIKE MANUAL-CHINA是一份介绍高速图像处理设备的使用手册,其中详细介绍了设备配置、操作界面和软件应用,强调了其高速图像处理的能力,可以达到每秒500帧的图像处理速度。该设备的特点在于其高速...

    PIKE--一种基于解释的脚本语言

    ### Pike-v7.6.112版本 这个版本的PIKE包含了对语言特性的改进、错误修复以及可能的新功能。具体更新内容可能包括性能提升、新的API函数、对最新操作系统版本的支持等。开发者可以通过查阅官方文档或发行说明来获取...

    neutron_lbaas_pike-devops-bed

    标题“neutron_lbaas_pike-devops-bed”暗示了我们正在探讨的是Neutron Load Balancing as a Service (LBaaS) 在OpenStack Pike版本中的一个与DevOps相关的项目或者工具集。Neutron是OpenStack的一个核心组件,负责...

    html_email_pike-st-theater:HTML电子邮件

    在"html_email_pike-st-theater-master"这个文件中,很可能包含了创建一个关于派克圣剧院的HTML邮件模板的所有必要文件,如HTML文件、CSS文件(即使它们是内联的)、图片和其他可能的资源。这些文件可以作为实例,...

    Pike-v8.0.1116.zip

    Pike-v8.0.1116的改进** 在Pike v8.0.1116这个版本中,开发者可以期待以下改进: - **性能提升**:通过优化编译器和运行时环境,提升了程序执行速度。 - **错误修复**:解决了一些已知的bug,提高了程序的稳定性...

    华硕 pike 2008使用说明书

    ### 华硕 PIKE 2008 使用说明书知识点概览 #### 一、产品介绍与规格 **产品名称:** 华硕 PIKE 2008/IMR LSI SAS RAID 卡。 **功能概述:** 该 RAID 卡支持多种 RAID 级别设置,如 RAID 0、1、5、6 等,能够提高...

    使用Kolla部署Pike版本的OpenStack-allinone云平台

    综上所述,使用Kolla部署Pike版本的OpenStack-allinone云平台是一个系统工程,它涵盖了从操作系统基础配置到OpenStack具体组件部署的全过程。对于想要打造私有云环境的企业和个人来说,掌握这些知识是非常必要的。

    CentOS1810-pike-文档.zip

    配置Cinder时,需要选择后端存储驱动,如LVM、NFS、iSCSI或 Cinder自身的卷类型。此外,还需配置Cinder与Nova的交互,使得计算节点能够动态挂载和卸载Cinder卷。 总结: 通过以上详细讲解,读者将对OpenStack Pike...

    华硕pike6480阵列卡驱动

    华硕Pike6480阵列卡是一款高性能的存储解决方案,旨在提升服务器和数据中心的数据存储和处理能力。它支持多种RAID(冗余磁盘阵列)级别,如RAID 0、1、5、6、10、50和60,这些级别的选择可以根据用户的需求平衡性能...

    Go-pike是HTTP缓存服务提供高效简单的HTTP缓存服务

    压缩包中的"vicanso-pike-ae9cef6"可能是Go-pike的一个特定版本源码,用户可以通过解压并编译这个源码来获取Go-pike的可执行文件。在实际使用中,开发者可以根据项目需求调整源码,或者通过Go的依赖管理工具(如go ...

    pike 64XX 阵列驱动

    总结起来,"pike 64XX 阵列驱动" 主题涉及到的是如何在Windows Server 2008 R2操作系统中,通过U盘引导的方式安装Pike 64XX系列阵列卡的驱动程序,以确保服务器能够正常识别和利用该硬件进行高效的数据存储和管理。...

    PIKE「BROCHET」-crx插件

    派克孵化器在线2.0 Incubateur de brochets 2.0。 更改互联网上的在线视听。 在“无所事事的时刻”和“无罪的救助”之间进行互动。 支持语言:Français

    pike:Pike SMB测试框架

    m pip install pike-smb2 制作说明Ubuntu 14.04 / 16.04 apt-get install -y --no-install-recommends krb5-user libkrb5-dev python-dev build-essential python2.7 python-pippip install setuptools pycr

    matlab做莫兰指数的代码-SSLB-examples:SSLB-示例

    matlab做莫兰指数的代码...安装以下用于模拟和数据分析的 R 包: install.packages(c("mvtnorm", "isa2", "biclust", "pals", "reshape2", "tidyverse", "gridExtra", "clue")) if (!requireNamespace("BiocManager",

    Pike Video-开源

    V4L2提供了丰富的功能,包括捕获、编码、解码、视频输出、音频同步等,适用于各种类型的视频设备,如摄像头、数字电视接收器等。它支持多种视频标准,如MPEG、JPEG、YUV等,并且与用户空间程序之间的通信通过ioctl...

    标准pike 6480华硕SAS阵列卡驱动 官方版

    标准pike6480驱动是适用于华硕电脑的主板驱动程序,用户下载之后可直接按住使用,促使电脑运行,此款驱动程序只适用于华硕SAS型号,需要的用户就下载吧!标准pike6480驱简介:标准pike6480华硕SAS阵列卡驱动,华硕z8...

    pike 6480 驱动

    "pike 6480 驱动"指的是LSI(现已被Avago,后又并入Broadcom公司)生产的Marvell 88SE6480 SAS(串行连接SCSI)控制器的驱动程序。这个驱动对于拥有该型号SAS卡的用户来说至关重要,因为它确保了操作系统能够识别和...

Global site tag (gtag.js) - Google Analytics