关照是什么意思| 反流性食管炎吃什么药好| 今年27岁属什么生肖| 口痰多是什么原因| 幽门梗阻是什么意思| 一路长虹是什么意思| 苦瓜和什么不能一起吃| 鱼字五行属什么| 卵巢囊性占位是什么意思| 榴莲吃多了有什么危害| 好记性不如烂笔头是什么意思| 竹心泡水喝有什么功效| 思密达是什么意思| 早搏心律不齐吃什么药| 夏天吃什么蔬菜好| 夏天什么颜色最防晒| 指甲上有竖条纹是什么原因| 孩子说话晚是什么原因是什么情况| 金牛后面是什么星座| 属羊是什么星座| 健脾丸和归脾丸有什么区别| 水滴鱼长什么样子| 边沿是什么意思| 投喂是什么意思| 大白条是什么鱼| lookbook是什么意思| 不安腿综合征吃什么药| 切除子宫有什么危害| 自恋是什么意思| 金融bp是什么意思| 反流性食管炎吃什么中成药最好| 头疼头晕是什么原因| 消化不良用什么药| 虐狗什么意思| 大生化检查都包括什么项目| 佛珠生菇讲述什么道理| 耳朵里面疼用什么药| 刘晓庆什么星座| 丁香花什么颜色| 结节影是什么意思| 胃炎是什么症状| 眼睛做激光手术有什么后遗症| 打嗝不停是什么病前兆| 鸡头米是什么| 11点到12点是什么时辰| 什么水果榨汁好喝| 鲷鱼是什么鱼| 小孩咳嗽流鼻涕吃什么药效果好| 沉香有什么作用| 刷牙出血是什么原因| 粉刺长什么样图片| 春宵一刻值千金是什么意思| 酸枣什么时候成熟| 红小豆和赤小豆有什么区别| 上海曙光医院擅长什么| 尿出红色的尿是什么原因| 胃肠炎可以吃什么水果| hpv是什么意思啊| 吃金蝉有什么好处| 肠炎用什么药好| 骨龄大于年龄意味着什么| 胆固醇高是什么原因引起的| 鼻炎是什么症状| 二线用药是什么意思| 2021属什么| 孔子姓什么名什么| 来月经喝啤酒有什么影响| 阴道什么样| 梦见两条蛇是什么预兆| 黑豆有什么功效| 肝脏的主要功能是什么| 经前期综合症吃什么药| apc药片是什么药| 五塔标行军散有什么功效| 惗是什么意思| 什么是嗳气有何症状| qr是什么意思| 焯是什么意思| 菩提子是什么材质| 被交警开罚单不交有什么后果| 宫腔粘连有什么症状| 什么鹦鹉说话能力最强| 口契是什么字| 天伦之乐是什么意思啊| 补办户口本需要什么材料| 穿刺是什么手术| 属蛇与什么属相相克| 五月一号什么星座| 一心一意指什么生肖| asuka是什么意思| 蒲公英什么时候播种| 紫苏有什么作用与功效| 骨蒸潮热是什么症状| 狮子座女和什么星座最配| 202年属什么生肖| 男生属鸡和什么属相配| 杨枝甘露是什么意思| 两个gg是什么牌子的包包| 唉声叹气是什么意思| 土家族是什么族| 血虚是什么意思| 不容乐观是什么意思| 什么药止血效果最快| 小鸟来家里有什么预兆| 厅局级是什么级别| 六月十号什么星座| 乳腺结节看什么科| 吃避孕药不能吃什么东西| 榨菜是什么菜做的| 霉菌阴道炎是什么引起的| 筋膜炎用什么药| 司命星君掌管什么| 吃黄精有什么好处| 小孩心肌炎有什么症状| 我行我素的人什么性格| 宜家宜室什么意思| 捕风捉影是什么意思| gigi 是什么意思| 贫血喝什么口服液| 彦五行属性是什么| 心肌梗塞是什么原因引起的| 火龙果吃了有什么好处| 肝郁脾虚吃什么药效果最好| 蚊子怕什么颜色| 白虎女是什么意思| ab是什么意思| 手心长痣代表什么| 黄精和什么煲汤好| 为什么胸会痒| 明媚是什么意思| 什么是质子重离子治疗| 什么是iga肾病| 做什么检查确诊是白塞| 手抖是什么病的症状| 鎏是什么意思| 奇变偶不变是什么意思| 一岁宝宝能吃什么水果| 什么钓鱼愿者上钩| 鸡头米是什么东西| 否极泰来是什么生肖| 烤箱能做什么美食| 岩茶属于什么茶| 懒是什么生肖| 箱变是什么| 月经没来吃什么药可以催月经来| 新疆是什么族| 龙虾不能和什么一起吃| 一什么蜘蛛| 阿佛洛狄忒是什么神| 神经是什么| 宫缩是什么原因引起的| 单飞什么意思| 手腕痛什么原因| 长期喝蜂蜜有什么好处| 什么样的充电宝能带上飞机| 身是什么结构| 口腔溃疡该挂什么科| 黄芪是什么样子的| 腱鞘炎用什么药能治好| 一什么绿毯| 心脏衰竭吃什么药| 摆架子是什么意思| 身体缺钾吃什么可以补充| 敦促的意思是什么| 纸是用什么材料做的| 邮政ems是什么意思| 四川酸菜是什么菜| 什么的目光| 螨虫什么样子| 午时五行属什么| 肌桥是什么意思| 东方不败练的什么武功| 什么叫k线| 血糖高不能吃什么水果| 宝宝拉肚子挂什么科| 马齿苋是什么菜| hw是什么牌子| 男士检查精子挂什么科| 什么颜色衣服最防晒| 口香糖是什么材料做的| 塔罗牌是什么意思| 宫腔内高回声是什么意思| 全组副鼻窦炎什么意思| 舌尖痛什么原因| 胃炎吃什么食物好得快| 斑秃是什么原因引起的| 母亲生日送什么礼物| h皮带是什么牌子| 新生儿痤疮是什么引起的| 宫颈纳囊用什么药治疗效果好| 无偿献血有什么待遇| 舌头胖大是什么原因| 什么叫做基本工资| 检查血压挂什么科| 做蛋糕用什么面粉| 女生为什么会来月经| 阴部潮湿是什么原因| 宫颈hsil是什么意思| 肝回声稍密是什么意思| 一箭双雕是什么生肖| 专项变应原筛查是什么| 什么时间吃苹果最好| 什么粥最养胃| 什么人容易得天疱疮| 18k是什么金| 指甲挂什么科| 体脂是什么意思| 番薯是什么时候传入中国的| 市局副局长什么级别| 负利率是什么意思| 鱼水之欢是什么意思| 铁锈色痰见于什么病| 人体是由什么组成的| 脑梗输液用什么药| 地中海贫血携带者是什么意思| 司局级是什么级别| 口干口苦口臭是什么原因| 四川属于什么气候| 小狗感冒症状是什么样的| 三七粉适合什么人群喝| biu是什么意思| 山不转水转是什么意思| 脚底板热是什么原因| 点痣挂什么科室| 数字五行属什么| 麦克白夫人什么意思| 10月19号什么星座| 什么东西不能托运| 宫颈筛查是什么意思| 牛肉和什么炒好吃| 打新股需要什么条件| 匪气是什么意思| 纳粹是什么意思| 二十年婚姻是什么婚| 小孩眼屎多是什么原因引起的| 双顶径和头围有什么区别| 右眼皮跳有什么预兆| 什么是暗网| 梅核气吃什么药| 檀郎是什么意思| trab是甲状腺什么指标| 晚上3点是什么时辰| 吃什么补锌| 甲醛中毒有什么症状| 妙赞是什么意思| 慢性阑尾炎吃什么消炎药| 脑多普勒检查什么| 七月七日是什么节日| 点到为止是什么意思| 蝙蝠怕什么| 男人耳朵大代表什么| 示数是什么意思| 肺栓塞的主要症状是什么| 肚子胀吃什么药| 感冒挂号挂什么科| 拜谢是什么意思| 仙人掌有什么作用| 什么茶提神| 两面三刀是什么生肖| 1987属什么生肖| 孩子打喷嚏流鼻涕吃什么药| 新生儿什么时候能看见东西| 慢性咽炎用什么药| 滚球是什么意思| 百度Jump to content

比特币扩容之争,革命将走向未来,还是走向分裂?

From Wikipedia, the free encyclopedia
百度 专家认为,老年人知识更新慢,面对疾病,他们往往会病急乱投医,导致轻易被骗子拿下。

In computer science, array is a data type that represents a collection of elements (values or variables), each selected by one or more indices (identifying keys) that can be computed at run time during program execution. Such a collection is usually called an array variable or array value.[1] By analogy with the mathematical concepts vector and matrix, array types with one and two indices are often called vector type and matrix type, respectively. More generally, a multidimensional array type can be called a tensor type, by analogy with the mathematical concept, tensor.[2]

Language support for array types may include certain built-in array data types, some syntactic constructions (array type constructors) that the programmer may use to define such types and declare array variables, and special notation for indexing array elements.[1] For example, in the Pascal programming language, the declaration type MyTable = array [1..4,1..2] of integer, defines a new array data type called MyTable. The declaration var A: MyTable then defines a variable A of that type, which is an aggregate of eight elements, each being an integer variable identified by two indices. In the Pascal program, those elements are denoted A[1,1], A[1,2], A[2,1], …, A[4,2].[3] Special array types are often defined by the language's standard libraries.

Dynamic lists are also more common and easier to implement[dubiousdiscuss] than dynamic arrays. Array types are distinguished from record types mainly because they allow the element indices to be computed at run time, as in the Pascal assignment A[I,J] := A[N-I,2*J]. Among other things, this feature allows a single iterative statement to process arbitrarily many elements of an array variable.

In more theoretical contexts, especially in type theory and in the description of abstract algorithms, the terms "array" and "array type" sometimes refer to an abstract data type (ADT) also called abstract array or may refer to an associative array, a mathematical model with the basic operations and behavior of a typical array type in most languages – basically, a collection of elements that are selected by indices computed at run-time.

Depending on the language, array types may overlap (or be identified with) other data types that describe aggregates of values, such as lists and strings. Array types are often implemented by array data structures, but sometimes by other means, such as hash tables, linked lists, or search trees.

History

[edit]

Heinz Rutishauser's programming language Superplan (1949–1951) included multi-dimensional arrays. However, although Rutishauser described how a compiler for his language should be built, did not implement one.

Assembly languages and low-level languages like BCPL[4] generally have no syntactic support for arrays.

Because of the importance of array structures for efficient computation, the earliest high-level programming languages, including FORTRAN (1957), COBOL (1960), and Algol 60 (1960), provided support for multi-dimensional arrays.

Abstract arrays

[edit]

An array data structure can be mathematically modeled as an abstract data structure (an abstract array) with two operations

get(A, I): the data stored in the element of the array A whose indices are the integer tuple I.
set(A, I, V): the array that results by setting the value of that element to V.

These operations are required to satisfy the axioms[5]

get(set(A, I, V), I) = V
get(set(A, I, V), J) = get(A, J) if IJ

for any array state A, any value V, and any tuples I, J for which the operations are defined.

The first axiom means that each element behaves like a variable. The second axiom means that elements with distinct indices behave as disjoint variables, so that storing a value in one element does not affect the value of any other element.

These axioms do not place any constraints on the set of valid index tuples I, therefore this abstract model can be used for triangular matrices and other oddly-shaped arrays.

Implementations

[edit]

In order to effectively implement variables of such types as array structures (with indexing done by pointer arithmetic), many languages restrict the indices to integer data types[6][7] (or other types that can be interpreted as integers, such as bytes and enumerated types), and require that all elements have the same data type and storage size. Most of those languages also restrict each index to a finite interval of integers, that remains fixed throughout the lifetime of the array variable. In some compiled languages, in fact, the index ranges may have to be known at compile time.

On the other hand, some programming languages provide more liberal array types, that allow indexing by arbitrary values, such as floating-point numbers, strings, objects, references, etc.. Such index values cannot be restricted to an interval, much less a fixed interval. So, these languages usually allow arbitrary new elements to be created at any time. This choice precludes the implementation of array types as array data structures. That is, those languages use array-like syntax to implement a more general associative array semantics, and must therefore be implemented by a hash table or some other search data structure.

Language support

[edit]

Multi-dimensional arrays

[edit]

The number of indices needed to specify an element is called the dimension, dimensionality, or rank of the array type. (This nomenclature conflicts with the concept of dimension in linear algebra, which expresses the shape of a matrix. Thus, an array of numbers with 5 rows and 4 columns, hence 20 elements, is said to have dimension 2 in computing contexts, but represents a matrix that is said to be 4×5-dimensional. Also, the computer science meaning of "rank" conflicts with the notion of tensor rank, which is a generalization of the linear algebra concept of rank of a matrix.)

A two-dimensional array stored as a one-dimensional array of one-dimensional arrays (rows)
A two-dimensional array stored as a one-dimensional array of one-dimensional arrays (rows)

Many languages support only one-dimensional arrays. In those languages, a multi-dimensional array is typically represented by an Iliffe vector, a one-dimensional array of references to arrays of one dimension less. A two-dimensional array, in particular, would be implemented as a vector of pointers to its rows.[8] Thus an element in row i and column j of an array A would be accessed by double indexing (A[i][j] in typical notation). This way of emulating multi-dimensional arrays allows the creation of jagged arrays, where each row may have a different size – or, in general, where the valid range of each index depends on the values of all preceding indices.

This representation for multi-dimensional arrays is quite prevalent in C and C++ software. However, C and C++ will use a linear indexing formula for multi-dimensional arrays that are declared with compile time constant size, e.g. by int A[10][20] or int A[m][n], instead of the traditional int **A.[9]

The C99 standard introduced Variable Length Array types that let define array types with dimensions computed in run time. The dynamic 4D array can be constructed using a pointer to 4d array, e.g. int (*arr)[t][u][v][w] = malloc(sizeof *arr);. The individual elements are accessed by first de-referencing an array pointer followed by indexing, e.g. (*arr)[i][j][k][l]. Alternatively, n-d arrays can be declared as pointers to its first element which is a (n-1) dimensional array, e.g. int (*arr)[u][v][w] = malloc(t * sizeof *arr); and accessed using more idiomatic syntax, e.g. arr[i][j][k][l].

Indexing notation

[edit]

Most programming languages that support arrays support the store and select operations, and have special syntax for indexing. Early languages used parentheses, e.g. A(i,j), as in FORTRAN; others choose square brackets, e.g. A[i,j] or A[i][j], as in Algol 60 and Pascal (to distinguish from the use of parentheses for function calls).

Index types

[edit]

Array data types are most often implemented as array structures: with the indices restricted to integer (or totally ordered) values, index ranges fixed at array creation time, and multilinear element addressing. This was the case in most "third generation" languages, and is still the case of most systems programming languages such as Ada, C, and C++. In some languages, however, array data types have the semantics of associative arrays, with indices of arbitrary type and dynamic element creation. This is the case in some scripting languages such as Awk and Lua, and of some array types provided by standard C++ libraries.

Bounds checking

[edit]

Some languages (like Pascal and Modula) perform bounds checking on every access, raising an exception or aborting the program when any index is out of its valid range. Compilers may allow these checks to be turned off to trade safety for speed. Other languages (like FORTRAN and C) trust the programmer and perform no checks. Good compilers may also analyze the program to determine the range of possible values that the index may have, and this analysis may lead to bounds-checking elimination.

Index origin

[edit]

Some languages, such as C, provide only zero-based array types, for which the minimum valid value for any index is 0.[10] This choice is convenient for array implementation and address computations. With a language such as C, a pointer to the interior of any array can be defined that will symbolically act as a pseudo-array that accommodates negative indices. This works only because C does not check an index against bounds when used.

Other languages provide only one-based array types, where each index starts at 1; this is the traditional convention in mathematics for matrices and mathematical sequences. A few languages, such as Pascal and Lua, support n-based array types, whose minimum legal indices are chosen by the programmer. The relative merits of each choice have been the subject of heated debate. Zero-based indexing can avoid off-by-one or fencepost errors.[11]

Highest index

[edit]

The relation between numbers appearing in an array declaration and the index of that array's last element also varies by language. In many languages (such as C), one should specify the number of elements contained in the array; whereas in others (such as Pascal and Visual Basic .NET) one should specify the numeric value of the index of the last element. This distinction is not present in languages where the indices start at 1, such as Lua.

Array algebra

[edit]

Some programming languages support array programming, where operations and functions defined for certain data types are implicitly extended to arrays of elements of those types. Thus one can write A+B to add corresponding elements of two arrays A and B. Usually these languages provide both the element-by-element multiplication and the standard matrix product of linear algebra, and which of these is represented by the * operator varies by language.

Languages providing array programming capabilities have proliferated since the innovations in this area of APL. These are core capabilities of domain-specific languages such as GAUSS, IDL, Matlab, and Mathematica. They are a core facility in newer languages, such as Julia and recent versions of Fortran. These capabilities are also provided via standard extension libraries for other general purpose programming languages (such as the widely used NumPy library for Python).

String types and arrays

[edit]

Many languages provide a built-in string data type, with specialized notation ("string literals") to build values of that type. In some languages (such as C), a string is just an array of characters, or is handled in much the same way. Other languages, like Pascal, may provide vastly different operations for strings and arrays.

Array index range queries

[edit]

Some programming languages provide operations that return the size (number of elements) of a vector, or, more generally, range of each index of an array. In C and C++ arrays do not support the size function, so programmers often have to declare separate variable to hold the size, and pass it to procedures as a separate parameter.

Elements of a newly created array may have undefined values (as in C), or may be defined to have a specific "default" value such as 0 or a null pointer (as in Java).

In C++ a std::vector object supports the store, select, and append operations with the performance characteristics discussed above. Vectors can be queried for their size and can be resized. Slower operations like inserting an element in the middle are also supported.

Slicing

[edit]

An array slicing operation takes a subset of the elements of an array-typed entity (value or variable) and then assembles them as another array-typed entity, possibly with other indices. If array types are implemented as array structures, many useful slicing operations (such as selecting a sub-array, swapping indices, or reversing the direction of the indices) can be performed very efficiently by manipulating the dope vector of the structure. The possible slicings depend on the implementation details: for example, Fortran allows slicing off one column of a matrix variable, but not a row, and treat it as a vector.

On the other hand, other slicing operations are possible when array types are implemented in other ways.

Resizing

[edit]

Some languages allow dynamic arrays (also called resizable, growable, or extensible): array variables whose index ranges may be expanded at any time after creation, without changing the values of its current elements.

For one-dimensional arrays, this facility may be provided as an operation append(A,x) that increases the size of the array A by one and then sets the value of the last element to x. Other array types (such as Pascal strings) provide a concatenation operator, which can be used together with slicing to achieve that effect and more. In some languages, assigning a value to an element of an array automatically extends the array, if necessary, to include that element. In other array types, a slice can be replaced by an array of different size, with subsequent elements being renumbered accordingly – as in Python's list assignment A[5:5] = [10,20,30], that inserts three new elements (10, 20, and 30) before element "A[5]". Resizable arrays are conceptually similar to lists, and the two concepts are synonymous in some languages.

An extensible array can be implemented as a fixed-size array, with a counter that records how many elements are actually in use. The append operation merely increments the counter; until the whole array is used, when the append operation may be defined to fail. This is an implementation of a dynamic array with a fixed capacity, as in the string type of Pascal. Alternatively, the append operation may re-allocate the underlying array with a larger size, and copy the old elements to the new area.

See also

[edit]

References

[edit]
  1. ^ a b Robert W. Sebesta (2001) Concepts of Programming Languages. Addison-Wesley. 4th edition (1998), 5th edition (2001), ISBN 9780201385960
  2. ^ "Introduction to Tensors | TensorFlow Core". TensorFlow.
  3. ^ K. Jensen and Niklaus Wirth, PASCAL User Manual and Report. Springer. Paperback edition (2007) 184 pages, ISBN 978-3540069508
  4. ^ John Mitchell, Concepts of Programming Languages. Cambridge University Press.
  5. ^ Lukham, Suzuki (1979), "Verification of array, record, and pointer operations in Pascal". ACM Transactions on Programming Languages and Systems 1 (2), 226–244.
  6. ^ Deitel, Harvey M.; Deitel, Paul J. (2005). C# for Programmers. Prentice Hall Professional. p. 303. ISBN 978-0-13-246591-5. Retrieved 22 May 2024.
  7. ^ Friesen, Jeff (5 March 2014). Learn Java for Android Development: Java 8 and Android 5 Edition. Apress. p. 56. ISBN 978-1-4302-6455-2. Retrieved 22 May 2024.
  8. ^ Van der Linden, Peter (1994). Expert C Programming: Deep C Secrets. Englewood Cliffs, NJ: SunSoft Press. ISBN 978-0-13-177429-2.
  9. ^ Brian W. Kernighan and Dennis M. Ritchie (1988), The C programming Language. Prentice-Hall, p. 81.
  10. ^ Kernighan, Brian W.; Ritchie, Dennis M. (1988). The C programming language (2nd ed.). Englewood Cliffs, N.J: Prentice Hall. p. 24. ISBN 978-0-13-110370-2.
  11. ^ Edsger W. Dijkstra, "Why numbering should start at zero"
[edit]
全青皮是什么皮 西芹和芹菜有什么区别 解体是什么意思 女人更年期什么症状 治类风湿用什么方法好
马车标志是什么品牌 沙眼衣原体是什么 腹股沟黑是什么原因 倭瓜是什么瓜 添堵是什么意思
为什么身体没力气也没有精神 bi是什么意思 碳酸氢根偏低什么意思 疏肝理气是什么意思 眼红是什么意思
无纺布是什么材料做的 右手无名指戴戒指什么意思 爱做梦是什么原因应该怎样调理 渡船是什么意思 牙疼吃什么药好
地级市市委书记是什么级别hcv8jop9ns9r.cn 美人尖是什么意思hcv8jop9ns2r.cn 胎盘做成胶囊吃有什么好处hcv9jop0ns9r.cn 发烧38度吃什么药hcv8jop0ns4r.cn 吃什么补精子快hcv8jop4ns0r.cn
尿道口红肿是什么原因hcv9jop5ns7r.cn 免疫固定电泳查什么的hcv8jop0ns4r.cn 不应期是什么hcv8jop4ns7r.cn 黄帝是一个什么样的人hcv8jop7ns8r.cn 2006属狗的五行缺什么hcv8jop0ns2r.cn
肝脏不好吃什么药hcv7jop4ns7r.cn maxco是什么牌子shenchushe.com 人体最大的消化腺是什么bjhyzcsm.com 补气血用什么泡水喝hcv7jop9ns3r.cn 点痣后用什么修复最好hcv7jop9ns3r.cn
脖子长痘痘是因为什么原因shenchushe.com 洛什么意思hcv8jop1ns3r.cn 什么是ph值hcv9jop1ns1r.cn 蹭饭是什么意思sscsqa.com 高光是什么意思xjhesheng.com
百度