[GAP Forum] Is it possible to obtain the size of a dictionary?

Hulpke,Alexander Alexander.Hulpke at colostate.edu
Tue Apr 14 22:49:24 BST 2020


Dear Will Chen, Dear Forum,


> On 14 Apr 2020, at 21:42, Will Chen <oxeimon at gmail.com> wrote:
> 
> Size(...) doesn't seem to work for dictionaries.
> 
> Is there a way to return its size? (or do we have to track it separately as
> we add to it?)
> 

When we designed dictionaries, Size had not been on the list of access functions (as i would be kbnown by the calling algorithm anyhow). However for the current implementations of dictionaries, it would not be hard to add `Size` methods, if they do not exist yet.
I think the following installations shoudl do so.

InstallMethod(Size,"for list dictionaries",true,[IsListDictionary],0,
function(d)
  return Length(d!.list);
end);

InstallMethod(Size,"for list lookup dictionaries",true,
  [IsListLookupDictionary],0,
function(d)
  return Length(d!.entries);
end);

InstallMethod(Size,"for position dictionaries",true,[IsPositionDictionary],0,
function(d)
  return SizeBlist(d!.blist);
end);

InstallMethod(Size,"for hash tables",true,[IsHash],0,
function(ht)
  return ht!.NumberKeys;
end);

Best,

  Alexander Hulpke






More information about the Forum mailing list