• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 11:43
CEST 17:43
KST 00:43
  • 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
[ASL21] Ro16 Preview Pt2: All Star10Team Liquid Map Contest #22 - The Finalists16[ASL21] Ro16 Preview Pt1: Fresh Flow9[ASL21] Ro24 Preview Pt2: News Flash10[ASL21] Ro24 Preview Pt1: New Chaos0
Community News
2026 GSL Season 1 Qualifiers13Maestros of the Game 2 announced82026 GSL Tour plans announced14Weekly Cups (April 6-12): herO doubles, "Villains" prevail1MaNa leaves Team Liquid24
StarCraft 2
General
Maestros of the Game 2 announced Team Liquid Map Contest #22 - The Finalists MaNa leaves Team Liquid 2026 GSL Tour plans announced Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament 2026 GSL Season 1 Qualifiers GSL CK: More events planned pending crowdfunding RSL Revival: Season 5 - Qualifiers and Main Event Master Swan Open (Global Bronze-Master 2)
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
Mutation # 522 Flip My Base The PondCast: SC2 News & Results Mutation # 521 Memorable Boss Mutation # 520 Moving Fees
Brood War
General
ASL21 General Discussion Any progamer "explanation" videos like this one? Data needed BGH Auto Balance -> http://bghmmr.eu/ ASL21 Strategy, Pimpest Plays Discussions
Tourneys
[ASL21] Ro16 Group D [Megathread] Daily Proleagues [ASL21] Ro16 Group C [ASL21] Ro16 Group B
Strategy
Simple Questions, Simple Answers What's the deal with APM & what's its true value Any training maps people recommend? Fighting Spirit mining rates
Other Games
General Games
Nintendo Switch Thread Dawn of War IV Starcraft Tabletop Miniature Game General RTS Discussion Thread Battle Aces/David Kim RTS Megathread
Dota 2
The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
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
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread Canadian Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread YouTube Thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion McBoner: A hockey love story Cricket [SPORT]
World Cup 2022
Tech Support
[G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Sexual Health Of Gamers
TrAiDoS
lurker extra damage testi…
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Iranian anarchists: organize…
XenOsky
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2099 users

The Big Programming Thread - Page 824

Forum Index > General Forum
Post a Reply
Prev 1 822 823 824 825 826 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.
Nyxisto
Profile Joined August 2010
Germany6287 Posts
January 03 2017 19:02 GMT
#16461
hey I'm tinkering with a little chat client that writes to stdout and gets server messages from stdin and I'm interacting with this through a QT gui that basically runs a Qprocess that gets the client as a process, reads the output and can write to the input. Now my problem is, how do I get a list of active users to the Qt window? I've only got the client input and output stream.

Do I make another process that gets the user list from the server and sends this back to the gui? That sounds somewhat complicated.
mantequilla
Profile Blog Joined June 2012
Turkey781 Posts
Last Edited: 2017-01-03 19:45:27
January 03 2017 19:43 GMT
#16462
instead of interpreting all data from stdin and stdout as messages, use them as a comm channel that carries different types of data?


in json format:

{ "type": "message", "content": "hello!" } or

{ "type": "userList", "content": "Alice, John" }
Age of Mythology forever!
Nyxisto
Profile Joined August 2010
Germany6287 Posts
Last Edited: 2017-01-03 19:53:16
January 03 2017 19:52 GMT
#16463
that's what I also thought about, but isn't that prone to bugs if someone would send a text message that accidentally has the wrong structure? (although probably unlikely)
mantequilla
Profile Blog Joined June 2012
Turkey781 Posts
January 03 2017 19:59 GMT
#16464
you would take everything the user typed literally and put it in content field, why would there be a bug?

this is similar to the way that all web requests work, only difference is you are using stdin/stdout instead of a tcp connection
Age of Mythology forever!
Nyxisto
Profile Joined August 2010
Germany6287 Posts
January 03 2017 20:15 GMT
#16465
yes, you're right. I was confused and thought that there might be a way how a user could act like he's sending a "userlist" message but that shouldn't be possible. I'll do that, thanks.
Manit0u
Profile Blog Joined August 2004
Poland17731 Posts
Last Edited: 2017-01-03 21:23:54
January 03 2017 21:16 GMT
#16466
On January 04 2017 02:27 tofucake wrote:
Old datatables was awful. New datatables is pretty nice


Have you ever tried them alongside materialize with responsive tables?

I'm living in a nightmare for the past few days. I've even solved the async mailer library being incompatible with user authentication library problem just to get out of this shit for a moment...

Edit:

I mean, why the fuck in this day and age they would go for changing the style attribute of column cells and setting their width in pixel values, along with absolute positioning everywhere? What in the actual fuck?! How am I supposed to work with this shit that just pretends to be responsive? (I'm using DataTables 1.10.10)

The funniest thing is, including the DataTables.responsive extras and doing responsive: true, in the set-up actually makes it worse.

Seriously, fuck that shit. Why don't front-end people rebel at such blatant violation of all good practices?
Time is precious. Waste it wisely.
Nyxisto
Profile Joined August 2010
Germany6287 Posts
Last Edited: 2017-01-05 01:00:01
January 04 2017 23:54 GMT
#16467
A new problem has cropped up in my chat client. The way this works at the moment is that I basically iterate over the sockets and if I receive anything the server will broadcast it, if some client is not available I'll catch that and drop the client from the socket list.

Problem is that this only updates if someone tries to send a message because that's the only time the sockets are being tested. My hacky solution was to basically generate a "quit key" that is being send to the server when the client quits the app. I assume there's some better way to do this?
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-01-05 01:26:55
January 05 2017 00:57 GMT
#16468
On January 05 2017 08:54 Nyxisto wrote:
A new problem has cropped up in my chat client. The way this works at the moment is that I basically iterate over the sockets and if I receive anything the server will broadcast it, if some client is not available I'll catch that and drop the client from the socket list.

Problem is that this only updates if someone tries to send a message because that's the only time the sockets are being tested. My hacky solution was to basically generate a "quit key" that is being send to the server when the client quits the app. I assume there's some better way to do this?


I don't really understand your problem but everything you seem to be doing looks like enforcing a protocol for communicating within your network, and stuff like that already exists because it's common.

https://en.wikipedia.org/wiki/JSON-RPC
https://en.wikipedia.org/wiki/IRCd

Some of your other "problems" just seem like problems with C/C++ async design, which is to say pretty poor multi-threading - polling, disconnects, updates (assuming you're using C++ cause you used stdin).
There is no one like you in the universe.
RoomOfMush
Profile Joined March 2015
1296 Posts
January 05 2017 01:19 GMT
#16469
On January 05 2017 08:54 Nyxisto wrote:
A new problem has cropped up in my chat client. The way this works at the moment is that I basically iterate over the sockets and if I receive anything the server will broadcast it, if some client is not available I'll catch that and drop the client from the socket list.

Problem is that this only updates if someone tries to send a message because that's the only time the sockets are being tested. My hacky solution was to basically generate a "quit key" that is being send to the server when the client quits the app. I assume there's some better way to do this?

What language do you use? What methods do you use to "test" your sockets?
Usually a socket should tell you when the connection has been closed. In java, for example, a TCP socket will throw an exeption when it discovers the other side is unavailable.
Manit0u
Profile Blog Joined August 2004
Poland17731 Posts
Last Edited: 2017-01-05 16:33:52
January 05 2017 06:32 GMT
#16470
I've decided to screw DataTables and implement my own solution.

Everything now works, is a lot simpler, a lot more maintainable and more reusable. It's also more than 6x faster.
Time is precious. Waste it wisely.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-01-05 19:43:53
January 05 2017 19:15 GMT
#16471
I am a bit confused about data structure complexity when it comes to iteration.

What is the difference between "iteration" and "search".

I understand that iteration means to go through each element 1 by 1.

For example on this page:

http://bigocheatsheet.com/

Hash Table has O(1) for "search". It uses the hashcode to find the element.

Array has O(n) for "search". in this case, is "search" the same as iteration?

If so, I am wondering how hash tables compare to other data structures in terms of iteration? Is iteration slower with a hashset because it likely contains empty buckets?



And does this mean that if I need a data structure where I have to iterate to find what I want, I should use an arraylist?
What I need to do is find elements based on criteria (not the element itself, just some field the element has). I then need to remove those elements. oh, and a map won't work because of the nature of the criteria


edit: (I realize that I am using hash table and hashset interchangeably here when they are different structures, but I am guessing it doesn't matter for iteration? if it does, why?)
RoomOfMush
Profile Joined March 2015
1296 Posts
Last Edited: 2017-01-05 19:53:37
January 05 2017 19:52 GMT
#16472
On January 06 2017 04:15 travis wrote:
I am a bit confused about data structure complexity when it comes to iteration.

What is the difference between "iteration" and "search".

I understand that iteration means to go through each element 1 by 1.

For example on this page:

http://bigocheatsheet.com/

Hash Table has O(1) for "search". It uses the hashcode to find the element.

Array has O(n) for "search". in this case, is "search" the same as iteration?

If so, I am wondering how hash tables compare to other data structures in terms of iteration? Is iteration slower with a hashset because it likely contains empty buckets?



And does this mean that if I need a data structure where I have to iterate to find what I want, I should use an arraylist?
What I need to do is find elements based on criteria (not the element itself, just some field the element has). I then need to remove those elements. oh, and a map won't work because of the nature of the criteria


edit: (I realize that I am using hash table and hashset interchangeably here when they are different structures, but I am guessing it doesn't matter for iteration? if it does, why?)

What that website refers to as "search" is probably a contains check for a given element. "Does the data structure contain a particular element?". This is something that all hash-based data structures are particularly good at since they have been made exactly for this purpose.

If you want to iterate over all elements within a data structure nothing will ever beat an array in terms of performance. ArrayList in java is using an array in the background and thus very fast for iterations. However, the HashMap (not HashTable!) also uses an array (more or less. Its complicated) and isnt that much slower. It should usually not make any difference. Dont worry about it unless you actually encounter problems with performance or you are explicitly working on an algorithm which needs to perform well for millions of elements.

The worst data structure for iterations is probably a linked list. This has nothing to do with the theoretic aspect of the linked list (since it is very good in theory!) but with the way modern hardware works. A linked list is very very hard to predict for the computer since each node could be at completely random points within the computers memory while an array traditionally has all of its elements tightly packed. Prediction is a big thing with hardware in modern times.

By the way: A HashSet is usually build by using a HashMap internally so it really doesnt matter. Even if the Set is build from scratch it probably does much of the same thing as the Map. The difference, if any, should be insignificant.
slmw
Profile Blog Joined October 2010
Finland233 Posts
January 06 2017 01:35 GMT
#16473
On January 06 2017 04:52 RoomOfMush wrote:


The worst data structure for iterations is probably a linked list. This has nothing to do with the theoretic aspect of the linked list (since it is very good in theory!) but with the way modern hardware works. A linked list is very very hard to predict for the computer since each node could be at completely random points within the computers memory while an array traditionally has all of its elements tightly packed. Prediction is a big thing with hardware in modern times.


I would say the logarithmic factor from a binary tree makes it a lot slower, and the empty buckets in hash sets slow things down as well. Neither of these data structures are 'tightly packed'.
RoomOfMush
Profile Joined March 2015
1296 Posts
January 06 2017 10:33 GMT
#16474
On January 06 2017 10:35 slmw wrote:
Show nested quote +
On January 06 2017 04:52 RoomOfMush wrote:


The worst data structure for iterations is probably a linked list. This has nothing to do with the theoretic aspect of the linked list (since it is very good in theory!) but with the way modern hardware works. A linked list is very very hard to predict for the computer since each node could be at completely random points within the computers memory while an array traditionally has all of its elements tightly packed. Prediction is a big thing with hardware in modern times.


I would say the logarithmic factor from a binary tree makes it a lot slower, and the empty buckets in hash sets slow things down as well. Neither of these data structures are 'tightly packed'.

It is true that the empty buckets have an impact on speed, but in the average case the number of empty buckets is usually not very big. It still is an array iteration though (assuming the regular java HashMap implementation of course) and those are relatively fast.

But why do you say iterating a binary tree has a logarithmic factor to it? The worst case for a binary tree is a linked list. I do not see how this would be anything but linear time.
zf
Profile Joined April 2011
231 Posts
January 06 2017 11:27 GMT
#16475
On January 06 2017 19:33 RoomOfMush wrote:
But why do you say iterating a binary tree has a logarithmic factor to it? The worst case for a binary tree is a linked list. I do not see how this would be anything but linear time.


Average search time is logarithmic.
RoomOfMush
Profile Joined March 2015
1296 Posts
January 06 2017 12:39 GMT
#16476
On January 06 2017 20:27 zf wrote:
Show nested quote +
On January 06 2017 19:33 RoomOfMush wrote:
But why do you say iterating a binary tree has a logarithmic factor to it? The worst case for a binary tree is a linked list. I do not see how this would be anything but linear time.


Average search time is logarithmic.

But travis and I were talking about iterating all elements.
slmw
Profile Blog Joined October 2010
Finland233 Posts
Last Edited: 2017-01-06 13:23:57
January 06 2017 13:05 GMT
#16477
Sorry, I meant binary search trees where most languages only provide an ordered iterator. I stand corrected.
Edit: Which is also O(N), so it's just the same as an in-order traversal of a tree. A few more steps involved than in iterating a linked list though.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-01-06 18:11:42
January 06 2017 17:18 GMT
#16478
edit:

i guess it would be rude to completely delete this. my question was about using recursion to find the smallest finite line segment among many finite line segments on a plane, that does not intersect any other line segments.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
Last Edited: 2017-01-06 17:45:05
January 06 2017 17:44 GMT
#16479
First of all you should sort your lines by length. There should be a sort-method readily available in Java, you might have to pass it a Comparer of sorts, which converts a line into its length. The result of this step is a sorted list of lines.

Then in the second step, you iterate over the sorted lines. For each line, you check it against all lines, which you do again by iterating over the sorted lines, skipping the one you're currently checking. If you find one that doesn't intersect any line, you return that one as a result. It is the smallest one because it's the first in the sorted list.

There is no recursion here. It's a naive approach, but clean and simple. It's O(n^2). More sophisticated approaches probably would keep the first part, but tweak the second part to use sort of a divide and conquer approach, but that won't be very simple at all. I can imagine O(n log n), but I don't know if it actually is possible.

This approach includes a number of pointless checks, in the worst case 50%. This is because I check against all lines without skipping the pairs already covered. We can avoid that easily by storing the sorted lines in a list, then iterate over the list by index. If we are currently at list[5], we only check against list[6] and beyond:

for(int i = 0; i < list.Count; ++i) {
for(int k = i + 1; k < list.Count; ++k) {
check if list[i] intersects list[k];
}
}
Still is O(n^2) though.

Always ask yourself if you can split your problem into smaller chunks. Sort first, check after. Simple approach first, optimization after.

Also Java or rather the JVM is not well equipped for heavy recursion. Don't avoid recursion at all costs, but if you're doing a lot of work with deep recursion, you probably should try to avoid it.
If you have a good reason to disagree with the above, please tell me. Thank you.
RoomOfMush
Profile Joined March 2015
1296 Posts
Last Edited: 2017-01-06 19:11:13
January 06 2017 19:11 GMT
#16480
On January 07 2017 02:44 spinesheath wrote:
Always ask yourself if you can split your problem into smaller chunks. Sort first, check after. Simple approach first, optimization after.

Another improvement would be to remove all lines that intersect any other line after each pass. This will make consecutive passes faster in a bad case with many intersecting lines. (in a case with few intersecting lines we will stop early anyways)

On January 07 2017 02:44 spinesheath wrote:
Also Java or rather the JVM is not well equipped for heavy recursion. Don't avoid recursion at all costs, but if you're doing a lot of work with deep recursion, you probably should try to avoid it.

There is some Just-In-Time optimizations which unroll the recursion but those are not quite at the level of the magic functional programming languages do so I agree.
Prev 1 822 823 824 825 826 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 8h 17m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
LamboSC2 185
ProTech108
Railgan 49
StarCraft: Brood War
Britney 51796
Calm 5884
Horang2 2158
Jaedong 1990
Mini 419
BeSt 338
ggaemo 310
Soma 304
Hyuk 272
firebathero 271
[ Show more ]
Rush 216
Light 206
actioN 178
Dewaltoss 86
Soulkey 77
Backho 63
Sharp 58
Hyun 58
ToSsGirL 49
sSak 41
Killer 38
Movie 34
soO 29
Hm[arnc] 26
IntoTheRainbow 24
Rock 24
HiyA 22
Sacsri 18
scan(afreeca) 17
GoRush 12
NotJumperer 10
Terrorterran 7
Dota 2
Gorgc6631
qojqva1826
Counter-Strike
olofmeister2232
ScreaM1671
fl0m1452
byalli597
zeus212
edward99
Super Smash Bros
Mew2King112
Other Games
FalleN 2999
singsing1717
hiko719
FrodaN711
B2W.Neo646
Mlord515
Trikslyr139
KnowMe127
QueenE89
ArmadaUGS85
Organizations
Dota 2
PGL Dota 2 - Main Stream14284
Other Games
BasetradeTV205
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• LUISG 30
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis2857
• TFBlade1871
• Jankos1524
Other Games
• WagamamaTV166
• Shiphtur112
Upcoming Events
Replay Cast
8h 17m
The PondCast
18h 17m
KCM Race Survival
18h 17m
WardiTV Map Contest Tou…
19h 17m
Gerald vs herO
Clem vs Cure
ByuN vs Solar
Rogue vs MaxPax
ShoWTimE vs TBD
OSC
23h 17m
CranKy Ducklings
1d 8h
Escore
1d 18h
RSL Revival
2 days
Replay Cast
2 days
WardiTV Map Contest Tou…
2 days
[ Show More ]
Universe Titan Cup
2 days
Rogue vs Percival
Ladder Legends
2 days
uThermal 2v2 Circuit
2 days
BSL
3 days
Sparkling Tuna Cup
3 days
WardiTV Map Contest Tou…
3 days
Ladder Legends
3 days
BSL
4 days
Replay Cast
4 days
Replay Cast
4 days
Wardi Open
4 days
Afreeca Starleague
4 days
Soma vs TBD
Monday Night Weeklies
5 days
Replay Cast
5 days
Afreeca Starleague
5 days
TBD vs YSC
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2026-04-20
RSL Revival: Season 4
NationLESS Cup

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
StarCraft2 Community Team League 2026 Spring
WardiTV TLMC #16
Nations Cup 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026

Upcoming

Escore Tournament S2: W4
Acropolis #4
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
RSL Revival: Season 5
2026 GSL S1
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
BLAST Rivals Spring 2026
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 © 2026 TLnet. All Rights Reserved.