Is there any particular reason you are using a hash table to store this information? It seems like you would be better off using an ordered method of storing information such as a window or file.
In that case you could use aline to add entries and something like:
if ($line(@mydata,0) > 1000) dline @mydata 1- $+ $calc($v1 - 1000)
to trim it down to 1000 entries.