Search Results

Search found 3339 results on 134 pages for 'hash collision'.

Page 30/134 | < Previous Page | 26 27 28 29 30 31 32 33 34 35 36 37  | Next Page >

  • Turning a nested hash structure into a non-nested hash structure - is this the cleanest way to do it

    - by knorv
    Assume a nested hash structure %old_hash .. my %old_hash; $old_hash{"foo"}{"bar"}{"zonk"} = "hello"; .. which we want to "flatten" (sorry if that's the wrong terminology!) to a non-nested hash using the sub &flatten(...) so that .. my %h = &flatten(\%old_hash); die unless($h{"zonk"} eq "hello"); The following definition of &flatten(...) does the trick: sub flatten { my $hashref = shift; my %hash; my %i = %{$hashref}; foreach my $ii (keys(%i)) { my %j = %{$i{$ii}}; foreach my $jj (keys(%j)) { my %k = %{$j{$jj}}; foreach my $kk (keys(%k)) { my $value = $k{$kk}; $hash{$kk} = $value; } } } return %hash; } While the code given works it is not very readable or clean. My question is two-fold: In what ways does the given code not correspond to modern Perl best practices? Be harsh! :-) How would you clean it up?

    Read the article

  • Sort by values from hash table - Ruby

    - by Adnan
    Hello, I have the following hash of countries; COUNTRIES = { 'Albania' => 'AL', 'Austria' => 'AT', 'Belgium' => 'BE', 'Bulgaria' => 'BG', ..... } Now when I output the hash the values are not ordered alphabetically AL, AT, BE, BG ....but rather in a nonsense order (at least for me) How can I output the hash having the values ordered alphabetically?

    Read the article

  • [Haskell]Curious about the Hash Table problem

    - by astamatto
    I read that hash tables in haskell are crippled ( citation: http://flyingfrogblog.blogspot.com/2009/04/more-on-haskells-hash-table-problems.html ) and since i like haskell it worried me. Since the blog-post one year has passed and im curious, The hash table problem in haskell was "fixed" in the traditional compilers? (like ghc) ps: I love stack overflow, im a long time visitor but only today i decided to try to post a question.

    Read the article

  • Cleaning up code - flatten a nested hash structure

    - by knorv
    The following Perl sub flattens a nested hash structure: sub flatten { my $hashref = shift; my %hash; my %i = %{$hashref}; foreach my $ii (keys(%i)) { my %j = %{$i{$ii}}; foreach my $jj (keys(%j)) { my %k = %{$j{$jj}}; foreach my $kk (keys(%k)) { my $value = $k{$kk}; $hash{$kk} = $value; } } } return %hash; } While the code works it is not very readable or clean. My question is two-fold: In what ways does it not correspond to modern Perl best practices? How would you clean it up?

    Read the article

  • Combine hash values in C#

    - by Chris
    I'm creating a generic object collection class and need to implement a Hash function. I can obviously (and easily!) get the hash values for each object but was looking for the 'correct' way to combine them to avoid any issues. Does just adding, xoring or any basic operation harm the quality of the hash or am I going to have to do something like getting the objects as bytes, combining them and then hashing that? Cheers in advance

    Read the article

  • How can I marshal a hash with arrays?

    - by tuner
    What should I do to marshal an hash of arrays? The following code only prints {}. s = Hash.new s.default = Array.new s[0] << "Tigger" s[7] << "Ruth" s[7] << "Puuh" data = Marshal.dump(s) ls = Marshal.restore( data ) p ls If the hash doesn't contain an array it is restored properly.

    Read the article

  • Hash value in the manifest file.

    - by satishtech
    Hello, Im tring to create a manifest for my own.dll, i took the manifest file from C:\WINDOWS\WinSxS\Manifests for example. In that, below tag was one of the line.<file name="msvcr90.dll" hashalg="SHA1" hash="e0dcdcbfcb452747da530fae6b000d47c8674671"> In above tag, hash value was assigned with 40 character. Here comes my doubt, 1) hash value was auto generated, if not, whats it points to?

    Read the article

  • How do I access a value of a nested Perl hash?

    - by st
    I am new to Perl and I have a problem that's very simple but I cannot find the answer when consulting my Perl book. When printing the result of Dumper($request); I get the following result: $VAR1 = bless( { '_protocol' => 'HTTP/1.1', '_content' => '', '_uri' => bless( do{\(my $o = 'http://myawesomeserver.org:8081/counter/')}, 'URI::http' ), '_headers' => bless( { 'user-agent' => 'Mozilla/5.0 (X11; U; Linux i686; en; rv:1.9.0.4) Gecko/20080528 Epiphany/2.22 Firefox/3.0', 'connection' => 'keep-alive', 'cache-control' => 'max-age=0', 'keep-alive' => '300', 'accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'accept-language' => 'en-us,en;q=0.5', 'accept-encoding' => 'gzip,deflate', 'host' => 'localhost:8081', 'accept-charset' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7' }, 'HTTP::Headers' ), '_method' => 'GET', '_handle' => bless( \*Symbol::GEN0, 'FileHandle' ) }, 'HTTP::Server::Simple::Dispatched::Request' ); How can I access the values of '_method' ('GET') or of 'host' ('localhost:8081'). I know that's an easy question, but Perl is somewhat cryptic at the beginning.

    Read the article

  • in ruby, how do you make this nested hash work?

    - by David
    this one creates an error: @settings = { :tab1 => { :name => { :required => true }, :description } } need to change :descrpition to :description = {}, but i don't have any values for :description so i want it to remain as is (without the empty = {}) Would you show me the best way to handle this kind of situation? thanks in advance

    Read the article

  • How can I merge several hashes into one hash in Perl?

    - by Nick
    In Perl, how do I get this: $VAR1 = { '999' => { '998' => [ '908', '906', '0', '998', '907' ] } }; $VAR1 = { '999' => { '991' => [ '913', '920', '918', '998', '916', '919', '917', '915', '912', '914' ] } }; $VAR1 = { '999' => { '996' => [] } }; $VAR1 = { '999' => { '995' => [] } }; $VAR1 = { '999' => { '994' => [] } }; $VAR1 = { '999' => { '993' => [] } }; $VAR1 = { '999' => { '997' => [ '986', '987', '990', '984', '989', '988' ] } }; $VAR1 = { '995' => { '101' => [] } }; $VAR1 = { '995' => { '102' => [] } }; $VAR1 = { '995' => { '103' => [] } }; $VAR1 = { '995' => { '104' => [] } }; $VAR1 = { '995' => { '105' => [] } }; $VAR1 = { '995' => { '106' => [] } }; $VAR1 = { '995' => { '107' => [] } }; $VAR1 = { '994' => { '910' => [] } }; $VAR1 = { '993' => { '909' => [] } }; $VAR1 = { '993' => { '904' => [] } }; $VAR1 = { '994' => { '985' => [] } }; $VAR1 = { '994' => { '983' => [] } }; $VAR1 = { '993' => { '902' => [] } }; $VAR1 = { '999' => { '992' => [ '905' ] } }; to this: $VAR1 = { '999:' => [ { '992' => [ '905' ] }, { '993' => [ { '909' => [] }, { '904' => [] }, { '902' => [] } ] }, { '994' => [ { '910' => [] }, { '985' => [] }, { '983' => [] } ] }, { '995' => [ { '101' => [] }, { '102' => [] }, { '103' => [] }, { '104' => [] }, { '105' => [] }, { '106' => [] }, { '107' => [] } ] }, { '996' => [] }, { '997' => [ '986', '987', '990', '984', '989', '988' ] }, { '998' => [ '908', '906', '0', '998', '907' ] }, { '991' => [ '913', '920', '918', '998', '916', '919', '917', '915', '912', '914' ] } ]};

    Read the article

  • Calculate sum of objects for each unique object property in Ruby

    - by macek
    I was helping with an answer in this question and it sparked a question of my own. Pie is an object that has a pieces array made of of PiePiece objects. Each PiePiece has a flavor attribute How do I create a hash that looks like this: # flavor => number of pieces { :cherry => 3 :apple => 1 :strawberry => 2 } This works, but I think it could be improved def inventory hash = {} pieces.each do |p| hash[p.flavor] ||= 0 hash[p.flavor] += 1 end hash end Any ideas?

    Read the article

  • Why is mesh baking causing huge performance spikes?

    - by jellyfication
    A couple of seconds into the gameplay on my Android device, I see huge performance spikes caused by "Mesh.Bake Scaled Mesh PhysX CollisionData" In my game, a whole level is a parent object containing multiple ridigbodies with mesh colliders. Every FixedUpdate(), my parent object rotates around the player. Rotating the world causes mesh scaling. Here is the code that handles world rotation. private void Update() { input.update(); Vector3 currentInput = input.GetDirection(); worldParent.rotation = initialRotation; worldParent.DetachChildren(); worldParent.position = transform.position; world.parent = worldParent; worldParent.Rotate(Vector3.right, currentInput.x * 50f); worldParent.Rotate(Vector3.forward, currentInput.z * 50f); } How can I get rid of mesh scaling ? Mesh.Bake physx seems to take effect after some time, is it possible to disable this function ? The profiler looks like this: Bottom-left panel shows data before spikes, the right after

    Read the article

  • Creating the “game space” for a 2D game

    - by alJaree
    How does one setup the game space for a game so that obstacles can be spawned? One example I am wondering about is doodle jump. Tile maps are limited in size and would need to change often if the user jumps a lot. How would this be done in another way than tile maps. How or what is used to create the notion of a game world where these spawned ledges/obstacles are placed as the user progresses through the stage? What is actually moving if the user jumps from ledge to ledge, what are the ledges based on in terms of the game world/space. What data structure or representation could the game use to reference and manage the spawning of these obstacles/ledges?

    Read the article

  • Box2D Static-Dynamic body joint eliminates collisions

    - by andrewz
    I have a static body A, and a dynamic body B, and a dynamic body C. A is filtered to not collide with anything, B and C collide with each other. I wish to create a joint between B and A. When I create a joint (ex. revolute), B no longer collides with C - C passes through it as if it does not exist. What am I doing wrong? How can adding a joint prevent a body from colliding with another body it used to? EDIT: I want to join B with A, and have B collide with C, but not A collide with C. In realistic terms, I'm trying to create a revolute joint between a wheel (B) and a wall (A), and have a box (C) hit the wheel and the wheel would then rotate. EDIT: I create a the simplest revolute joint I can with these parameters (C++): b2RevoluteJointDef def; def.Initialize(A, B, B -> GetWorldCenter()); world -> CreateJoint(&def);

    Read the article

  • How to set a target as image [on hold]

    - by Zadalaxmi
    How to set a target as image in given code. public void addListenerForImage(final Image roomImage) { final DragAndDrop dragAndDrop = new DragAndDrop(); dragAndDrop.addSource(new DragAndDrop.Source(roomImage) { public DragAndDrop.Payload dragStart (InputEvent event, float x, float y, int pointer) { DragAndDrop.Payload payload = new DragAndDrop.Payload(); payload.setDragActor(roomImage); dragAndDrop.setDragActorPosition(-x, -y + roomImage.getHeight()); return payload; } public void dragStop (InputEvent event, float x, float y, int pointer,Target target) { roomImage.setBounds(50, 125, roomImage.getWidth(), roomImage.getHeight()); if(target != null) { roomImage.setPosition(target.getActor().getX(), target.getActor().getY()); } System.out.println(target); stage.addActor(roomImage); } }); My problem is i can drag the images and i am not able to set target as image; and target shows as null;One more if a invisible some of the images in group how can i test that it is overlapped or not;Please give some links and suggestion

    Read the article

  • Algorithm for spreading labels in a visually appealing and intuitive way

    - by mac
    Short version Is there a design pattern for distributing vehicle labels in a non-overlapping fashion, placing them as close as possible to the vehicle they refer to? If not, is any of the method I suggest viable? How would you implement this yourself? Extended version In the game I'm writing I have a bird-eye vision of my airborne vehicles. I also have next to each of the vehicles a small label with key-data about the vehicle. This is an actual screenshot: Now, since the vehicles could be flying at different altitudes, their icons could overlap. However I would like to never have their labels overlapping (or a label from vehicle 'A' overlap the icon of vehicle 'B'). Currently, I can detect collisions between sprites and I simply push away the offending label in a direction opposite to the otherwise-overlapped sprite. This works in most situations, but when the airspace get crowded, the label can get pushed very far away from its vehicle, even if there was an alternate "smarter" alternative. For example I get: B - label A -----------label C - label where it would be better (= label closer to the vehicle) to get: B - label label - A C - label EDIT: It also has to be considered that beside the overlapping vehicles case, there might be other configurations in which vehicles'labels could overlap (the ASCII-art examples show for example three very close vehicles in which the label of A would overlap the icon of B and C). I have two ideas on how to improve the present situation, but before spending time implementing them, I thought to turn to the community for advice (after all it seems like a "common enough problem" that a design pattern for it could exist). For what it's worth, here's the two ideas I was thinking to: Slot-isation of label space In this scenario I would divide all the screen into "slots" for the labels. Then, each vehicle would always have its label placed in the closest empty one (empty = no other sprites at that location. Spiralling search From the location of the vehicle on the screen, I would try to place the label at increasing angles and then at increasing radiuses, until a non-overlapping location is found. Something down the line of: try 0°, 10px try 10°, 10px try 20°, 10px ... try 350°, 10px try 0°, 20px try 10°, 20px ...

    Read the article

  • Libgdx detect when player is outside of screen

    - by Rockyy
    Im trying to learn libGDX (coming from XNA/MonoDevelop), and I'm making a super simple test game to get to know it better. I was wondering how to detect if the player sprite is outside of the screen and make it so it is impossible to go outside of the screen edges. In XNA you could do something like this: // Prevent player from moving off the left edge of the screen if (player.Position.X < 0) player.Position = new Vector2(0, player.Position.Y); How is this achieved in libgdx? I think it's the Stage that handles the 2D viewport in libgdx? This is my code so far: private Texture texture; private SpriteBatch batch; private Sprite sprite; @Override public void create () { float w = Gdx.graphics.getWidth(); float h = Gdx.graphics.getHeight(); batch = new SpriteBatch(); texture = new Texture(Gdx.files.internal("player.png")); sprite = new Sprite(texture); sprite.setPosition(w/2 -sprite.getWidth()/2, h/2 - sprite.getHeight()/2); } @Override public void render () { Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); if(Gdx.input.isKeyPressed(Input.Keys.LEFT)){ if(Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT)) sprite.translateX(-1f); else sprite.translateX(-10.0f); } if(Gdx.input.isKeyPressed(Input.Keys.RIGHT)){ if(Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT)) sprite.translateX(1f); else sprite.translateX(10f); } batch.begin(); sprite.draw(batch); batch.end(); }

    Read the article

  • A* Jump Point Search - how does pruning really work?

    - by DeadMG
    I've come across Jump Point Search, and it seems pretty sweet to me. However, I'm unsure as to how their pruning rules actually work. More specifically, in Figure 1, it states that we can immediately prune all grey neighbours as these can be reached optimally from the parent of x without ever going through node x However, this seems somewhat at odds. In the second image, node 5 could be reached by first going through node 7 and skipping x entirely through a symmetrical path- that is, 6 -> x -> 5 seems to be symmetrical to 6 -> 7 -> 5. This would be the same as how node 3 can be reached without going through x in the first image. As such, I don't understand how these two images are not entirely equivalent, and not just rotated versions of each other. Secondly, I'd like to understand how this algorithm could be generalized to a three-dimensional search volume.

    Read the article

  • How to impale and stack targets correctly according to the collider and its coordinate?

    - by David Dimalanta
    I'm making another simple game, a catch game, where a spawning target game object must be captured using a skewer to impale it. Here how: At the start, the falling object (in red) will fall in a vertical direction (in blue) When aimed properly, the target will fall down along the line of the skewer. (in blue) Then, another target is spawned and will fall vertically. (in red) When aimed successfully again in a streak, the second target will fall along the skewer and stacked. Same process over and over when another target is spawned. However, when I test run it on the scene tab in Unity, when impaled several targets, instead of a smooth flow and stacking it ended up overlaying it instead of stacking it up like a pancake. Here's what it look like: As I noticed when reaching the half-way of my progress, I tried to figure out how to deal with collider bodies without sticking each other so that it will actually stack like in the example of the image at no. 3. Here's the script code I added in the target game object: using UnityEngine; using System.Collections; public class ImpaleStateTest : MonoBehaviour { public GameObject target; public GameObject skewer; public bool drag = false; private float stack; private float impaleCount; void Start () { stack = 0; impaleCount = 0; } void Update () { if(drag) { target.transform.position = new Vector3 (DragTest.dir.transform.position.x, DragTest.dir.transform.position.y - 0.35f, 0); target.transform.rotation = DragTest.degrees; target.rigidbody2D.fixedAngle = true; target.rigidbody2D.isKinematic = true; target.rigidbody2D.gravityScale = 0; if(Input.GetMouseButton(0)) { Debug.Log ("Skewer: " + DragTest.dir.transform.position.x); Debug.Log ("Target: " + target.transform.position.x); } } } void OnTriggerEnter2D(Collider2D collider) { impaleCount++; Debug.Log ("Impaled " + impaleCount + " time(s)!"); drag = true; audio.Play (); } } Aside from that, I'm not sure if it's right but, the only way to stick the impaled targets while dragging the skewer left or right is to get the X coordinates from the skewer only. Is there something else to recommend it in order to improve this behavior as realistic as possible? Please help.

    Read the article

  • How do I get the compression on specific dynamic body

    - by Mike JM
    Sorry, I could not find any tag that would suit my question. Let me first show you the image and then write what I want to do: I'm using box2D. As you can see there are three dynamic bodies connected to each other (think of it as a table from front view).The LEG1 and LEG2 are connected to the static body. (it's the ground body). Another dynamic body is falling onto the table. I need to get the compression in the LEG1 and LEG2 separately. Joints have GetReactionForce() function which returns a b2Vec, which in turn has Length() and LengthSqd functions. This will give the total sum of the forces in any taken joint. But what I need is forces in individual bodies that are connected with joints. Once you connect several bodies with a single joint it again will show the sum of forces which is not useful.Here's the case iI'm talking about:

    Read the article

< Previous Page | 26 27 28 29 30 31 32 33 34 35 36 37  | Next Page >