忠实是什么意思| 苦瓜不能和什么一起吃| 阑尾炎属于什么科室| 什么七什么八| au9999是什么意思| 肌酐高什么原因引起的| 脸上长痘挂什么科| 南瓜不能和什么食物一起吃| 屁股长痘是什么原因| 肛裂擦什么药膏| 一什么天| 中年人吃什么钙片补钙效果好| 白带是什么意思| 心脏疼吃什么药效果好| 甲醇对人体有什么伤害| 文心什么字| 告诉我们什么道理| 沉香是什么| 梦到丧尸是什么预兆| 胃痛胃胀什么原因引起的| 7月29号是什么日子| 落枕挂什么科| 一天什么时候血压最高| 感冒引起的咳嗽吃什么药| 出冷汗是什么原因| 佝偻是什么意思| 空调管滴水是什么原因| 冠心病是什么病| 青鸾是什么意思| 火韦是什么字| 月经前长痘痘是什么原因| 钠低会出现什么症状| 头孢喝酒有什么反应| 紫癜有什么危害| 乌龟下蛋预示着什么| 免费查五行缺什么| 金融行业五行属什么| 耳聋吃什么药| 信徒是什么意思| 膝盖咔咔响吃什么药| 莲蓬吃了有什么好处| 嘴唇紫色是什么原因| 货比三家是什么意思| 血糖偏高可以吃什么水果| 腹泻吃什么药| 焯水什么意思| 常流鼻血是什么原因| 阴盛格阳是什么意思| 喝苦荞茶有什么好处和坏处| 不自觉摇头是什么病| 芦荟有什么作用| 墨镜什么牌子好| 灏字五行属什么| 打2个喷嚏代表什么| 葛洲坝集团是什么级别| gf是什么单位| 脂肪球是什么意思| 什么品种的狗最粘人| 衣食父母什么意思| 淋巴是什么| 落枕是什么原因| 老年人吃什么营养品好| 梦见前夫是什么意思| 鸿运当头什么意思| 711是什么星座| ck属于什么档次的品牌| r代表什么意思| 右肾小结石是什么意思| 目加此念什么| 因人而异是什么意思| 非即食是什么意思| 空调除湿是什么标志| 孩子爱啃指甲是什么原因| 贫血吃什么水果| 饱和脂肪是什么| 夜场是什么工作| 南昌有什么好玩的地方| 为什么突然就得肝炎了| 石家庄为什么叫国际庄| 金项链断了有什么预兆| 上海新华医院擅长什么| 窦性心律过缓吃什么药| 张信哲为什么不结婚| 肝肾挂什么科| 梦见吃梨是什么意思| 煮酒论英雄什么意思| 不射精是什么原因| 女人左眼跳是什么预兆| 心肌受损会出现什么症状| 吃小米粥有什么好处和坏处| 月黑见渔灯的见读什么| 梦到手机丢了什么预兆| 水痘是什么| 夏季养什么脏腑| 西瓜有什么功效| 明胶是什么东西| 哈密瓜为什么叫哈密瓜| 什么是火象星座| pci是什么| 癌抗原125是什么意思| 什么是呆账| 风热证是什么意思| 口腔溃疡什么药最管用| 四维空间是什么样子| 血钾高是什么引起的| 梦见被蛇缠身是什么意思| 脑癌是什么原因引起的| 肛门长期瘙痒是什么原因| 吃什么可以提高新陈代谢| 宫殿是什么意思| 什么是聚酯纤维面料| 身上长痣是什么原因| 四面八方什么生肖| 背痛是什么原因| 反流性食管炎是什么病| 人的五官是什么| 吃什么对头发有好处| 冬虫夏草有什么功效与作用| 为什么低烧比高烧可怕| 长长的柳条像什么| afar是什么意思| 鱼油什么时间吃最好| 体征是什么意思| cordura是什么面料| 白头发吃什么药| 粗茶淡饭下一句是什么| 紫癜是什么| 政协是什么| 破釜沉舟是什么意思| 股票填权是什么意思| 愈合是什么意思| 净身出户什么意思| 肛瘘是什么症状| 吃鱼油有什么好处| 喉咙挂什么科室| nu11是什么意思| 红薯不能和什么一起吃| 喜气洋洋是什么意思| 总是抽筋是什么原因| 股骨头疼痛吃什么药| 翔是什么意思| 泡菜生花用什么方法可以去掉| 颈动脉彩超查什么| 宜入宅是什么意思| 重阳节干什么| 起夜是什么意思| 化妆品属于什么行业| 惊闻是什么意思| 车船税是什么意思每年都交吗| 人造奶油是什么做的| 过敏性鼻炎吃什么水果好| 三教九流代表什么生肖| 溺爱的意思是什么| 清宫是什么意思| 暗的反义词是什么| 黄花苗泡水喝有什么作用| 应激是什么意思| 腰间盘膨出和突出有什么区别| 痔疮饮食要注意什么| 儿童不长个子去医院挂什么科| 属鸡的守护神是什么菩萨| 鱼吐泡泡是什么原因| 梗犬是什么意思| 爱生闷气的人容易得什么病| 血糖高可以吃什么主食| 钙化灶什么意思| 狗可以吃什么水果| 术后引流管什么时间可以拔| 今年30岁属什么生肖| 吃辣流鼻涕是什么原因| 膀胱是什么| 王字旁加己念什么| 梦见前夫是什么意思| 六味地黄丸什么牌子的好| 菊花和枸杞泡水喝有什么功效| 长白眉毛是什么征兆| 胆小如鼠的意思是什么| 戒指中指代表什么意思| 碳水化合物是什么食物| invent是什么意思| 四百多分能上什么大学| 驰字五行属什么| 为什么口臭| 什么牌子的充电宝好| 双清是什么意思| 白介素高是什么原因| 溶血症是什么症状| 手术后可以吃什么| cp是什么意思| 眩晕症是什么原因引起的| 舌头烂了是什么原因| 珍惜眼前人是什么意思| 易孕体质是什么意思| 中国国鸟是什么鸟| 大姨妈不来是什么原因造成的| 拔罐有什么用| 什么饮料解酒效果最好| 奇葩什么意思| 宫颈癌做什么检查| 套话是什么意思| 吃蒲公英有什么好处| 白内障的症状是什么| 骨盆前倾有什么危害| 分开后我会笑着说是什么歌| 孩子过敏性咳嗽吃什么药好| 吃什么会变胖| 不遗余力的遗是什么意思| 妈妈桑是什么意思| 东北冻梨是什么梨| 总蛋白偏高有什么危害| 关节炎有什么症状| 什么是粒子植入治疗| 恶寒发热是什么意思| 口舌是非是什么意思| 烧心吃什么| 苍蝇是什么味道| 死亡是什么感觉| 老年人出现幻觉是什么原因| 什么是风湿| 脾气虚吃什么中成药| 1955年出生属什么| 空腹血糖17已经严重到什么时候| 艾灸脚心有什么好处| 什么是制片人| 海蜇丝是什么做的| 女上位什么意思| cm医学上是什么意思| 改良剂是什么| 二脚趾比大脚趾长代表什么| 什么紫什么红| 为什么喝水血糖也会高| 去医院看头发挂什么科| brunch是什么意思| 户口分户需要什么条件| 紫癜是什么病严重吗| 火星是什么意思| 什么大腰粗| 小别胜新婚是什么意思| 一月十九号是什么星座| 飞刃是什么意思| 氯雷他定有什么副作用| 10月24号是什么星座| 彻夜难眠什么意思| hc是胎儿的什么意思| 土字五行属什么| 肚子疼喝什么药| nerdy是什么牌子| 紫笋茶属于什么茶| 焱加木念什么| 拍黄瓜什么意思| 小孩拉肚子吃什么药| 脂肪肝吃什么药最好| twins什么意思| 孕妇适合吃什么食物| 小腿浮肿是什么原因女性| 备孕需要吃什么| 鸭肉炖什么好吃| 腰椎滑脱是什么意思| 猫鼻支什么症状| 血小板计数偏低是什么意思| 驻马店古代叫什么| 手到擒来是什么意思| 核桃壳有什么用| 什么是造影手术| 百度

五成无人问津:资本热捧下的共享充电宝真是好生意?

百度 譬如自主乘用车搞不上去,还在跟跑,他分析主观原因是浮躁,直言缺乏脚踏实地的苦干精神;客观原因是乘用车市场让国外品牌进来得太多了。

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)

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
o型血和什么血型容易溶血 病毒性扁桃体炎吃什么药 高考明天考什么 肾构错瘤要注意什么 痔疮瘙痒用什么药
95年属什么的生肖 儿童铅超标有什么症状 直接胆红素是什么 跑马什么意思 ab和b型血生的孩子是什么血型
尿气味重是什么原因 喝苹果醋有什么好处 自愿离婚要带什么证件 28属什么的生肖 骨转移是什么意思
产检请假属于什么假 怀孕应该注意什么 豚鼠吃什么食物 手上长毛是什么原因 不可亵玩焉的亵是什么意思
疱疹是一种什么病jinxinzhichuang.com 月经什么时候来hcv8jop6ns8r.cn 放疗什么意思0735v.com 真菌感染用什么药hcv7jop5ns6r.cn 湿毒吃什么药最有效hcv8jop6ns6r.cn
腹腔积水是什么原因造成的hcv7jop6ns2r.cn 左撇子是什么意思xjhesheng.com 红细胞偏低是什么原因hcv9jop1ns2r.cn 单核细胞百分比偏高是什么原因hcv9jop0ns2r.cn 血小板压积是什么意思hcv9jop2ns1r.cn
胺试验阳性是什么意思bfb118.com 手上脱皮什么原因hcv9jop0ns5r.cn 口头禅是什么意思hcv8jop3ns0r.cn plory是什么牌子hcv9jop6ns8r.cn 夏季吃什么水果hcv9jop3ns9r.cn
子宫息肉是什么hcv9jop2ns8r.cn 风湿病挂什么科hcv9jop5ns3r.cn 八月十六号是什么星座hcv8jop3ns4r.cn 为什么医生很少开阿斯美hcv8jop9ns8r.cn 子宁不嗣音什么意思hcv8jop5ns7r.cn
百度