Array: Difference between revisions

Line 209:
 
===[[Smalltalk]]===
Smalltalk provides a rich set of collection classes in its base library, which is also standard (ANSI) among the different implementations. <br>The most used are:
* Array - fixed size, indexed by integer index, any kind of element
* ByteArray - an array of bytes, like Array, but only byte valued integers as elements
* String - an array of characters, like Array, but only characters as elements
* OrderedCollection - variable size, indexed by integer index, any kind of element
* Dictionary - variable size, indexed by arbitrary object as index, any kind of element
 
Array, ByteArray, String and all othersother collection types provide a common protocol which they inherit from their common superclass, <tt>Collection</tt>. ByteArray and String can be considered as Arrays which usewith a more compact storage representation internally (and maybut provide additional protocol eg. for case conversion or bit-array operations).
 
In Smalltalk, a character is exactly that: a character with a code point, not to be confused with a byte valued integer. Thus Strings and ByteArrays are different things (as opposed to eg. C language).
 
Array
Line 250 ⟶ 252:
a1 collect:#squared -> ditto
a1 count:[:e | e >= 20]. -> 3
a1 occurrencesOf:10 -> 10
.. there are many many more such functions..
 
"converting"
a1 asByteArray -> #[10 20 30]
#(200 300 400) asByteArray -> error raised
(#(65 66 67) collect:#asCharacter) asString -> 'ABC'
 
"searching"
Line 300 ⟶ 307:
d1 removeKey:'one'
d1 includesKey:'two' -> false. "is key present"
d1 includes:2 -> false. "is value present; attention: not O(1)"</lang>
 
Overall there are hundreds of methods implemented in Collection, from which all of the above inherit and which are not listed here.
 
[[Category:Data Structures]]
Anonymous user