Doubly Linked List search without traversal - doubly-linked-list

How to search an element in a doubly linked list without traversing the linked list and deleting any node from it?
I'm looking for solutions but I'm getting stuck with the conditions provided. It's simple with the deletion process, you simply check the beginning node and keep on deleting if not present. But that is also not allowed.

Related

DOM querySelectorAll - element ID not starting with

In an HTML document I have a large inline SVG object with groups bearing a variety of IDs (or none at all). I want to find all groups other than those whose IDs start with the letter sequences l0pzlo, l1pzloand l2pzlo. The task of finding just those IDs is easy
element.querySelectorAll("[id^=l0pzlo_],[id^=l1pzlo_],[id^=l2pzlo_]")
does the trick. However, I cannot work out how to get only those elements whose IDs DO NOT start with any of the three prefixes given above. I have attempted to use :notin a variety of different ways, e.g.
element.querySelectorAll(:not('[(id^=l0pzlo)]'))";
but nothing seems to be to the liking of the browser. How can I do this?
I think it would be more useful to leave my own answer here rather than just delete the question
element.querySelectorAll('*:not([id^=l0pzlo]):not([id^=l1pzlo]):not([id^=l2pzlo])');
works. Think of it as going about the task of filtering in a non-greedy way. First you get absolutely everything and then progressively filter out what you don't need with a sequence of one or more :nots

Perl: Quickly find object in list of objects - looking for a fitting datastructure

I am developing a program to sync users between to different LDAP Servers. I have two types of user groups: Master-Groups and Target-Groups (those are predefined in a config-file. There can be multiple Master and Targets per Group definition).
Users in Master-Groups missing in the Target-Groups shall be added to the Targets, Users in Target-Groups missing in Master-Groups shall be removed from the Targets.
The Users in those Groups are Objects themselves. My problem is as follows:
I loop through my availiable master groups and have to perform a quick lookup wheter a user is already part of a target-group. I am struggeling to pick the right datastructure to solve this problem. I tried using a hash, but quickly realized that hash-keys are stringyfied, so I cannot perform
if ( exists( $master_members->{$target_user_object} ) )
When using an array for storing the objects, everytime I have to check if a user object exists, I have to loop through the whole array which essentially kills performance.
How do I perfom a lookup if a specific object exists in a list of objects?
Kind Regards,
Yulivee
You're right that hash keys are stringified. You cannot use objects as keys. But a hash is the right data structure.
Instead of just letting Perl stringify your references, build your own serializer. That could be as simple as using the cn. Or a concatenation of all the fields of the object. Make a sub, put that in there, call that sub within your exist.
... if exists $master_members->{ my_serializer($target_user_object) };

Doubly linked list of process control block in Operating Systems

What is the reasoning behind maintaining doubly linked lists of PCB's(process control blocks) in an OS for scheduling. I have seen this mentioned multiple times for Real time operating systems.
I would ideally go for a circular singly linked list , so that you could do a round robin and reach back to 1st task after looking to all. You could also sort it by priority...
But, why a doubly linked list?
You have made the assumption that you would always want to start at the head, and work towards the end of the list. This may not be true. Say you are swapping one process out (eg it is pending on a sempahore). You already have the current process control block, so it makes sense to start using the information you have rather than iterate through the entire list.
Because the PCB has a reference to both the previous and the next, you can cut that node out of the running-list, and move to a pended-list, or from a pended-list back into a ready-to-run list etc, without having to iterate all the way through.

Mongoid: correctly using association callbacks with forms

I have come across a problem which I am struggling to solve elegantly. I am more versed in RDBMSs so the way I am doing things may not be ideal.
What I am doing:
I am having to keep track of items within a HABTM association. Whats more, there is a condition on the count as only items that are 'active' are counted. I have successfully used the association callbacks to track additions and removals from the collection.
The problem:
I am also adding items to the collection via forms by setting the opposite instance's id to the form as a hidden field. This works fine, however the problem is that this adds the opposite instance straight to the collection without invoking the callback (the age old problem).
My Question:
Is there a more elegant way to add add instances to the collection that invokes the callback?
Let me know if you need any more specific examples and I'll happily provide some.
Have you try using the following mongoid3 callbacks?
after_add
after_remove
before_add
before_remove
More information here

Trees - saving parent path

I have an embedded (updatable) tree structure in an array - considering the upcoming $slice abilities to select only parts of an array, I'm thinking of implementing a way to display only one (sub-)branch of the tree.
If I understand correctly, to do this efficiently, I'd have to save the path (grandparent.parent.child) in each item in the tree.
However, I can't see a nice way of managing these paths (when updating), looks like these are my options:
trusting client-side parameters blindly and just inserting to the array without verification of the path.
fetching the entire document, compute the path and only then store the new item
What do you think? Branches cannot move around in the tree, they are only inserted/updated.
I just didn't think about deep enough. At the time of insertion I currently have only a parent-id, but when I start having paths - I can use them to find the parent, then I can verify that the parent exist exactly in the same way as I'm currently doing it with parent-id.
The only problem with this approach is that I'd need to save the path even for branches that don't have a parent (children of root).
Then, I can just search for them in the array with the mongo query and if they don't exist the path is bogus and I stop the update.