Post Reply 
Z LST: List handling API
01-16-2017, 05:04 PM (This post was last modified: 01-16-2017 05:05 PM by StephenG1CMZ.)
Post: #1
Z LST: List handling API
A few list handling routines

Stephen Lewkowicz (G1CMZ)
Visit this user's website Find all posts by this user
Quote this message in a reply
01-16-2017, 05:07 PM
Post: #2
RE: Z LST: List handling API
Version 0.001

Code:


 // List routines V0.001 StephenG1CMZ 2017

 LOCAL TM;

 LST_HasDups (LST,AnBOOL)
 // RETURNS EITHER
 // BOOL:"0 OR 1" IF element duplicated in LST
 // OR POSITION OF 1st duplicate (slower)
 BEGIN
  LOCAL PS;
  LOCAL II:=1;
  IF SIZE(LST)≤1 THEN
   RETURN 0;//SMALL LST==NO DUPS
  ELSE
 
   WHILE POS(LST,LST(II))==II  AND II<SIZE(LST) DO
    II:=II+1;
   END;
 
   IF AnBOOL THEN
    //RETURN BOOL
    IF II<SIZE(LST) THEN
     RETURN 1;//QUICKER THAN POS
    ELSE 
     RETURN (POS(LST,LST(II))<II); //BOOL
    END;
   ELSE 
    //RETURN POSITION
    IF II<SIZE(LST) THEN
     RETURN II;
    ELSE
     PS:=POS(LST,LST(II));
     RETURN IFTE(PS==SIZE(LST),0,PS);
    END;
   END;
  END;
 END;

 EXPORT IZ_HasDups(LST)
 //RETURN 1 if LST Has Duplicates ELSE 0
 BEGIN
  RETURN LST_HasDups(LST,1);
 END;

 EXPORT ZMISSINGPROC() 
 //WHY IS THIS MISSING FROM RUN LIST?
 BEGIN
 END;

 EXPORT Z_LST_Once(LST)
 //Return LST with duplicates occuring once. Input unchanged.
 BEGIN
  LOCAL II;
  LOCAL OUTLST:={};

  //THIS SOLN-WORKS WHEREVER POS RECOGNISES ELEMENT WITHIN LST
  FOR II FROM 1 TO SIZE(LST)  DO
   IF POS(OUTLST,LST(II))==0 THEN //NOT YET LISTED
    OUTLST(0):=LST(II); 
   END;
  END;
  RETURN OUTLST;
  //EACH ITEM NOW OCCURS ONCE ONLY 
 END;

 EXPORT Z_LST_OnceCS(LST)
 //As LST_Once: Using CAS. 
 BEGIN
  LOCAL SL:=STRING(LST); 
  LOCAL st;

  st:=SL+" union "+SL;
  mat2list(CAS(st));
 END;

 EXPORT Z_POS_HasDups(LST)
 //RETURN position of 1st Duplicate ELSE 0
 //If you do not need position: IZ_HasDups returns 01
 BEGIN
  RETURN LST_HasDups(LST,0);
 END;

 EXPORT Z_LST()
 BEGIN
  LOCAL NN;
  LOCAL UNIQUELST:={};
  LOCAL LST:=IP(RANDOM(1000,1,1ᴇ8));
 
  UNIQUELST:=Z_LST_Once({1,2,2,2,2,3});
  UNIQUELST:=Z_LST_OnceCS({1,2,2,2,2,3});
 
  PRINT("WORKING");
  TM:=TICKS;
  NN:=LST_HasDups(LST,1);
  MSGBOX(NN+" in "+(TICKS-TM));
  //RETURN UNIQUELST;
 END;

Stephen Lewkowicz (G1CMZ)
Visit this user's website Find all posts by this user
Quote this message in a reply
11-01-2017, 02:10 AM
Post: #3
RE: Z LST: List handling API
For whatever reason, the missing procedure now shows up in the run list, both on the current compiler and 8151.

I have created a new more comprehensive list API, without using this file in case it contained a rogue character...this thread is now deprecated and may be deleted in due course.
http://www.hpmuseum.org/forum/thread-9411.html

Stephen Lewkowicz (G1CMZ)
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)