contents: update default Python sort to Powersort (#721)

Signed-off-by: SoulSniper1212 <warush23@gmail.com>
pull/694/merge
Arush Wadhawan 11 months ago committed by GitHub
parent 1d62b88a43
commit cbcb5a010e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -71,7 +71,7 @@ export default function GoogleAnalytics({ children }: Props) {
return () => { return () => {
router.events.off('routeChangeComplete', handleRouteChange); router.events.off('routeChangeComplete', handleRouteChange);
}; };
}, [router.events,]); }, [router.events]);
return ( return (
<GoogleAnalyticsContext.Provider value={{ event }}> <GoogleAnalyticsContext.Provider value={{ event }}>

@ -43,7 +43,8 @@ const getYoeRange = (yoeCategory: number | null | undefined) => {
: null; // Internship : null; // Internship
}; };
export const offerAdminRouter = createProtectedRouter().query('list', { export const offerAdminRouter = createProtectedRouter()
.query('list', {
input: z.object({ input: z.object({
companyId: z.string().nullish(), companyId: z.string().nullish(),
countryId: z.string().nullish(), countryId: z.string().nullish(),
@ -67,9 +68,9 @@ export const offerAdminRouter = createProtectedRouter().query('list', {
const userId = ctx.session.user.id; const userId = ctx.session.user.id;
const adminAccount = await ctx.prisma.offersAdmin.findFirst({ const adminAccount = await ctx.prisma.offersAdmin.findFirst({
where: { where: {
userId userId,
} },
}) });
if (!adminAccount) { if (!adminAccount) {
throw new TRPCError({ throw new TRPCError({
@ -477,15 +478,16 @@ export const offerAdminRouter = createProtectedRouter().query('list', {
!yoeRange ? JobType.INTERN : JobType.FULLTIME, !yoeRange ? JobType.INTERN : JobType.FULLTIME,
); );
}, },
}).query('isAdmin', { })
.query('isAdmin', {
async resolve({ ctx }) { async resolve({ ctx }) {
const userId = ctx.session.user.id; const userId = ctx.session.user.id;
const result = await ctx.prisma.offersAdmin.findFirst({ const result = await ctx.prisma.offersAdmin.findFirst({
where: { where: {
userId userId,
} },
}) });
return result ? true : false return result ? true : false;
} },
}); });

@ -320,7 +320,6 @@ export const offersCommentsRouter = createRouter()
id: input.profileId, id: input.profileId,
}, },
}); });
} else { } else {
throw new trpc.TRPCError({ throw new trpc.TRPCError({
code: 'UNAUTHORIZED', code: 'UNAUTHORIZED',

@ -41,12 +41,13 @@ export const questionsQuestionEncounterUserRouter = createProtectedRouter()
}); });
} }
await tx.questionsQuestion.update({ await tx.questionsQuestion.update({
data: { data: {
lastSeenAt: (questionToUpdate.lastSeenAt === null || lastSeenAt:
questionToUpdate.lastSeenAt < input.seenAt) questionToUpdate.lastSeenAt === null ||
? input.seenAt : undefined, questionToUpdate.lastSeenAt < input.seenAt
? input.seenAt
: undefined,
numEncounters: { numEncounters: {
increment: 1, increment: 1,
}, },

@ -1,8 +1,13 @@
import type { Config } from 'unique-names-generator'; import type { Config } from 'unique-names-generator';
import { adjectives, animals,colors, uniqueNamesGenerator } from 'unique-names-generator'; import {
adjectives,
animals,
colors,
uniqueNamesGenerator,
} from 'unique-names-generator';
import { PrismaClient } from '@prisma/client'; import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient() const prisma = new PrismaClient();
const customConfig: Config = { const customConfig: Config = {
dictionaries: [adjectives, colors, animals], dictionaries: [adjectives, colors, animals],
@ -10,24 +15,23 @@ const customConfig: Config = {
separator: '-', separator: '-',
}; };
export default async function generateRandomName(): Promise<string> { export default async function generateRandomName(): Promise<string> {
let uniqueName: string = uniqueNamesGenerator(customConfig); let uniqueName: string = uniqueNamesGenerator(customConfig);
let sameNameProfiles = await prisma.offersProfile.findMany({ let sameNameProfiles = await prisma.offersProfile.findMany({
where: { where: {
profileName: uniqueName profileName: uniqueName,
} },
}) });
while (sameNameProfiles.length !== 0) { while (sameNameProfiles.length !== 0) {
uniqueName = uniqueNamesGenerator(customConfig); uniqueName = uniqueNamesGenerator(customConfig);
sameNameProfiles = await prisma.offersProfile.findMany({ sameNameProfiles = await prisma.offersProfile.findMany({
where: { where: {
profileName: uniqueName profileName: uniqueName,
} },
}) });
} }
return uniqueName return uniqueName;
} }

@ -71,7 +71,7 @@ While you're unlikely to be asked to implement a sorting algorithm from scratch
## Things to look out for during interviews ## Things to look out for during interviews
Make sure you know the time and space complexity of the language's default sorting algorithm! The time complexity is almost definitely O(nlog(n))). Bonus points if you can name the sort. In Python, it's [Timsort](https://en.wikipedia.org/wiki/Timsort). In Java, [an implementation of Timsort](https://github.com/openjdk/jdk/blob/d9052b946682d1c0f2629455d73fe4e6b95b29db/src/java.base/share/classes/java/util/TimSort.java) is used for sorting objects, and [Dual-Pivot Quicksort](https://github.com/openjdk/jdk/blob/d9052b946682d1c0f2629455d73fe4e6b95b29db/src/java.base/share/classes/java/util/DualPivotQuicksort.java) is used for sorting primitives. Make sure you know the time and space complexity of the language's default sorting algorithm! The time complexity is almost definitely O(n log n). Bonus points if you can name the sort. In Python 3.11+, it's [Powersort](https://www.wild-inter.net/posts/powersort-in-python-3.11), which replaced Timsort as the default sorting algorithm. In Java, [an implementation of Timsort](https://github.com/openjdk/jdk/blob/d9052b946682d1c0f2629455d73fe4e6b95b29db/src/java.base/share/classes/java/util/TimSort.java) is used for sorting objects, and [Dual-Pivot Quicksort](https://github.com/openjdk/jdk/blob/d9052b946682d1c0f2629455d73fe4e6b95b29db/src/java.base/share/classes/java/util/DualPivotQuicksort.java) is used for sorting primitives.
## Corner cases ## Corner cases

Loading…
Cancel
Save