clear loMyClass=createobject('SparseMatrix2D', 'I') RAND(-1) lnStart = seconds() for ln1 = 1 to 1000 for ln2 = 1 to 1000 lnValue = IIF(RAND()> 0.8, rand() * 100000, 0) && Will end up with around 200,000 records IF m.lnValue > 0 loMyClass.data[m.ln1, m.ln2] = lnValue endif next ln2 next ln1 ? seconds() - lnStart && Takes 3 seconds, not the fastest kid in the block :( lnStart = seconds() ? loMyClass.data[2, 5] ? seconds() - lnStart loMyClass.browse() define class SparseMatrix2D as session dimension data(1, 1) procedure browse() browse last normal endproc procedure Data_assign(m.vNewVal, m.nIndex1, m.nIndex2) if indexseek(bintoc(m.nIndex1) + bintoc(m.nIndex2), .t., 'cData', 'RowCol') replace value with m.vNewVal in cData else insert into cData (row, column, value) values (m.nIndex1, m.nIndex2, m.vNewVal) endif endfunc procedure Data_Access(m.nIndex1, m.nIndex2) return iif(indexseek(bintoc(m.nIndex1) + bintoc(m.nIndex2), .t., 'cData', 'RowCol'), cData.value, 0) endfunc function init(tcValueType as string) as VOID local lcCommand lcCommand = 'CREATE CURSOR cData (Row I, Column I, Value ' + tcValueType + ')' execscript(lcCommand) index on bintoc(row) + bintoc(column) tag rowcol return .t. endfunc enddefine