• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 03:58
CET 09:58
KST 17:58
  • 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
Behind the Blue - Team Liquid History Book16Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info8herO wins SC2 All-Star Invitational14
Community News
ACS replaced by "ASL Season Open" - Starts 21/0222LiuLi Cup: 2025 Grand Finals (Feb 10-16)37Weekly Cups (Feb 2-8): Classic, Solar, MaxPax win2Nexon's StarCraft game could be FPS, led by UMS maker12PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar)15
StarCraft 2
General
Nexon's StarCraft game could be FPS, led by UMS maker Behind the Blue - Team Liquid History Book How do you think the 5.0.15 balance patch (Oct 2025) for StarCraft II has affected the game? Terran Scanner Sweep Weekly Cups (Jan 12-18): herO, MaxPax, Solar win
Tourneys
$5,000 WardiTV Winter Championship 2026 StarCraft Evolution League (SC Evo Biweekly) LiuLi Cup: 2025 Grand Finals (Feb 10-16) SC2 AI Tournament 2026 PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar)
Strategy
Custom Maps
Map Editor closed ? [A] Starcraft Sound Mod
External Content
Mutation # 513 Attrition Warfare The PondCast: SC2 News & Results Mutation # 512 Overclocked Mutation # 511 Temple of Rebirth
Brood War
General
BW General Discussion Which units you wish saw more use in the game? TvZ is the most complete match up Ladder maps - how we can make blizz update them? ACS replaced by "ASL Season Open" - Starts 21/02
Tourneys
[Megathread] Daily Proleagues Escore Tournament StarCraft Season 1 Small VOD Thread 2.0 KCM Race Survival 2026 Season 1
Strategy
Fighting Spirit mining rates Zealot bombing is no longer popular? Simple Questions, Simple Answers Current Meta
Other Games
General Games
Diablo 2 thread Path of Exile ZeroSpace Megathread Nintendo Switch Thread Battle Aces/David Kim RTS Megathread
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 Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Ask and answer stupid questions here! Things Aren’t Peaceful in Palestine European Politico-economics QA Mega-thread
Fan Clubs
The IdrA Fan Club The herO Fan Club!
Media & Entertainment
[Req][Books] Good Fantasy/SciFi books [Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
TL Community
The Automated Ban List
Blogs
The Search For Meaning in Vi…
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2639 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
Poland17662 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
Poland17662 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 2m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ProTech135
StarCraft: Brood War
Sea 1171
Bisu 181
ToSsGirL 152
Shinee 96
Sharp 45
Hm[arnc] 29
Noble 20
NotJumperer 1
Dota 2
XaKoH 424
NeuroSwarm137
League of Legends
JimRising 646
Counter-Strike
olofmeister2346
kRYSTAL_31
Super Smash Bros
Mew2King108
Other Games
summit1g7994
C9.Mang0704
ceh9367
Happy183
crisheroes125
Organizations
Counter-Strike
PGL12225
Other Games
gamesdonequick843
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• Sammyuel 28
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Stunt1044
• HappyZerGling118
Upcoming Events
Replay Cast
2m
Wardi Open
3h 2m
Monday Night Weeklies
8h 2m
OSC
15h 2m
WardiTV Winter Champion…
1d 3h
PiGosaur Cup
1d 16h
Replay Cast
2 days
WardiTV Winter Champion…
2 days
Replay Cast
2 days
PiG Sty Festival
3 days
[ Show More ]
The PondCast
3 days
KCM Race Survival
3 days
WardiTV Winter Champion…
3 days
Replay Cast
3 days
PiG Sty Festival
4 days
Epic.LAN
4 days
Replay Cast
4 days
PiG Sty Festival
5 days
CranKy Ducklings
5 days
Epic.LAN
5 days
Replay Cast
5 days
PiG Sty Festival
6 days
Sparkling Tuna Cup
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2026-02-14
LiuLi Cup: 2025 Grand Finals
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
Nations Cup 2026
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025

Upcoming

Escore Tournament S1: King of Kings
[S:21] ASL SEASON OPEN 1st Round
[S:21] ASL SEASON OPEN 1st Round Qualifier
[S:21] ASL SEASON OPEN 2nd Round
[S:21] ASL SEASON OPEN 2nd Round Qualifier
Acropolis #4
IPSL Spring 2026
HSC XXIX
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
RSL Revival: Season 4
WardiTV Winter 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
FISSURE Playground #3
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
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.