LPC Library Functions: allocate_mapping

NAME

allocate_mapping() - pre-allocate space for a mapping

SYNOPSIS

mapping allocate_mapping( int size );

mapping allocate_mapping( mixed *keys, mixed v );

DESCRIPTION

In the first form, returns a mapping with space for 'size' elements preallocated.

For example:

    mapping x;
    int y = 200;

    x = allocate_mapping(y);

In this example, y is the initial size of the mapping. For efficiency of storage, using allocate_mapping is the preferred way to initalize the mapping if you have some idea of how many elements the map will contain. Note that doing so does not restrict you to a fixed number of elements. If you will be deleting many elements from the mapping, you should use x = ([]) to initialize the mapping rather than using allocate_mapping().

In the second form of allocate_mapping(), 'keys' will be the initial keys of the mapping and 'v' will be used to initialize the values of the mapping.

  • if 'v' is an array, the returned array has keys 'keys' and values 'v'
  • if 'v' a function, the the mapping has keys 'keys' and values evaluate(v, key)
  • otherwise, each key has the value 'v'

SEE ALSO

map_delete()

Page design by Frank Jacquette & Tim Hollebeek
Copyright (C) 1998 Tim Hollebeek & Frank Jacquette
Back to MudOS