Skip to content

Instantly share code, notes, and snippets.

@lpvm
Created November 25, 2015 12:50
Show Gist options
  • Save lpvm/40395a23a9c808d75cc5 to your computer and use it in GitHub Desktop.
Save lpvm/40395a23a9c808d75cc5 to your computer and use it in GitHub Desktop.
let insert db contact =
if db.number_of_contacts >= Array.length db.contacts then
(false, db, nobody)
else
let (status, db, _) = search db contact in
if status then (false, db, contact) else
let cells i =
if i = db.number_of_contacts then contact else db.contacts.(i)
in
let db' = {
number_of_contacts = db.number_of_contacts + 1;
contacts = Array.init (Array.length db.contacts) cells
}
in
(true, db', contact);;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment