Jump to content

Change atom in list directly ?


chavlji

Recommended Posts

I have list of 1.000.000 elements.

Now i have to check each item by each other item:

that is 1mio*1mio/2 iterations. Each time it checks if lets say item i is same as item j. If it is it should delete it.

 

And now the problem:

1mio*1mio is... alot

It is very time consuming. It is not wise to phisicaly delete items that are same. This would take reconstruction of whole list in memory each time. And it would last forever at that amount of items.

 

It would be wiser to mark same items and delete them afterwards:

In C++ I each item of list would be a record consisitng of Deleted:boolean, Value:integer. If two items would be the same I would simply set Deleted value of this item to true.

At the end I would go through all items and erase all that has Deleted true.

 

In lisp I would have a list ( (0,21.5) (0,21.2) (0,43.2) (0,23) ... )

where first item of each item would mean deleted (0 at all showned) and second would be the value.

But how to set 0 to 1 afterwards ? That is:

 

How to change the certain vales inside lists directly ?

Link to comment
Share on other sites

If so, this is from CAB:

 

;;  CAB  12/02/05
(defun unique  (lst / result)
 (while (setq itm (car lst))
   (setq lst    (vl-remove itm lst)
         result (cons itm result)))
 result)

 

You may want to reverse the result of this to keep the items in the correct order :)

Link to comment
Share on other sites

On 1mio*1mio it would take years this way.

It is not right to delete each item along executing. That way the "whole" list will be rewritten lets say 500.000.000.000 times !

Along execution it should only MARK duplicates and construct new list afterwards...

 

But how to MARK an item in lisp?

Link to comment
Share on other sites

A simple form would be:

 

[b][color=BLACK]([/color][/b]defun deldup [b][color=FUCHSIA]([/color][/b]tl / dl[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]foreach a tl
      [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]member a dl[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
          [b][color=MAROON]([/color][/b]setq dl [b][color=GREEN]([/color][/b]cons a dl[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]reverse dl[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]


[b][color=BLACK]([/color][/b]setq  l '[b][color=FUCHSIA]([/color][/b]22 33 44 33 44 33 66 77 88 99 22 44 33
          22 33 44 33 44 33 66 77 88 99 22 44 33
          22 133 144 133 144 133 166 177 88 99 22 44 33
          22 33.1 44.1 33.1 44.1 33 66 77 88 99 22 44 33[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

[b][color=BLACK]([/color][/b]prin1 [b][color=FUCHSIA]([/color][/b]deldup l[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

The amount of time would be dictated by how many duplicates that there are. More duplicates = less time

Link to comment
Share on other sites

That would work but the VL version would be quicker - vl-remove-item takes out all the duplicates of an item in one hit, so you wouldn't need to shuffle through the set. :thumbsup:

Link to comment
Share on other sites

Hey chavlji,

 

What sort of routine are you developing?

 

Is it possible to process and sort the information into smaller lists instead of one large list?

Link to comment
Share on other sites

A simple form would be:

 

[b][color=BLACK]([/color][/b]defun deldup [b][color=FUCHSIA]([/color][/b]tl / dl[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]foreach a tl
      [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]member a dl[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
          [b][color=MAROON]([/color][/b]setq dl [b][color=GREEN]([/color][/b]cons a dl[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]reverse dl[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]


[b][color=BLACK]([/color][/b]setq  l '[b][color=FUCHSIA]([/color][/b]22 33 44 33 44 33 66 77 88 99 22 44 33
          22 33 44 33 44 33 66 77 88 99 22 44 33
          22 133 144 133 144 133 166 177 88 99 22 44 33
          22 33.1 44.1 33.1 44.1 33 66 77 88 99 22 44 33[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

[b][color=BLACK]([/color][/b]prin1 [b][color=FUCHSIA]([/color][/b]deldup l[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

The amount of time would be dictated by how many duplicates that there are. More duplicates = less time

 

David,

 

Try using vl-position in these instances. From my experience it's much faster than member since it only returns the index rather than the item and the remaining list. :)

 

Ron

Link to comment
Share on other sites

On 1mio*1mio it would take years this way.

It is not right to delete each item along executing. That way the "whole" list will be rewritten lets say 500.000.000.000 times !

Along execution it should only MARK duplicates and construct new list afterwards...

 

But how to MARK an item in lisp?

 

A list of 1 milion items!? That is a huge amount of data to process! Im not even sure you got enough stack. (Im interested: Have you retrieved this amount of data or is this still theory?)

 

> But how to MARK an item in lisp?

You cant/dont; Autolisp high level. You got nothing for control.

Link to comment
Share on other sites

You cant/dont; Autolisp high level.

 

You know it has always surprised me that most people don't understand that AutoLsip is a very high level language. We don't have to do any housekeeping anymore. All of the stack heaps, memory allocations, etc are preset. Even Vl is lower due to fact that you must implicitly load its command module (vl-load-com).

 

I've done a bit assmbly langauge stuff in a past life and man was it complicated, Just to know if was going to be a far call or not.

 

-David

Link to comment
Share on other sites

What exactly is the difference between "high-level programming languages" as opposed to other languages?

 

Which is the most powerful?

 

Could you give me some info on the whole levels of programming languages please? :)

Link to comment
Share on other sites

Thanks David - that clears things up nicely.

 

I never realised LISP was a high-level language.... I always thought high level languages needed much more knowledge to write... but I don't really know all that much in the programming background of things.

Link to comment
Share on other sites

I did it!

 

I've created ActiveX DLL in Delphi and registered it in Autocad.

Now I am sending all needed data to DLL wich is actually creating and processing the list with 1 mio items. It then returns a result to VLISP (a list of about 1000 items).

 

I dont think it could be done in VLISP. Even creating a list of 1 mio items seems to be too much time consuming... i interrupted it after 10 minutes.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...