Why associative array is not supporting array ordering method

module g;
int ass[*];
int r[int];
//int q[$];
initial
begin
ass=‘{1:2,2:3,4:5};
r=’{4:9,5:6,7:8};

  $display("%p",ass);
  $display("%p",r);
  r.sort;
  $display("%p",r);
end
  endmodule

ERROR VCP7542 “Cannot apply array ordering methods to an associative array.” “testbench.sv” 14 13
FAILURE “Compile failure 1 Errors 0 Warnings Analysis time: 0[s].”

  1. Associative array r[int] is not support only the array ordering method what is the reason ?
  2. While associative array using the wildcard ass[*] is not support for any array method.

In reply to Om Ganesh B k:

An associative array is not contiguous array while other arrays are contiguous and by default, the index will start from 0. In an associative array, each data we are writing is associated with the random address & hence array ordering methods are not supported by an associative array.

Regards,
Shanthi

In reply to Om Ganesh B k:

An associative array associates a key with a value as a set of key/value pairs. Any attempt in sorting the values would break the association. The key is the index value that selects an array element.

The wildcard key is a typeless index. Certain array methods and the foreach loop construct need to return an index value into a variable, and there is no such thing as a typeless variable in SystemVerilog.

Never use the wildcard key [$] as it prevents you from using these other features. Use [int] instead.

The wildcard feature is left over from earlier language (VERA) that was basis for most of SystemVerilog’s verification features. It did not have the concept of type parameters.

My doubt is cleared now .Thank you dave and shanthi.