shankslog(a,g,card)=
{
  my(M=Map());
  my(h=a,B=sqrtint(card)+1);
  for(i=0,B-1,
    mapput(~M,h,i);
    h*=g);
  g2=h*a^-1;
  h=1;
  for(i=0,B,my(j);
    if(mapisdefined(M,h,&j),
      return(i*B-j));
    h*=g2);
  error("shankslog: not found");
}
if(Mod(2,1000003)^shankslog(Mod(3,1000003),Mod(2,1000003),1000002)!=3, error("shankslog"));

tablelog(g,card)=
{
  my(M=Map());
  my(h=1);
  for(i=0,card-1,
    mapput(~M,h,i);h*=g);
  M;
}
tablelogdel(g,card)=
{
  my(M=Map());
  my(h=1);
  for(i=0,card-1,
    mapput(~M,h,i);h*=g);
  h=1;
  for(i=0,card-1,
    mapdelete(~M,h);h*=g);
  #M;
}
a=ffgen(5^5,'a); g=ffprimroot(a); T=tablelog(g,5^5-1);
if(g^mapget(T,a^2+a+1)!=a^2+a+1,error("shankslog"));
if(tablelogdel(g,5^5-1),error("mapdelete"));

M=Map([1,2;3,4;5,6])
Vec(M)
Vecrev(M)
Mat(M)
apply(sqr,M)
for(i=0,2,mapput(~M, 2*i+1, -mapget(M,2*i+1)));M

M0=Map(matrix(10,2,i,j,i));
M1=Map(matrix(10,2,i,j,if(j==1,i,i*x^0)));
M2=Map(matrix(10,2,i,j,11-i));
M3=Map(matrix(10,2,i,j,12-i));
M4=Map(matrix(10,2,i,j,i*x^0));
MV=[M0,M1,M2,M3,M4];
[a==b|a<-MV;b<-MV]
[a===b|a<-MV;b<-MV]
cmp(M0,M1)
cmp(M0,M0)

M=Map();
mapput(~M,2,3);
mapdelete(~M,2);
M
mapisdefined(M,2)
mapput(~M,2,3);M

bagput(~M,k,v)=my(z=List());mapisdefined(M,k,&z);listput(~z,v);mapput(~M,k,z);
get(N,q)=
{
  my(M=Map());
  forprime(p=2,N,bagput(~M,p%q,p));
  Mat(M);
}
get(100,10)

M=Map([1,2;3,4;5,6]);
mapget(M,7)
mapdelete(~M,7)
Vec(M,1)
Vec(M,-1)
[Map(Mat([0, 0])), [0, 0, 1]]

maplistput(~M,k,v) = mapapply(~M,k,(~y)->listput(~y,v),()->List(v));
maplisterr(~M,k,v) = mapapply(~M,k,(~y)->listput(~y,v));
M = Map(["a",List(); "b",List()])
maplistput(~M,"a",1); M
maplistput(~M,"a",2); M
maplistput(~M,"c",3); M
maplistput(~M,"c",4); M
maplisterr(~M,"b",5); M

\\ Errors, keep at end
maplisterr(~M,"d",6);
Map([1,2;2,3;1,3;1,4])
L=List();
mapdelete(1,1)
mapdelete(~L,1)
mapget(1,1)
mapget(L,1)
mapisdefined(1,1)
mapisdefined(L,1)
mapput(1,1)
mapput(~L,1)
Map(1)
