• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 07:52
CET 13:52
KST 21:52
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3
Community News
Starcraft, SC2, HoTS, WC3, returning to Blizzcon!12$5,000+ WardiTV 2025 Championship4[BSL21] RO32 Group Stage3Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win9
StarCraft 2
General
Starcraft, SC2, HoTS, WC3, returning to Blizzcon! RotterdaM "Serral is the GOAT, and it's not close" Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win 5.0.15 Patch Balance Hotfix (2025-10-8) TL.net Map Contest #21: Voting
Tourneys
Constellation Cup - Main Event - Stellar Fest Merivale 8 Open - LAN - Stellar Fest $5,000+ WardiTV 2025 Championship Sea Duckling Open (Global, Bronze-Diamond) $3,500 WardiTV Korean Royale S4
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review [BSL21] RO32 Group Stage Practice Partners (Official) [ASL20] Ask the mapmakers — Drop your questions
Tourneys
BSL21 Open Qualifiers Week & CONFIRM PARTICIPATION [ASL20] Grand Finals Small VOD Thread 2.0 The Casual Games of the Week Thread
Strategy
Current Meta How to stay on top of macro? PvZ map balance Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Stormgate/Frost Giant Megathread Dawn of War IV Nintendo Switch Thread ZeroSpace Megathread General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread YouTube Thread Things Aren’t Peaceful in Palestine Dating: How's your luck?
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Why we need SC3
Hildegard
Career Paths and Skills for …
TrAiDoS
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1508 users

The Big Programming Thread - Page 797

Forum Index > General Forum
Post a Reply
Prev 1 795 796 797 798 799 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
November 11 2016 01:56 GMT
#15921
Doing an insertion with recursion actually seems really annoying, but ^_^
I'll always be your shadow and veil your eyes from states of ain soph aur.
NovemberstOrm
Profile Blog Joined September 2011
Canada16217 Posts
Last Edited: 2016-11-11 07:46:31
November 11 2016 07:41 GMT
#15922
Anyone familiar with swift/xcode?
xcode 7.1
swift 2 i believe

I have one Textfield(playerAnswerTextView) on ViewController1 and a UI label(userAnswerTextBox) on ViewController2, I want the textfield to display its text to the ui label, segues are setup, i have a button setup to go to the next view controller. I've tried to get it work but can't seem to for some reason :/

Help is appreciated.
Moderatorlickypiddy
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2016-11-11 10:18:38
November 11 2016 09:54 GMT
#15923
--- Nuked ---
Prillan
Profile Joined August 2011
Sweden350 Posts
November 11 2016 13:48 GMT
#15924
On November 10 2016 12:52 Manit0u wrote:
[image loading]

This is great!
TheBB's sidekick, aligulac.com | "Reality is frequently inaccurate." - Douglas Adams
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
November 12 2016 21:40 GMT
#15925
I just switched from Unity desktop to Gnome and I'm LOVIN it so far. Workspaces are such a nice touch. Lovin it. If I could move my bottom file bar to left, it would be perfect. Can't I just do that with some extension or shit?
"windows bash is a steaming heap of shit" tofucake
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-13 16:06:21
November 13 2016 16:05 GMT
#15926
I need to write a weighted graph in java. Any opinion on the best way to implement this?

I am thinking that my graph class will have a map members:


Map<node, Map<node, intege>>

where the integer represents the weight of the edge


So My map would store each node, as well as a map of nodes it connects to and the weight of the edge between them.

Is this a good solution?
Are there alternatives any of you would prefer?


Also in lecture, the professor kept mentioning "nodes" and "vertexes". Though for the life of me I didn't understand the difference and he didn't (couldn't?) really explain the difference.

Is it that in a typical representation, the vertex is simply a representation of the spot on the graph, and the node would be an object that contains the vertex and any other associated data?

But in that case if there was no other associated data it would make sense to just represent it with nodes instead of vertexes, right?

Okay, thanks!
Acrofales
Profile Joined August 2010
Spain18108 Posts
Last Edited: 2016-11-13 17:20:01
November 13 2016 17:12 GMT
#15927
There are many ways of implementing weighted graphs. It really depends on what you want to do with them. Generally a decent method is:

Your graph is simply a list of nodes

Every node has a list of edges in the form:

Map<Node, Integer> weightededges

However, this doesn't work for some common graph problems (such as max-flow-min-cut) where you want a list of edges at the top level. It also means that if your graph is not directed, you are storing each edge twice, which is slightly redundant (but usually not a problem).

There is no difference between nodes and vertices. Node is used in networks, and vertices in mathematics. Both mean the same thing.

If you need your edges at the top level for the functioning of your algorithm, generally a good solution is to have an edge data structure with fields:

Node start
Node end
int weight

And have a List<Edge> at the top level. However, in this case you will have to do extra work to ensure your graph is sane, and you don't have multiple edges between the same 2 nodes.

I'm not a big fan of your solution of Map<Node, Map<Node, Ingeger>>: it takes care of keeping the graph sane, but it is not as easy to do operations on (such as order all edges by weight): it is a compromise between the node-based solution and the edge-based solution, without the advantages of either.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-13 17:25:08
November 13 2016 17:22 GMT
#15928
Thanks acrofales

that all makes sense


So, if my graph got really really huge, using lists of edges would be bad, right? Wouldn't sets be better?


edit: your last edit touches on my project requirements a lot. im gonna have to think about that.


Let's say I was going to have to implement djiksta's algorithm
What structure would you recommend then?
RoomOfMush
Profile Joined March 2015
1296 Posts
November 13 2016 18:25 GMT
#15929
On November 14 2016 02:22 travis wrote:
Thanks acrofales

that all makes sense


So, if my graph got really really huge, using lists of edges would be bad, right? Wouldn't sets be better?

Why would sets be somehow better than lists?
An ArrayList is pretty much the fastest data structure for append operations and iterations. Only when it comes to random access insertions and deletions is the ArrayList somewhat slow (but still pretty fast).

On November 14 2016 02:22 travis wrote:Let's say I was going to have to implement djiksta's algorithm
What structure would you recommend then?

I would recommend having a Node class and an Edge class. An Edge connects two Node's. Each Node has a List of Edge's to other Node's which are connected. You can also have a Graph class which has a List of all Node's.

The List of Edge's is useful because it can be sorted by weight which makes it easy to pick the "cheapest" path first.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-13 18:30:41
November 13 2016 18:28 GMT
#15930
Okay so I basically went with what I think you were saying, I am going to use an arraylist of edges.
yeah basically exactly what you are talking about.


there's so many ways to implement this lol
Acrofales
Profile Joined August 2010
Spain18108 Posts
Last Edited: 2016-11-13 18:42:41
November 13 2016 18:28 GMT
#15931
The first. Just think about how that algorithm works.

E: had this reply open without posting.

Having both nodes and edges is a "complete" representation of a graph, but you'll find it's really redundant most of the time. For starters, at no point in Dijkstra will you be interested in knowing about all edges, so why bother representing them explicitly. Having a list of edges in each node is effectively the same as having a list of nodes in each node. It's just encapsulated in an imho over-engineered OOP manner.

The reason you want a Set (in my example, and your initial idea, the keys in the map) is so you don't have to check uniqueness of each edge.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
November 13 2016 18:42 GMT
#15932
Okay cool guys it's all coming together now

I'll probably be back in a few days with more questions lol
Mr. Wiggles
Profile Blog Joined August 2010
Canada5894 Posts
November 13 2016 18:49 GMT
#15933
On November 14 2016 01:05 travis wrote:
I need to write a weighted graph in java. Any opinion on the best way to implement this?

I am thinking that my graph class will have a map members:


Map<node, Map<node, intege>>

where the integer represents the weight of the edge


So My map would store each node, as well as a map of nodes it connects to and the weight of the edge between them.

Is this a good solution?
Are there alternatives any of you would prefer?


Also in lecture, the professor kept mentioning "nodes" and "vertexes". Though for the life of me I didn't understand the difference and he didn't (couldn't?) really explain the difference.

Is it that in a typical representation, the vertex is simply a representation of the spot on the graph, and the node would be an object that contains the vertex and any other associated data?

But in that case if there was no other associated data it would make sense to just represent it with nodes instead of vertexes, right?

Okay, thanks!

I don't believe there's any technical difference between nodes and vertices. They're basically synonyms when talking about graphs. For example, I usually refer to vertices, but others use the word nodes.

In addition to what's been suggested, another possible graph representation is the adjacency-matrix:

https://en.m.wikipedia.org/wiki/Adjacency_matrix

This is generally useful for doing random lookups of if two vertices are connected.

On November 14 2016 03:28 travis wrote:
Okay so I basically went with what I think you were saying, I am going to use an arraylist of edges.
yeah basically exactly what you are talking about.


there's so many ways to implement this lol

Instead of repeated sorting to find the minimum edge distance, you can also look at using a priority-queue implementation.

https://en.m.wikipedia.org/wiki/Priority_queue
https://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.html

This will generally be faster than re-sorting the list at every step of Dijkstra's algorithm. It's also a very useful data structure to know in general, when you want to keep a sorted queue of something where you're popping and pushing members.
you gotta dance
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
November 13 2016 19:01 GMT
#15934
In java, is there a time you need to use "this" to specify what member you are referring to *other* than when you have duplicate field names? (like, are passed parameter "key" and have a class member "key" so in your constructor you do this.key = key ... which is obviously bad anyways)
phar
Profile Joined August 2011
United States1080 Posts
November 13 2016 19:16 GMT
#15935
Yes. When implementing an equals() method, the canonical example uses syntax like if (this == other) { return true; }
Who after all is today speaking about the destruction of the Armenians?
RoomOfMush
Profile Joined March 2015
1296 Posts
November 13 2016 19:27 GMT
#15936
On November 14 2016 04:01 travis wrote:
In java, is there a time you need to use "this" to specify what member you are referring to *other* than when you have duplicate field names? (like, are passed parameter "key" and have a class member "key" so in your constructor you do this.key = key ... which is obviously bad anyways)

There is a few obvious situations like returning "this" or passing "this" as an argument. Other than that it might happen when dealing with non-static inner classes that the inner class and the outer class have a method with the same name (or perhaps a member with the same name) and you need to refer to both of them, for example:

public class Test {

public Test() {
// ... do stuff
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
Test.this.actionPerformed(e);
}
};
// ... do more stuff
}

private void actionPerformed(ActionEvent e) {
// something something
}

}

If you would leave the "Test.this." out you would get an infinite recursion.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-13 20:09:45
November 13 2016 19:33 GMT
#15937
okay another weird question


I have an arraylist filled with objects
each object has a map

I find one of the objects
I do a shallow copy

I then update the map of the shallow copy

I then do a indexOf(shallow copy) on the arraylist

will it find the index of the original object?

It will, right?



edit: I don't even need to put the shallow copy in the arraylist do I? by updating the map I also update the map of the original object? Is that correct?


edit: yes. yes that is correct.
AKnopf
Profile Blog Joined March 2011
Germany259 Posts
Last Edited: 2016-11-13 22:26:53
November 13 2016 20:13 GMT
#15938
If you change the map of the copy, then yes, the map of the original is altered, too. This is because they both have a reference to the very same map. Primitive types are passed by value while complex types are passed by reference.

About indexOf(), it depends on how you implemented the equals()-Method in your custom class. The ArrayList just goes through its elements until it finds the first element that returns true for equals().
If you have not defined your own version of equals() and you are not inherting from a class that implements equals(), then you use the default implementation, which is for complexe types a reference check. This means that only the exact same object is equal. The copy is not equal.

Further reading:

  • Different variants of equality in java:
    • http://www.leepoint.net/data/expressions/22compareobjects.html
    • http://stackoverflow.com/questions/4178997/how-default-equals-and-hashcode-will-work-for-my-classes#4179011

  • indexOf() uses equals() http://stackoverflow.com/questions/22236009/why-does-list-indexof-use-equals-method-of-passed-in-object#22236559





Most importantly: Always also implement hashCode() when you implement equals() in a way, that two object that are equal also produce the same hash code. Otherwise you will land in programmers hell when you want to use your objects in a HashMap.

Cheers!

Update: Fixed sentence about reference vs value. Thanks, Manit0u!
The world - its a funny place
Manit0u
Profile Blog Joined August 2004
Poland17419 Posts
November 13 2016 22:03 GMT
#15939
On November 14 2016 05:13 AKnopf wrote:
Primitive types are referenced by value while complex types are referenced by value.


You might want to revisit this sentence
Time is precious. Waste it wisely.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2016-11-14 02:45:35
November 14 2016 00:30 GMT
#15940
--- Nuked ---
Prev 1 795 796 797 798 799 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 2h 8m
[ Submit Event ]
Live Streams
Refresh
StarCraft: Brood War
Jaedong 2290
GuemChi 2075
Sea 1636
firebathero 607
Pusan 420
Stork 358
Soma 303
Leta 244
Last 235
Hyun 170
[ Show more ]
Light 153
Rush 134
Snow 95
sSak 85
Killer 85
hero 79
Barracks 72
ToSsGirL 71
Backho 65
ZerO 60
Mong 55
Shine 44
JulyZerg 38
Sharp 37
Movie 22
zelot 20
Terrorterran 16
Noble 13
scan(afreeca) 11
Icarus 9
IntoTheRainbow 8
Dota 2
BananaSlamJamma269
XcaliburYe165
Counter-Strike
x6flipin621
zeus500
oskar119
edward65
Other Games
singsing2003
B2W.Neo573
crisheroes295
DeMusliM248
Happy193
Fuzer 156
XaKoH 141
Liquid`LucifroN104
Mew2King71
ZerO(Twitch)3
Organizations
Counter-Strike
PGL295
StarCraft: Brood War
lovetv 8
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• StrangeGG 75
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 8
• HerbMon 1
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV323
League of Legends
• Jankos2359
Upcoming Events
LAN Event
2h 8m
OSC
9h 8m
Replay Cast
10h 8m
OSC
23h 8m
LAN Event
1d 2h
Korean StarCraft League
1d 14h
CranKy Ducklings
1d 21h
WardiTV Korean Royale
1d 23h
LAN Event
2 days
IPSL
2 days
dxtr13 vs OldBoy
Napoleon vs Doodle
[ Show More ]
BSL 21
2 days
Gosudark vs Kyrie
Gypsy vs Sterling
UltrA vs Radley
Dandy vs Ptak
Replay Cast
2 days
Sparkling Tuna Cup
2 days
WardiTV Korean Royale
2 days
LAN Event
3 days
IPSL
3 days
JDConan vs WIZARD
WolFix vs Cross
BSL 21
3 days
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
Replay Cast
3 days
Wardi Open
3 days
WardiTV Korean Royale
4 days
Replay Cast
5 days
Kung Fu Cup
5 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
6 days
The PondCast
6 days
RSL Revival
6 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
6 days
WardiTV Korean Royale
6 days
Liquipedia Results

Completed

BSL 21 Points
SC4ALL: StarCraft II
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025

Upcoming

BSL Season 21
SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
Stellar Fest
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.