package com.github.vlsi.mat.optiq;

public class HeapFunctions {
    public static int get_id(Object r) {
        if (r == null || !(r instanceof HeapReference)) return -1;
        return ((HeapReference) r).getIObject().getObjectId();
    }

    public static String toString(Object r) {
        if (r == null) return null;
        return r.toString();
    }
}

@@ -33,141 +33,608 @@
 q;%0A%0A
-public class HeapFunctions %7B%0A    public static int get_id(Object r) %7B%0A        if (r == null %7C%7C !(r instanceof HeapReference))
+import org.eclipse.mat.SnapshotException;%0Aimport org.eclipse.mat.snapshot.ISnapshot;%0Aimport org.eclipse.mat.snapshot.model.*;%0A%0Apublic class HeapFunctions %7B%0A    public static int get_id(Object r) %7B%0A        HeapReference ref = ensureHeapReference(r);%0A        return ref == null ? -1 : ref.getIObject().getObjectId();%0A    %7D%0A%0A    public static String toString(Object r) %7B%0A        if (r == null) return null;%0A        return r.toString();%0A    %7D%0A%0A    public static Object get_by_key(Object r, String value) %7B%0A        HeapReference ref = ensureHeapReference(r);%0A        if (ref == null) %7B%0A           
  return 
 -1;%0A
@@ -629,18 +629,20 @@
  return 
--1
+null
 ;%0A      
@@ -647,80 +647,1878 @@
     
-return ((HeapReference) r).getIObject().getObjectId();%0A    %7D%0A%0A    public
+%7D%0A        IObject iObject = ref.getIObject();%0A        ISnapshot snapshot = iObject.getSnapshot();%0A        String className = iObject.getClazz().getName();%0A%0A        if (!%22java.util.HashMap%22.equals(className))%0A        %7B%0A            throw new RuntimeException(%22Unsupported map type: %22+className);%0A        %7D%0A%0A        try%0A        %7B%0A            IObjectArray table = (IObjectArray)iObject.resolveValue(%22table%22);%0A            long%5B%5D referenceArray = table.getReferenceArray();%0A            for (long entryAddress : referenceArray)%0A            %7B%0A                if (entryAddress != 0)%0A                %7B%0A                    int entryId = snapshot.mapAddressToId(entryAddress);%0A                    IObject entry = snapshot.getObject(entryId);%0A                    while (entry != null)%0A                    %7B%0A                        IObject keyObject = (IObject) entry.resolveValue(%22key%22);%0A                        if (value.equals(toString(keyObject)))%0A                        %7B%0A                            IObject valueObject = (IObject) entry.resolveValue((%22value%22));%0A                            if (valueObject != null)%0A                            %7B%0A                                return new HeapReference(snapshot, valueObject);%0A                            %7D%0A                            else%0A                            %7B%0A                                return null;%0A                            %7D%0A                        %7D%0A%0A                        entry = (IObject)entry.resolveValue(%22next%22);%0A                    %7D%0A                %7D%0A            %7D%0A        %7D catch (SnapshotException e)%0A        %7B%0A            throw new RuntimeException(e);%0A        %7D%0A%0A        return null;%0A    %7D%0A%0A    private static HeapReference ensureHeapReference(Object r) %7B%0A        return (r == null %7C%7C !(r instanceof HeapReference)) ?%0A                null :%0A                (HeapReference) r;%0A    %7D%0A%0A    private
  sta
@@ -2533,32 +2533,33 @@
 ng toString(
+I
 Object 
-r
+o
 ) %7B%0A        
@@ -2562,34 +2562,124 @@
     
-if (r == null) return null
+String classSpecific = o.getClassSpecificName();%0A        if (classSpecific != null)%0A            return classSpecific
 ;%0A  
@@ -2687,34 +2687,40 @@
      return 
-r.toString
+o.getDisplayName
 ();%0A    %7D%0A%7D%0A

Add get_by_key function to extract value by key from HashMaps