logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: ExtArray?: msg#00004

Subject: Re: ExtArray?
Here are a couple more functions which I propose for addition to
ExtArray:

  (* Swap two elements in an array. *)
  let swap xs i j =
    if i <> j then (
      let c = xs.(i) in
      xs.(i) <- xs.(j);
      xs.(j) <- c
    )
  
  (* Randomize an array (in place). *)
  let unsort xs =
    let n = Array.length xs in
    for i = 0 to n-2 do
      let j = Random.int (n - i) in
      swap xs i j
    done

If you like those, then one for ExtList:

  (* Randomize a list. *)
  let unsort xs =
    let xs = Array.of_list xs in
    Array.unsort xs;
    Array.to_list xs

Rich.

-- 
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click


<Prev in Thread] Current Thread [Next in Thread>