TCL/TK reference--variables and processes Array__statistics

Source: Internet
Author: User
Tags glob

.

.

name

Array-dealing with the syntax of arrays variables

array option arrayname arg arg ...?
Description

This command performs one of several options, the object of which is arrayname, unless the following command specifically declares that the arrayname must be the existing array variable name. The option argument determines what action to take on an array variable, as follows:Array anymoreArrayname Searchid If there are remaining elements in an array search, it returns1, if no remaining elements are returned0。 SEARCHID Specifies the search identifier for the checked arrayname, which must be a commandArray StartsearchThe search identifier returned. This command is useful when an array has an element with an empty index, becauseArray NextelementThe return value does not indicate whether the search is complete or not.Array DonesearchArrayname searchid This command ends an array search, Searchid points to an array search identifier that needs to be terminated, which must be a commandArray StartsearchThe search identifier returned. Returns an empty string.Array existsArrayname If Arrayname is an array variable, return1, if you do not have this variable or a non-array variable, return0Array getArrayname? Returns a list of elements in the list that are pairs, alternating indices and corresponding array values, and if pattern is not specified, all elements of the array are returned, and if pattern is specified, only matching pattern (withMatch StringMatches the same style) of the array element returned. Returns an empty list if Arrayname is not the name of an array variable or contains no elements.array NamesArrayname mode? Returns a list of array element indices that match pattern, mode can be-exact-globOr-regexpthat specifies the style of the match, and if mode is not specified, the default is-glob。 If you need to know a detailed matching style please refer toMatch StringAndRegExp。 If pattern is not specified, all indexes in the array are returned, and an empty list is returned if Arrayname is not the name of an array variable or contains no elements.Array NextelementArrayname Searchid Returns the index of the next element in the Arrayname array, and returns an empty string if all the elements in the array are searched, Searchid indicates an array search mark that needs to be terminated, which must be a commandArray StartsearchReturns the search mark. Warning: If an array has an action to add and delete elements, then all searches will end automatically, just like calling theArray Donesearch, which will causeArray NextelementThe operation failed.Array SetArrayname list set one or more array elements, the list must be likeArray getReturns a list of value styles in which the odd list element is considered an element index of arrayname, followed by an even number of list elements as values in the previous element's array, and an empty array arrayname is created if the variable arrayname does not exist or is empty.Array SizeArrayname returns a decimal string value indicating the number of elements in the array, and returns if Arrayname is not an array name0Array StartsearchArrayname This command begins a search of an element in the Arrayname array,Array NextelementCommand returns the index of the next element, and when the search is complete,Array Donesearchcommand must call, the return value is a search identifier, which can beArray NextelementAndArray DonesearchUse to identify the search for an operation by using a search identifier to allow for a different search of an array at the same time. At present, the commonly used way is to useArray getAndarray NamesAndforeachUsed to traverse each element of the array. Please refer to the example below for details.Array StatisticsArrayname returns the statistics on how the elements in the array are allocated in the hash table, which contains the number of entries in the tables, the number of buckets, and the utilization of the buckets.array unsetArrayname? Deletes all elements in the array that match pattern (withMatch StringMatching style), if Arrayname is not an array variable or does not match any element, does not produce an error, if the pattern variable is omitted and Arrayname is an array name, this command will delete all elements of the entire array, which always returns an empty string.Sample

Array Set Colorcount {
   Red   1
   Green 5
   Blue  4
   White 9

foreach {color count} [array get Colorcount] {
   Puts "Color: $color Count: $count"
}
  Color:blue Count:4
    Color:white Count:9
    Color:green Count:5
    Color:red count:1
foreach color [array names Colorcount] {
   Puts "Color: $color Count: $colorcount ($color)"
}
  Color:blue Count:4
    Color:white Count:9
    Color:green Count:5
    color:red count:1

foreach color [lsort [array names Colorcount]] {
   Puts "Color: $color Count: $colorcount ($color)"
}
  Color:blue Count:4
    Color:green Count:5
    Color:red count:1
    Color:white count:9

Array statistics Colorcount
  4 entries in table, 4 buckets
    Number of buckets with 0 entries:1
    Number of buckets with 1 entries:2
    Number of buckets with 2 entries:1
    Number of buckets with 3 entries:0
    Number of buckets with 4 entries:0
    Number of buckets with 5 entries:0
    Number of buckets with 6 entries:0
    Number of buckets with 7 entries:0
    Number of buckets with 8 entries:0
    Number of buckets with 9 entries:0
    Number of buckets with or more entries:0
    Average search distance for entry:1.2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.